Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
*.log
settings.json
E-paper_Separate_Program/4in2_e-Paper_G/RaspberryPi_JetsonNano/python/lib/waveshare_epd/__init__.pyc
E-paper_Separate_Program/4in2_e-Paper_G/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd4in2g.pyc
E-paper_Separate_Program/4in2_e-Paper_G/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)

import logging
from waveshare_epd import epd4in2g
import time
from PIL import Image,ImageDraw,ImageFont
import traceback

logging.basicConfig(level=logging.DEBUG)

try:
logging.info("epd4in2g Demo")

epd = epd4in2g.EPD()
logging.info("init and Clear")
epd.init()
epd.Clear()
time.sleep(3)
font15 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font40 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)

# Drawing on the image
logging.info("1.Drawing on the image...")
Himage = Image.new('RGB', (epd.height, epd.width), epd.WHITE)
draw = ImageDraw.Draw(Himage)
draw.rectangle([(0,0),(50,50)],outline = epd.BLACK)
draw.rectangle([(55,0),(100,50)],fill = epd.RED)
draw.line([(0,0),(50,50)], fill = epd.YELLOW,width = 1)
draw.line([(0,50),(50,0)], fill = epd.YELLOW,width = 1)
draw.pieslice((55, 60, 95, 100), 90, 180, outline = epd.RED)
draw.pieslice((55, 60, 95, 100), 270, 360, fill = epd.BLACK)
draw.chord((10, 60, 50, 100), 0, 360, fill = epd.YELLOW)
draw.ellipse((55, 60, 95, 100), outline = epd.RED)
draw.polygon([(110,0),(110,50),(150,25)],outline = epd.BLACK)
draw.polygon([(190,0),(190,50),(150,25)],fill = epd.BLACK)
draw.text((120, 60), 'e-Paper demo', font = font15, fill = epd.YELLOW)
draw.text((110, 90), u'微雪电子', font = font24, fill = epd.RED)

epd.display(epd.getbuffer(Himage))
time.sleep(3)

# read bmp file
logging.info("2.read bmp file")
Himage = Image.open(os.path.join(picdir, '4.2inch_G-1.bmp'))
epd.display(epd.getbuffer(Himage))
time.sleep(3)

logging.info("Clear...")
epd.Clear()

logging.info("Goto Sleep...")
epd.sleep()

except IOError as e:
logging.info(e)

except KeyboardInterrupt:
logging.info("ctrl + c:")
epd4in2g.epdconfig.module_exit(cleanup=True)
exit()
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)

import logging
from waveshare_epd import epd4in2g
import time
from PIL import Image, ImageDraw
import traceback

logging.basicConfig(level=logging.DEBUG)

try:
logging.info("epd4in2g Demo")
epd = epd4in2g.EPD()
logging.info("Initializing display")
epd.init()
time.sleep(1)

# Create an image where the left half is black and the right half is white

# ToDo: appearing top row as black and bottom row as white in (landscape mode) ? is this expected?
logging.info("Rendering 50 percent black test pattern")
img_width = epd.height
img_height = epd.width
Himage = Image.new('RGB', (img_width, img_height), epd.WHITE)
draw = ImageDraw.Draw(Himage)
draw.rectangle((0, 0, img_width // 2, img_height - 1), fill=epd.BLACK)

epd.display(epd.getbuffer(Himage))
time.sleep(3)

logging.info("Goto Sleep...")
epd.sleep()

except IOError as e:
logging.info(e)
traceback.print_exc()

except KeyboardInterrupt:
logging.info("ctrl + c:")
epd4in2g.epdconfig.module_exit(cleanup=True)
exit()
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import gpiod
import time

'''
This is a cleaner version of gpiotest_raw.py so you don't have to calculate line offset.
'''

def gpio_from_pin(pin):
chip, line = PINMAP[pin]
c = gpiod.Chip(chip)
l = c.get_line(line)
return c, l


PINMAP = {
# --- Power / GND pins intentionally omitted ---
# Header pin : (gpiochip, line)
3: ("gpiochip0", 63), # GPIOA_14
5: ("gpiochip1", 5), # GPIOA_15 ⚠ USB related
7: ("gpiochip1", 3), # GPIOAO_3
8: ("gpiochip1", 0), # GPIOAO_0
10: ("gpiochip1", 1), # GPIOAO_1
11: ("gpiochip1", 2), # GPIOAO_2
12: ("gpiochip0", 74), # GPIOX_9
13: ("gpiochip0", 76), # GPIOX_11
16: ("gpiochip0", 75), # GPIOX_10
18: ("gpiochip0", 73), # GPIOX_8

19: ("gpiochip0", 20), # GPIOH_4
21: ("gpiochip0", 21), # GPIOH_5
22: ("gpiochip0", 48), # GPIOC_7 (open-drain)
23: ("gpiochip0", 23), # GPIOH_7
24: ("gpiochip0", 22), # GPIOH_6

27: ("gpiochip1", 3), # GPIOAO_3 (same as pin 7)
28: ("gpiochip1", 2), # GPIOAO_2 (same as pin 11)

32: ("gpiochip1", 4), # GPIOAO_4
34: ("gpiochip1", 8), # GPIOAO_8
36: ("gpiochip0", 24), # GPIOH_8 ⚠ 5V open-drain
37: ("gpiochip1", 9), # GPIOAO_9
38: ("gpiochip1", 10), # GPIOAO_10 (not always bonded)
40: ("gpiochip1", 11), # GPIOAO_11
}

chip, line = gpio_from_pin(19)
line.request(consumer="app", type=gpiod.LINE_REQ_DIR_OUT)
line.set_value(1)

time.sleep(1)
line.set_value(0)
time.sleep(1)
line.release()
chip.close()
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import gpiod
import time

CHIP_NAME = "gpiochip0"
LINE_OFFSET = 20 # GPIO pin 19 gpio-532 = 532 - 512
'''
Note the first line gives the BASE GPIOs 512-596 so 512 is the base
Global GPIO number = base + line_offset.

TO test this connect LED +ve to GPIO pin 19 and -ve to GND (pin 6) of the radxa zero amlogic board.

$ sudo cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 512-596, parent: platform/ff634400.bus:pinctrl@40, periphs-banks:
gpio-532 (19 [GPIOH_4] )
gpio-533 (21 [GPIOH_5] )
gpio-534 (24 [GPIOH_6] )
gpio-535 (23 [GPIOH_7] )
gpio-536 (36 [GPIOH_8] )
gpio-549 ( |reset ) out hi ACTIVE LOW
gpio-559 ( |cd ) in lo ACTIVE LOW
gpio-560 (22 [GPIOC_7] )
gpio-575 (3 [GPIOA_14] )
gpio-583 ( |reset ) out hi ACTIVE LOW
gpio-585 (18 [GPIOX_8] )
gpio-586 (12 [GPIOX_9] )
gpio-587 (16 [GPIOX_10] )
gpio-588 (13 [GPIOX_11] )
gpio-594 ( |shutdown ) out hi

gpiochip1: GPIOs 597-611, parent: platform/ff800000.bus:pinctrl@14, aobus-banks:
gpio-597 (8 [GPIOAO_0] )
gpio-598 (10 [GPIOAO_1] )
gpio-599 (11,28 [GPIOAO_2] )
gpio-600 (7,27 [GPIOAO_3] )
gpio-601 (32 [GPIOAO_4] )
gpio-602 (5 [GPIOA_15] )
gpio-605 (35 [GPIOAO_8] )
gpio-606 (37 [GPIOAO_9] )
gpio-608 (40 [GPIOAO_11] )
'''

def main():
print(f"Testing GPIO pin {LINE_OFFSET} on {CHIP_NAME}")

# Open GPIO chip
chip = gpiod.Chip(CHIP_NAME)
line = chip.get_line(LINE_OFFSET)

# Request line as output
line.request(
consumer="gpiotest",
type=gpiod.LINE_REQ_DIR_OUT
)

try:
# Turn on GPIO pin 19
print(f"Turning ON GPIO pin {LINE_OFFSET}")
line.set_value(1)
time.sleep(1) # Wait 1 second

# Turn off GPIO pin 19
print(f"Turning OFF GPIO pin {LINE_OFFSET}")
line.set_value(0)
time.sleep(1) # Wait 1 second

print("GPIO test completed successfully")
finally:
# Release line and close chip
line.release()
chip.close()
print("GPIO closed")

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
"""
SPI1 MOSI test for Radxa Zero

This script tests SPI1 by sending 100,000 bytes of 0xFF followed by
100,000 bytes of 0x00 repeatedly. At 5MHz SPI clock, this should blink
an LED connected to MOSI at approximately 6.3 times per second.

SPI1 MOSI is on GPIOH_4 (gpio-532, offset 20) - Pin 19 on the 40-pin header.

To test this connect LED +ve to SPI PIN 19 and -ve to GND (pin 6) of the radxa zero amlogic board.
which is also labeled GPIO447
"""

import time
import spidev

# SPI1 configuration
SPI_BUS = 1 # SPI1
SPI_DEVICE = 0 # CS0 -> /dev/spidev1.0
SPI_SPEED = 5000000 # 5 MHz
SPI_MODE = 0b00 # SPI mode 0

# Number of bytes to send per pattern
BYTES_PER_PATTERN = 100000

def main():
print("SPI1 MOSI Test for Radxa Zero")
print("=" * 50)
print(f"SPI Device: /dev/spidev{SPI_BUS}.{SPI_DEVICE}")
print(f"Clock Speed: {SPI_SPEED / 1000000:.1f} MHz")
print(f"Bytes per pattern: {BYTES_PER_PATTERN:,}")
print("=" * 50)

# Initialize SPI
spi = spidev.SpiDev()

try:
# Open SPI device
print(f"\nOpening SPI bus {SPI_BUS}, device {SPI_DEVICE}...")
spi.open(SPI_BUS, SPI_DEVICE)

# Configure SPI
spi.max_speed_hz = SPI_SPEED
spi.mode = SPI_MODE
spi.bits_per_word = 8

print(f"SPI configured: {SPI_SPEED} Hz, mode {SPI_MODE}")
print("\nStarting SPI transmission...")
print("Pattern: 100,000 bytes of 0xFF, then 100,000 bytes of 0x00")
print("Press Ctrl+C to stop\n")

# Prepare data buffers
data_high = bytes([0xFF] * BYTES_PER_PATTERN)
data_low = bytes([0x00] * BYTES_PER_PATTERN)

cycle_count = 0

try:
while True:
cycle_count += 1
start_time = time.time()

# Send 0xFF bytes
print(f"Cycle {cycle_count}: Sending {BYTES_PER_PATTERN:,} bytes of 0xFF...", end="", flush=True)
spi.writebytes2(data_high)
high_time = time.time() - start_time

# Send 0x00 bytes
print(f" done ({high_time:.2f}s). Sending {BYTES_PER_PATTERN:,} bytes of 0x00...", end="", flush=True)
low_start = time.time()
spi.writebytes2(data_low)
low_time = time.time() - low_start

total_time = time.time() - start_time
frequency = 1.0 / total_time

print(f" done ({low_time:.2f}s). Total: {total_time:.2f}s ({frequency:.2f} Hz)")

except KeyboardInterrupt:
print(f"\n\nStopped after {cycle_count} cycles")

except Exception as e:
raise e
finally:
try:
spi.close()
print("\nSPI device closed.")
except:
pass

return 0

if __name__ == '__main__':
exit(main())
Loading