Look inside the Turnigy 9X

ATmega64 processor Controller internals

Installing jumper leads

Jumper leads on circuit board Jumper leads on circuit board alternate Pins on raspberry pi Pins on raspi alternate

Install avrdude on Raspi

Option A - Install with apt

This is easiest method but see footnote

sudo apt update
sudo apt install avrdude

Footnote: for me apt installs avrdude revision 6.3-20171130+svn1429-2+rpt1. You may run into 2 issues using packaged binaries: 1) Avrdude needs to be compiled with a linuxgpio flag 2) There appears to be a bug in revision 6.3 that breaks linuxgpio. Install a revision before or after 6.3 otherwise you will get the error Can't export GPIO 8, already exported/busy?: Invalid argument. (bug link: http://savannah.nongnu.org/bugs/?47550) Check what version your apt will use with apt-cache policy avrdude

Option B - Install from source

sudo apt update
sudo apt install -y build-essential bison flex automake libelf-dev libusb-1.0-0-dev libusb-dev libftdi-dev libftdi1
wget http://download.savannah.gnu.org/releases/avrdude/avrdude-6.2.tar.gz
tar xvfz avrdude-6.2.tar.gz
cd avrdude-6.2
./configure --enable-linuxgpio
make
sudo make install

Ensure avrdude is installed correctly

cd ~
avrdude -v

Configure avrdude

Edit config for avrdude

# This is for apt install method, if using manual install find global config
# file location with avrdude -v
sudo nano /etc/avrdude.conf

Use Ctrl+w to find linuxgpio. Uncomment the config and edit it so it looks like:

programmer
  id    = "linuxgpio";
  desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
  type  = "linuxgpio";
  reset = 8;
  sck   = 11;
  mosi  = 10;
  miso  = 9;
;

Check avrdude is installed properly

avrdude -v

Footnote: in theory this could be done with user config (~/.avrduderc) but this does not work since all avrdude read/write commands need to be run with sudo due to Raspi bug here (http://avr.2057.n7.nabble.com/bug-44218-linuxgpio-not-working-with-raspberryPi-2-quot-Can-t-open-gpioX-direction-quot-Permission-dy-td21548.html) (https://github.com/raspberrypi/linux/issues/553)

Connect Turnigy 9X to Raspi

Install gpiozero

sudo apt install python3-gpiozero

Get the pinout of you board with

pinout

This prints the pinout of your board like this

There are two number types, the physical pin numbers which are in brackets (19), and the internal Broadcom “BCM” pin numbers like GPIO10. The BCM pin numbers are what is referenced in the avr configuration so wire the Turnigy 9X and Raspi up as follows:

           3V3  (1) (2)  5V
         GPIO2  (3) (4)  5V     -- VCC+
         GPIO3  (5) (6)  GND    -- GND
         GPIO4  (7) (8)  GPIO14
           GND  (9) (10) GPIO15
        GPIO17 (11) (12) GPIO18
        GPIO27 (13) (14) GND
        GPIO22 (15) (16) GPIO23
           3V3 (17) (18) GPIO24
MOSI -- GPIO10 (19) (20) GND
MISO --  GPIO9 (21) (22) GPIO25
 SCK -- GPIO11 (23) (24) GPIO8  -- RESET
           GND (25) (26) GPIO7

Choosing the chip type to chip with avrdude

You can list all the AVR microcontrollers configured to work with avrdude with

avrdude -c linuxgpio -v

Read the text on the chip in your 9X to determine which AVR microcontroller it is and match it to one in the list from the command above. Mine chip reads ‘ATMEGA64A AU 1309’. Avrdude doesn’t appear to have a config for the ATmega64A but a quick search reveals that ATmega64A is a drop in replacement for the ATmega64 which has a config m64

Try connecting to the chip with

sudo avrdude -c linuxgpio -p m64

OpenTX Install

Get the companion app and download which ever firmware version you want to use.

om@DESKTOP-7T7GALB:/mnt/c/Users/om/Downloads$ rsync -r raspi-share/ pi@10.0.0.138:~/raspi-share/
om@DESKTOP-7T7GALB:/mnt/c/Users/om/Downloads$ rsync -r pi@10.0.0.138:~/raspi-share/ raspi-share/

ER9XV2 (aka mbtx) Install

mbtx5a.zip from https://openrcforums.com/forum/viewtopic.php?f=5&t=8217 use mbtx.hex

make backup of current firmware

sudo avrdude -c linuxgpio -p m64 -v -U flash:r:flash_dump.hex:i

write mbtx.hex

sudo avrdude -c linuxgpio -p m64 -v -U flash:w:mbtx.hex:i

Debugging

If you some of the commands without sudo you will get error Can't open gpioX/direction: Permission denied. Subsequent commands will then fail with Can't export GPIO 8, already exported/busy?: Device or resource busy. To fix this run sudo echo 8 > /sys/class/gpio/unexport

https://github.com/raspberrypi/linux/issues/553