RTk.GPIO - First looks on a Mac
RaspberryPi Input and output ports on your computer
I just received a RTk.GPIO from Ryanteck, for which I was part of the Kickstarter campaign. This is designed to allow you to have a set of GPIO ports similar to the Raspberry Pi via USB on your Windows or Mac.
I realised that the board has the much maligned CH340 chip on it, which has had its ups and downs with MacOS. Thankfully I read a really useful blog post the other day which had helped me to work out how to get the most up to date driver for this chip. So hoped that the work I had done with that on getting Arduino clones to work would work with this board too.
You can control the interface with Python, the same as on a Pi, so to get it on the Mac I had to install python from: https://www.python.org/downloads/release/python-353/
This downloaded as a pkg file and ran easily. Although it took a bit of careful reading to establish which installer to use for OSX Sierra first.
Once I had python installed the brief setup guide explained I had to run the following in Terminal on the Mac:
sudo -H pip3 install RTk
This burst to life after typing the password and off it went to download the RTk drivers and installed them:
Installing collected packages: pyserial, wheel, future, RTk Running setup.py install for future ... done Successfully installed RTk-0.3.7 future-0.16.0 pyserial-3.2.1 wheel-0.29.0
I didn't follow half or that. Never mind. I typed in Ryanteck's demo program using pico, saved as gpio.py and typed python gpio.py.
To which it replied:
Traceback (most recent call last): File "gpio.py", line 1, in
from RTk import GPIO ImportError: No module named RTk
After a lot of head scratching I discovered (thanks python-guide.org ) that I had installed Python 3, and appeared to be running the built in version of Python, which isn't what I had installed the RTK library into.
To remedy, I simply typed Python3 gpio.py instead. This now appeared to work better:
Error: RTk.GPIO not detected. For more support please visit our website at http://Ryanteck.com/rtk-000-00C Press enter to close.
I deduced from this that the drivers I had installed for my Arduino clones were not the same as the ones for the RTk.GPIO so went and installed them from the github at: https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver
I connected an LED to the ground pin and the other pin via a 330 Ohm resistor to pin 21 (which I had set in the code) and the LED lit up.
It didn't flash to begin with. This was because I had missed out the tab in the last sleep command, which meant the LED was only turning off for an instant each time around the loop, and the second sleep command was never executed.
Once that was all working as expected, I re-wired another LED and wrote my own test program. So here is my first OSX python RTk.GPIO program:
from RTk import GPIO from time import sleep LED1=21 LED2=20 GPIO.setmode(GPIO.BCM) GPIO.setup(LED1,GPIO.OUT) GPIO.setup(LED2,GPIO.OUT) while True: GPIO.output(LED1,1) GPIO.output(LED2,0) sleep(.5) GPIO.output(LED1,0) GPIO.output(LED2,1) sleep(.5)
This does a 'flip-flop' flash between two LEDs. Here it is running in its full glory:
Thanks for this Ryanteck. Thanks for the lesson in Python and OSX too!
24-Jan-2017 Add commentblog comments powered by Disqus Permanent Link