Raspberry Pi Serial Comms – Gambas plus wiringPi

I’ve been playing around with serial comms on my Pi/Picaxe dev rig.

Using Gordon’s wiringPi library makes it easy to open the gpio serial comms port on the Pi and write code with Gambas.

So this post involves writing a simple Picaxe program, and then using wiringPi and Gambas on the Pi to communicate with the Picaxe.

Much of the configuration stuff is described in my previous posts which you can link to from here:-

I am using a PiB2 running Raspbian Jessie, and found I needed the very latest versions/updates for wiringPi and Jessie.

I’m running Gambas v3.5.4 which can be installed straight from the Jessie repository. Dont forget you will need to run Gambas as root, which you can do from a terminal with:-

gksu gambas3

The Picaxe I’m using is an 08M2, but in principle you could use other models/variants.

Picaxe test program

Initially I wrote a simple Picaxe program to send data to the Pi, which looked like this:-

‘Serial comms check
‘===================
‘Send a message at 3s intervals
‘+++++++++++++++++++++++++++++++++++
b0 = 1
main:
SerOut 0,N4800,(“Hi Pi!  “,#b0,13)    ’13 = CR, 10=LF
inc b0
pause 3000
goto main

Once compiled and downloaded, I used minicom to check that the Pi was receiving the message. So in a terminal:-

sudo minicom -D /dev/ttyAMA0 -b 4800

…which should result in an output like this:-

Raspberry Pi Serial Comms - Gambas plus wiringPi

Welcome to minicom 2.7

OPTIONS: I18n
Compiled on Jan 12 2014, 05:42:53.
Port /dev/ttyAMA0, 09:18:17

Press CTRL-A Z for help on special keys

Hi Pi!  18

…where the “Hi Pi!” number increments every 3 seconds.

If all is OK, its time to write a Gambas program for the Pi.

Using wiringPi in Gambas

After wiringPi has been downloaded, un-packed and built (as described in my previous posts) we need to add declarations to a new Gambas project, which I’ve called: Picaxe2Pi

‘ Gambas class file
Library “/usr/local/lib/libwiringPi” Public Extern wiringPiSetup() As Integer
Public Extern serialOpen(strPort As String, intBaud As Integer) As Integer
Public Extern serialClose(intFileDescriptor As Integer)
Public Extern serialGetchar(intFD As Integer) As Integer

…and declare a few global variables & constants:-

Public iFD As Integer
Const Pi_PORT As String = “/dev/ttyAMA0”
Const BAUD_RATE As Integer = 4800

 

For more detail: Raspberry Pi Serial Comms – Gambas plus wiringPi

About The Author

Scroll to Top
Read previous post:
LiTiny- A Tiny LiIon
LiTiny- A Tiny LiIon charger for most things battery

Lithium Batteries are indispensable. I have a few project like my own DIY Badge [Post Soon] or a Light Wand...

Close