pimoroni / unicorn-hat-hd

Python library and examples for Unicorn HAT HD
https://shop.pimoroni.com/products/unicorn-hat-hd
MIT License
172 stars 69 forks source link

Unicorn hat hd with jetson Nano #38

Closed 32nguyen closed 5 years ago

32nguyen commented 5 years ago

Hi,

I am trying to use NVIDIA jetson nano to control unicorn hat hd thought Jetson.GPIO which is provided by jetson board. It is supposed to replace RPi.GPIO somewhere in unicorn library. Would please please point it out for me? Have you tested unicorn library on others device containing 40 header pins.

Thanh

Gadgetoid commented 5 years ago

Unicorn HAT HD doesn't use GPIO- it uses the SPI bus through the kernel SPI interface. This should, in theory, work on the jetson nano as long as it has a functional SPI bus accessible in this way. You may have to change this line to adjust the bus/chip select pin:

https://github.com/pimoroni/unicorn-hat-hd/blob/c83fbcd28ae9e83abf0b87cee36761067df3a3d1/library/unicornhathd/__init__.py#L102

Failing that, you'd have to manually "bitbang" SPI and replace the calls to xfer2 with a function that clocks the data out via GPIO:

https://github.com/pimoroni/unicorn-hat-hd/blob/c83fbcd28ae9e83abf0b87cee36761067df3a3d1/library/unicornhathd/__init__.py#L279-L282

A not necessarily clear example of this is in Blinkt! which has a bitbanged _write_byte function which is effectively what xfer2 would call for each byte passed in:

https://github.com/pimoroni/blinkt/blob/db430642a13416925e0d6e7854ebfb829647d225/library/blinkt.py#L47-L54

def _write_byte(byte):
    for x in range(8):
        GPIO.output(DAT, byte & 0b10000000)
        GPIO.output(CLK, 1)
        time.sleep(0.0000005)
        byte <<= 1
        GPIO.output(CLK, 0)
        time.sleep(0.0000005)
32nguyen commented 5 years ago

Hi @Gadgetoid

Thanks for your detail. I will try it out.