raspberry pi - best friend for all your gpio needs
TRANSCRIPT
Raspberry Pi - best friend for all your GPIO needs
Dobrica Pavlinušićhttp://blog.rot13.org
https://frab.fsec.foi.hr/en/fsec2015/public/events/9http://bit.ly/fsec2015-rpi
Summary
Raspberry Pi is well known little Linux machine which almost everybody has. But, did you know that it can replace multiple programmers and enrich your hacking toolbox?
In this talk, we will take a look how to use Raspberry Pi (any model) to program any 3.3V target device from AVR micro-controllers, CPLD and FPGA devices and even CC110x which is available in IM-ME, nice little gadget useful for sub-1GHz radio spectrum analysis.
We will cover openocd, urjtag, avrdude and other projects which are useful if you want to run your own code on more of less any device.
Raspberry Pi Model B (without plus) not newer, because we are cheap and everybody has at least one around
root@raspberrypi:/home/pi# git clone https://github.com/Pulse-Eight/libcec.git
root@raspberrypi:/home/pi# cd libcec/
root@raspberrypi:/home/pi/libcec# apt-get install autoconf automake libtool liblockdev1-dev
libudev-dev libraspberrypi-dev
root@raspberrypi:/home/pi/libcec# sh -x bootstrap
root@raspberrypi:/home/pi/libcec# ./configure --with-rpi-include-path=/opt/vc/include/ --with-rpi-
lib-path=/opt/vc/lib/
Can watch CEC messages on bus and send them, e.g. TV on
pi@raspberrypi ~ $ echo "on 0" | cec-client -s
It’s much simpler to turn TV on using IR led, resistor and LIRC if this is goal :-)
But, still probably easiest (no hardware required) platform to explore CEC
HDMI and CEC
pi@raspberrypi ~ $ gpio readall
+-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5V | | |
| 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | ALT0 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT0 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | OUT | 0 | 11 || 12 | 1 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 1 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | ALT0 | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | ALT0 | CE1 | 11 | 7 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| 28 | 17 | GPIO.17 | IN | 0 | 51 || 52 | 0 | IN | GPIO.18 | 18 | 29 |
| 30 | 19 | GPIO.19 | IN | 0 | 53 || 54 | 0 | IN | GPIO.20 | 20 | 31 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
WiringPi - http://wiringpi.com/
WiringPi is a GPIO access library written in C for the BCM2835 used in the Raspberry Pi. It’s released under the GNU LGPLv3 license and is usable from C and C++ and many other languages with suitable wrappers (See below) It’s designed to be familiar to people who have used the Arduino “wiring” system1
● Porting arduino code is possible, but due to Linux non-RT on rpi, for receivers and precies senders it’s better to fallback to AVR for tight timing.
● Support for IO expanders, chips● remote AVR orver serial to extend available pinns https://projects.drogon.
net/drogon-remote-control/drc-protocol-arduino/● Best way to shell script your GPIO!
PCF8591 8-Bit A/D D/A Converter Module I2C
pi@raspberrypi ~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi ~ $ gpio -x pcf8591:120:0x48 readall
+------+---------+--------+
| Pin | Digital | Analog |
+------+---------+--------+
| 120 | 0 | 132 |
| 121 | 0 | 224 |
| 122 | 0 | 89 |
| 123 | 0 | 119 |
+------+---------+--------+
pi@raspberrypi ~ $ gpio -x pcf8591:120:0x48 awrite 120 128
IR receive
IR send (use IR LED from TV remote!)
3.3V Arduino ProMini
433 send
433 receive
DS18B20 (mesuring air on top of rpi which has cpu at 50 deg. C)
v1
https://github.com/dpavlin/avrdude-rpi/tree/fix_channel_in_use
serial connection and additional reset pin
doesn’t require re-compiling avrdude (work on raspian out-of-box)
pi@raspberrypi ~ $ cat avrdude.sh
#!/bin/sh
hex=`ls -t /tmp/*.hex | head -1`
echo "flash hex: $hex"
sudo /home/pi/avrdude-rpi/avrdude-autoreset -C /home/pi/avrdude.
conf -v -v -patmega328p -carduino -P/dev/ttyAMA0 -b57600 -D -
Uflash:w:$hex:i
avrdude with auto-reset
And then you get 328p which doesn’t have boot loader
You could use external USB programmer, but hmmm...
AVR ISP
avrdude 3.3V ISP
Using Raspberry Pi as Arduino ISP programmer, save USB port
● https://github.com/onandoffables/avrdude-linuxgpio
root@raspberrypi:/home/pi# avrdude -c linuxgpio -p atmega328p
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: safemode: Fuses OK (E:05, H:DA, L:FF)
avrdude done. Thank you.
MiniPCIe/PCI/LPC Combo-Debug CardAltera MAX 3000A CPLDEPM3064ATC100
https://saturn.ffzg.hr/rot13/index.cgi?urjtag
pi@raspberrypi ~/urjtag/urjtag $ sudo jtag
jtag> cable gpio tms=18 tdi=23 tdo=24 tck=25
Initializing GPIO JTAG Chain
jtag> detect
IR length: 10
Chain length: 1
Device Id: 00010111000001100100000011011101 (0x170640DD)
Manufacturer: Altera (0x0DD)
Part(0): EPM3064A (0x7064)
Stepping: 1
Filename: /usr/local/share/urjtag/altera/epm3064a/epm3064a
https://saturn.ffzg.hr/rot13/index.cgi?minipcie_pci_lpc_combo_debug_card
urjtag EPM3064A
CC1110
IM-ME Console = CC1110+keyboard+display
http://daveshacks.blogspot.com/2010/01/im-me-hacking.htmlhttp://travisgoodspeed.blogspot.com/2010/03/im-me-goodfet-wiring-tutorial.htmlhttps://github.com/m0nk/IMME
● (square pad) RESET_N
● P2_1 = debug data
● P2_2 = debug clock
● +2.5 volts (CC1110 VDD max 3.9V)
● Gnd
Spectrum analyzer https://github.com/mossmann/im-megit clone https://github.com/tobyjaffey/cctl
pi@raspberrypi ~/cctl $ git diff
diff --git a/ccpil/dbg.c b/ccpil/dbg.c
index 9ca33da..2b4a796 100644
--- a/ccpil/dbg.c
+++ b/ccpil/dbg.c
@@ -30,9 +30,9 @@
#define NUM_ATTEMPTS 100
-#define PIN_DD RPI_GPIO_P1_11
-#define PIN_DC RPI_GPIO_P1_12
-#define PIN_RST RPI_GPIO_P1_13
+#define PIN_DD RPI_GPIO_P1_21
+#define PIN_DC RPI_GPIO_P1_23
+#define PIN_RST RPI_GPIO_P1_24
#define ST_CHIP_ERASE_DONE 0x80
wget https://github.com/mossmann/im-me/raw/master/specan/specan.hex
sudo ./ccpil -f specan.hex
dongle, cc1110 (no usb)removed HID chip
openocd JTAG 3.3V
https://github.com/synthetos/PiOCD/wiki/Using-a-Raspberry-Pi-as-a-JTAG-Dongle
Due Pi
JTAG_TCK (Debug header) 11
JTAG_TMS (Debug header) 25JTAG_TDI (JTAG header, with clip) 10JTAG_TDO (JTAG header, with clip) 9MASTER-RESET (Debug header, closest to the reset button) 7
GND (Debug header) GND
./configure --enable-sysfsgpio --enable-maintainer-mode --disable-
werror --enable-usbprog --enable-dummy --enable-buspirate --
enable-bcm2835gpio --enable-stlink --enable-usb-blaster-2 --
enable-usb_blaster_libftdi --enable-remote-bitbang
it should be possible :-)
openocd 0.10 SWD without ST-Link?
Raspberry Pi compile is slow!
distcc for compiling, qemu-user is helpful for modifying images http://openframeworks.cc/setup/raspberrypi/Raspberry-Pi-DISTCC-guide.html
https://xkcd.com/303/
PWM, power glitzing?
SPI and bit-bang displays
bonus
current rpi setup v3
DHT22
315 Mhz send
433Mhz send
● PWM on the Raspberry Pi - DMAhttps://github.com/sarfata/pi-blaster
ULN2803A Darlington Transistor Arrays
Check if module has 5V pull-up I2C resistors! If it does (like Tiny RTC has R2 and R3)you will have to remove them.
root@raspberrypi:/home/pi# apt-get install i2c-tools
root@raspberrypi:/home/pi# modprobe i2c-dev
root@raspberrypi:/home/pi# i2cdetect -y 1
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@raspberrypi:/home/pi# modprobe rtc-ds1307
root@raspberrypi:/home/pi# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
root@raspberrypi:/home/pi# hwclock --systohc -D --noadjfile --utc
hwclock from util-linux 2.20.1
Using /dev interface to clock.
Assuming hardware clock is kept in UTC time.
Time elapsed since reference time has been 0.722720 seconds.
Delaying further to reach the new time.
Setting Hardware Clock to 11:53:41 = 1429876421 seconds since 1969
ioctl(RTC_SET_TIME) was successful.
DS1307 Tiny RTC
https://github.com/notro/fbtft/wiki
https://saturn.ffzg.hr/rot13/index.cgi?tft01_2_2s
pi@jpi1 ~ $ sudo modprobe fbtft_device name=adafruit22a
verbose=1
pi@jpi1 ~ $ dmesg | tail -8
[ 173.796933] fbtft_device: Deleting spi0.0
[ 173.797590] spi spi0.0: setting up native-CS0 as GPIO 8
[ 173.797807] fbtft_device: GPIOS used by 'adafruit22a':
[ 173.797833] fbtft_device: 'reset' = GPIO25
[ 173.797851] fbtft_device: 'dc' = GPIO24
[ 173.797864] fbtft_device: 'led' = GPIO18
[ 173.838265] fb_ili9340: module is from the staging
directory, the quality is unknown, you have been warned.
[ 174.220426] graphics fb1: fb_ili9340 frame buffer,
240x320, 150 KiB video memory, 4 KiB DMA buffer memory,
fps=20, spi0.0 at 32 MHz
fbtft
● rpp - PIC Programmer using GPIO http://holdenc.altervista.org/rpp/ and newer http://mujweb.cz/tlc/rpp/
● SWD python http://www.disk91.com/2015/technology/programming/swd-programming-using-a-raspberrypi/
● FreeLSS is a laser scanning program for the Raspberry Pi. It allows a Raspberry Pi to function as the core to a complete turn table laser scanning system.https://github.com/hairu/freelss
● https://github.com/ali1234/raspi-teletext
● https://github.com/jgarff/rpi_ws281x
● https://saturn.ffzg.hr/rot13/index.cgi?raspberrypi
Raspberry Pi links
Why do we need AVR and JTAG/SWD programmers anyway?
Program all things!
Transistor tester ebay searchWhich one to buy?! $15-30http://blog.rot13.org/2015/06/dorscluc-2015-avr-component-tester.html
IMAX B6 battery charger
https://github.com/stawel/cheali-charge
AVR IMAX B6 clone $30-40Nuvoton NuMicro M0517LBN CPU - ARM SWD https://github.com/sasam/M0517_flash_toolshttps://github.com/hackocopter/SWD-Hacking
cheap 315 MHz relay from china - Testing 4 channel RF relay 220V with 3W led bulbs... Total 4 A with all 4 on... 45-50 deg C on leds after half hour
related: http://blog.rot13.org/2014/12/controlling-315-mhz-light-sockets-using-arduino.html