Sites and articles referenced writing this:
https://bootlin.com/labs/doc/nunchuk.pdfhttps://learn.adafruit.com/16-channel-p ... ng-drivershttps://computers.tutsplus.com/tutorial ... -cms-20984https://www.raspberrypi.org/forums/view ... 44&t=98318https://mcpeppr.wordpress.com/2015/02/0 ... is-broken/https://pimylifeup.com/raspberry-pi-wii ... ntrollers/https://raspberrypi.stackexchange.com/q ... g-wiringpihttps://learn.adafruit.com/adafruit-16- ... cking-hatshttps://www.raspberrypi.org/forums/view ... p?t=135364https://raspberrypi.stackexchange.com/q ... wont-starthttps://help.ubuntu.com/community/CWiiDhttps://hackaday.com/2019/05/13/wii-nun ... y-pi-zero/https://www.raspberrypi.org/forums/view ... p?t=122260viewtopic.php?f=3&t=17024&p=262942&hilit=shoulder+cannon#p262942https://pythonbasics.org/python-play-sound/https://my.eng.utah.edu/~cs5780/debouncing.pdfhttps://hackaday.com/2015/12/09/embed-w ... ns-part-i/https://pythonforbiologists.com/printin ... ating-texthttps://www.python-course.eu/tkinter_text_widget.phphttps://realpython.com/python-print/https://forums.envato.com/t/trying-to-c ... him/304683https://www.kite.com/python/answers/how ... -in-pythonhttps://stackoverflow.com/questions/324 ... -time?lq=1https://stackabuse.com/parallel-processing-in-python/https://www.raspberrypi.org/forums/view ... p?t=195859https://realpython.com/python-while-loop/https://ray.io/https://www.element14.com/community/thr ... hread=truehttps://keyboardinterrupt.org/catching- ... pt-signal/https://stackoverflow.com/questions/306 ... ray-objecthttps://learn.sparkfun.com/tutorials/i2c/allhttps://raspi.tv/2013/how-to-use-interr ... pio-part-2https://github.com/adafruit/circuitpyth ... master.ziphttps://github.com/adafruit/Adafruit_Ci ... master.ziphttps://sourceforge.net/p/raspberry-gpi ... ki/Inputs/viewtopic.php?f=3&t=17024&hilit=raspberry+predator+cannon&start=25https://www.element14.com/community/thr ... hread=truehttps://www.amazon.com/Python-Programmi ... 154&sr=8-2https://github.com/boppreh/keyboard/archive/master.zipTo communicate with the Nunchuk, we must send a handshake signal. If you are using a black Wii Nunchuk, send 2 bytes 0xF0, 0x55 to initialize the first register and 0xFB, 0x00 to initialize the second register of the Nunchuk. On a white Wii Nunchuk, send 0x40, 0x00 followed by 0x00. The I2C address of both Wii Nunchucks is 0x52. The frequency used to communicate with the Wii Nunchuk is 100khz
Source:
https://pimylifeup.com/raspberry-pi-wii ... ntrollers/OK now the base addresses of the wii nunchuck conflicts with the pca9685 bonnet. 0x40 is shared with the nunchuck. We are not able to change the address of the nunchuck so we have to change the address of the bonnet. In my case I bridged pin a2 to give it a base adress of 0x44. This solved the conflict. I would note that this is a big issue as when you have i2c addresses clash you will get no results when running i2cdetect -y 1. (older versions of the pi may have to use a zero instead of a 1.)
Source:
https://learn.adafruit.com/16-channel-p ... ng-driversto setup the nunchuck just do these simple steps.
run: sudo raspi-config
under interfacing options select spi, seril, i2c and set them to on. DO NOT turn on 1-wire. (having 1-wire on breaks the pimoroni onoff shim from working (had a hell of a time finding out that one as the pimoroni forums are not exactly like most forums))
in raspi-config is network options and you can connect to wireless from there. If you get errors about wpa_supplicant you will have to run this command:
sudo wpa_suppicant -c "/etc/wpa_supplicant/wpa_supplicant.conf" -iwlan0 -d
If you are using outdated wireless settings you will have to add your network settings to wpa_supplicant.conf manually:
with the following in that file: network={ ssid="networkname" psk="networkpassword" }
Localisation options are where you set the keyboard and other country settings (timezone, wifi country, locale) Linux and keyboards can suck if you do not have the correct mapping and this is where you set it the easy way.
to boot/config.txt add:
dtparam=i2c_arm=on
dtparam=spi=on
dtparam=i2s=on
to /etc/modprobe.d/rspi-blacklist.conf add:
#blacklist spi-bcm2708
#blacklist i2-bcm2708
/usr/local/lib/python3.5/dist-packages/adafruit_pca9685.py <-- change ox40 to ox44
Now update the pi once you have it on the network:
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo rpi-update
sudo apt-get install python-cwiid
sudo apt-get install wminput
sudo apt-get install bluetooth <-- only needed if you have a very old raspberry pi
sudo apt-get install i2c-tools
sudo apt-get install python-smbus -
sudo pip3 install adafruit-circuitpython-servokit
sudo pip3 install --upgrade setuptools
sudo apt-get install python3-pip
pip3 install RPI.GPIO
pip3 install adafruit-blinka <--failed? <-- use --upgrade switch to upgrade...
pip3 install adafruit-circuitpython-bme280
sudo pip3 install adafruit-circuitpython-pca9685
sudo pip3 install adafruit-circuitpython-servokit
sudo pip3 install adafruit-circuitpython-busdevice
sudo pip3 install adafruit-circuitpython-register
pip3 install adafruit-circuitpython-lis3dh
sudo pip3 install adafruit-Blinka
sudo pip3 install adafruit-circuitpython-motor
sudo apt-get install python3-smbus
sudo pip3 install pydub
sudo pip3 install numpy
sudo pip3 install keyboard
sudo pip3 install pathlib
sudo pip3 install rst2pyi
sudo pip3 install gpiozero
sudo pip install gpiozero
sudo pip3 install RPI.GPIO
sudo pip3 install --upgrade adafruit_blinka
sudo pip3 install adafruit-circuitpython-max31855
sudo pip3 install adafruit-circuitpython-gps
A word on libraries. libraries are like your public library. They are only as good as the amount of books that they have that YOU can use. Some books will be there by default, but other books you have to specifically request or donate/install at the library. each book when used will expand your ability to do things. Every distribution of a given utility be it python, mysql, php, www, etc, has a path variable and set of location(s) where functions/libraries are placed. Some utilities will have multiple versions installed or present and some of the previous versions will be symbolic links or symlinks to the latest version for compatibility with older untilities. The libraries are extensions or plug-ins for binaries and secured binaries (bin and sbin) processes/executables. the root directies of /bin and /sbin and /lib are for core system functionality. add-on utilities and things beyond core system functionality are located at /usr/local/bin/ , /usr/bin , /usr/sbin , /usr/local/sbin , /usr/lib , /usr/local/lib. User installed utilities and libraries are typically housed in /usr/local in sub folders there. But, the system configuration files and anything outside of those categories goes into /etc. logs are typically stored in /var. boot configuration files are stored in /boot. /boot is assessible on the sd card if you mount it on another computer and is a quick cheat to quickly move files to your raspberry pi if you have large files to move or do not want to hook it up to the internet for whatever reason or need. Knowing that most of your manual installs will get placed in one of those folders. In my case in this exploration of development I had to manually install the keyboard, debounce, nunchuck in /usr/local/lib/python3.5/dist-packages. This amounted mainly consisted of downloading the files as a zip from github, and unzipping them to the relevant folder.
Now saying all that that information is handy to know as you are troubleshooting errors. the errors will literally point you to what is missing and then you have to research that module and how to invoke the install for it or ensure that it is registered and present on the system and recognized. In the CentOS/Redhat world these errors are referred to as dependency hell and it can be a very time consuming and frustrating exercise in patience to get all requirements met to make something work. That said make sure to liberally document all steps taken so you have some basis to later replicate your work.
Simple run setup test of nunchuck.
wget
https://raw.githubusercontent.com/Boeee ... unchuck.pysudo python
from nunchuck import nunchuck
wii = nunchuck()
wii.raw()
wii raw will get you directional and accelerometer readings.
source:
https://computers.tutsplus.com/tutorial ... -cms-20984Since you are running two i2c devices you will need push resisters on the SCL and SDA data lines. The nunchuck has additional pins you can use for this so you are going to be running a 6 wire harness. Due to resistance and physics it helps to keep all wires as close to the same length as possible. If you are running a nunchuck all by itself this should not be an issue.
On the Pimoroni onoff shim if you need to not have it mounted just hook up these wires:
5v to 5v, gnd to a gnd. 3v3 to 3v3 for led. io#4 and #17 to the relevant pins.
And make sure 1-wire interface is turned OFF.
From Pimoroni Software:
We've put together a one-line-installer to install the clean shutdown daemon. It watches the state of BCM pin 17 and, when pulled low (pressed), it initiates a clean shutdown. Last thing, just before your Pi shuts down, BCM pin 4 is pulled low to completely cut power to your Pi.
To install the software, open a terminal and type curl
https://get.pimoroni.com/onoffshim | bashto run the one-line-installer.
source:
https://shop.pimoroni.com/products/onoff-shimIf you need to alter your scripts for startup and shutdown reference this article:
https://retropie.org.uk/forum/topic/157 ... pimoroni/4I have been chipping away at things and I just want to get some notes out there. At this point I am tracing down some nasty error codes in what we Linux geeks like to call dependency hell. You need this but you don't have that. You go to install that and this other thing is needed. You go to get this other thing and you need to install this thingamabob. You to go to install the thingamabob and the whachamawhooseit is needed. You go to look for the whachamawhooseit and realise you ran out of coffee, need to sleep and tray again from scratch.
That is dependency hell. I try to take all the guess work out on the write ups I do so others that are less technical do not tear their hair out if they have any left to remove to start with...
setting up the GPIO pin as an imput pin and in python "GPIO.setup(encoder_pin, GPIO.IN)" would be the same (not sure if there is a wired in pull up/down resistor in the circuit or you will need to setup to use the RPi internal 1). attachInterrupt is to configure the call back to call the counter function on a rising GPIO pin, python would use "GPIO.add_event_detect"
Ok lets look at the callback function next (the counter function). Basically it only does 1 thing if all the debounce is correct then increment the global variable pulses. In python you will set all the debounce in when setting it up in the initialization "GPIO.add_event_detect" google it. So in python the counter function will only have 2 lines "global pulses" and "pulses +=1"
https://www.raspberrypi.org/forums/view ... p?t=195859You may notice that the callbacks are called more than once for each button press. This is as a result of what is known as 'switch bounce'. There are two ways of dealing with switch bounce: add a 0.1uF capacitor across your switch, software debouncing, or a combination of both
To communicate with the Nunchuk, we must send a handshake signal. If you are using a black Wii Nunchuk, send 2 bytes 0xF0, 0x55 to initialize the first register and 0xFB, 0x00 to initialize the second register of the Nunchuk. On a white Wii Nunchuk, send 0x40, 0x00 followed by 0x00. The I2C address of both Wii Nunchucks is 0x52. The frequency used to communicate with the Wii Nunchuk is`100khz
OK now the base addresses of the wii nunchuck conflicts with the pca9685 bonnet. 0x40 is shared with the nunchuck. We are not able to change the address of the nunchuck so we have to change the address of the bonnet. In my case I bridged pin a2 to give it a base adress of 0x44. This solved the conflict. I would note that this is a big issue as when you have i2c addresses clash you will get no results when running i2cdetect -y 1. (older versions of the pi may have to use a zero instead of a 1.)
The wiinunchuck libs can run under python version 1. To run under python version3 you have to update smbus to python3. The pca9685 appears to only work when running under python version 3 or python3 command versus regulary python from the command line. I will have to rehash the old Arduino code to convert to a usable python script. At this point I am only focused on getting a working python script. I will worry about Daemonizing it later.
to setup the nunchuck just do these simple steps.
run: sudo raspi-config
under interfacing options select spi, seril, i2c and set them to on. DO NOT turn on 1-wire. (having 1-wire on breaks the pimoroni onoff shim from working (had a hell of a time finding out that one as the pimoroni forums are not exactly like most forums))
in raspi-config is network options and you can connect to wireless from there. If you get errors about wpa_supplicant you will have to run this command:
sudo wpa_suppicant -c "/etc/wpa_supplicant/wpa_supplicant.conf" -iwlan0 -d
If you are using outdated wireless settings you will have to add your network settings to wpa_supplicant.conf manually:
with the following in that file: network={ ssid="networkname" psk="networkpassword" }
Localisation options are where you set the keyboard and other country settings (timezone, wifi country, locale) Linux and keyboards can suck if you do not have the correct mapping and this is where you set it the easy way.