Raspberry Pi With Arduino Uno and Golang
Raspberry Pi With Arduino Uno and Golang
priyabgeek.blogspot.com/2016/09/raspberry-pi-with-arduino-uno-and-golang.html
Background
I just bought an Arduino Uno to continue my IOT experiments and one of the first
experiments that I wanted to carry out was to check how I can setup Arduino Uno with my
Raspberry PI 3 mod b model and make it work.
It must be understood that what I am going to explain now involves a bit of hack and hence
should be done with utmost care as it may change your Raspberry pi settings specifically
with that of inbuilt Bluetooth.
I wanted to try and see how we can program Arduino with Raspberry Pi without Arduino
IDE. Turns out we can do it using serial port and though we can do Arduino programming
and serial port programming using python for this particular instance I chose Golang. I
wanted particularly to explore the gobot framework which is suited for robotics and Arduino
programming.
A better solution is to disable BT and map UART1 back to UART0 (ttyAMA0) so we can talk
to Arduino in the same way as before.
1/5
Step 1: Update the system with:
dtoverlay=pi3-miniuart-bt
sudo reboot
Note:
There is now a device tree file called pi3-miniuart-bt which makes the Raspberry Pi 3
disable the Bluetooth and map pl011 UART on pins 14 and 15 as before.
Enabling the Serial Console Rasbian Jessie after 18th March 2016 release
To enable the serial console, you need to edit the /boot/cmdline.txt file
With the serial console enabled you should now have the boot commands and login prompt
when connected at 115200 baud.
2/5
(Reference: https://www.abelectronics.co.uk/kb/article/1035/raspberry-pi-3-serial-port-
usage)
Once plugged in, use Gort's gort scan serial command to find out your connection info and
serial port address:
Use the gort arduino install command to install avrdude, this will allow you to upload firmata
to the arduino:
$ gort arduino install
Once the avrdude uploader is installed we upload the firmata protocol to the arduino, use
the arduino serial port address found when you ran gort scan serial, or leave it blank to use
the default address ttyACM0:
$ gort arduino upload firmata /dev/ttyACM0
Now you are ready to connect and communicate with the Arduino using serial port
connection
(Reference: https://gobot.io/documentation/platforms/arduino/)
The below packages for Arduino platform provide the adaptor for microcontrollers such as
Arduino that support the Firmata protocol. The sample program to run is given below:
3/5
// testarduino.goimport (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
)
func main() {
gbot := gobot.NewGobot()
firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "led", "13")
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}
4/5
The output can be watched in the following video where an led on Arduino is blinking
5/5