Sunday, May 6, 2018

beaglebone - Making a simple remote host system by accessing gpio through c code + simple tui

With the advancing and mass production of single board computer, the hardware getting cheap and the software getting stable, the community getting stronger, there are a lot of things do not seem out of reach now.

I want a simple remote host system which allowed me to do simple on / off and serial console terminal software to remote slave system.

Power control:
[MY PC] --> [Remote Host System] --> [Relay] --> [Remote Slave System Power Supply]

Communication:
[MY PC] --> [Remote Host System] --> [Serial Console Terminal] --> [Remote Slave System]

Power Control
For power control, I only need to control GPIO. Looking at the beaglebone pinout, I choose GPIO_66 and GPIO_67.


I am using the newest Beaglebone Black image
"
debian@beaglebone:~$ uname -a
Linux beaglebone 4.9.78-ti-r94 #1 SMP PREEMPT Fri Jan 26 21:26:24 UTC 2018 armv7l GNU/Linux
"
where all sysfs for gpios are exported. Good for me. I highlighted gpio66 and gpio67.

I want to control everything through c code.
I found the library written by derekmolloy/beaglebone.
https://github.com/derekmolloy/beaglebone
SimpleGPIO.cpp
SimpleGPIO.h

The library is intuitive and minor modification to get the thing working, at least for my case.

Along that, I can some simple user interface. This is where termbox come along.
I want a simple mouse click to turn on and turn off the relay.
This is the interface I created and use the led for indication.
Red square is the indication of the led is on, while blank indicate the led is off.

This is the actual wiring diagram.


Communication:
For serial console terminal in Linux, after trying two minicom and picocom, I decided to go with picocom. Ok, I lied. I only tried picocom and it is working. Didnt bother to go and try another one.
Source: https://github.com/npat-efault/picocom
Command used: picocom -b 115200 -r -l /dev/ttyS0

debian@beaglebone:~/software/picocom-master$ ./picocom -b 115200 -r -l /dev/ttyUSB0
picocom v3.2a

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : yes
hangup is      : no
nolock is      : yes
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        :
omap is        :
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready

I felt the interface not bad. Here are the hot keys
*** Picocom commands (all prefixed by [C-a])

*** [C-x] : Exit picocom
*** [C-q] : Exit without reseting serial port
*** [C-b] : Set baudrate
*** [C-u] : Increase baudrate (baud-up)
*** [C-d] : Decrease baudrate (baud-down)
*** [C-i] : Change number of databits
*** [C-j] : Change number of stopbits
*** [C-f] : Change flow-control mode
*** [C-y] : Change parity mode
*** [C-p] : Pulse DTR
*** [C-t] : Toggle DTR
*** [C-g] : Toggle RTS
*** [C-|] : Send break
*** [C-c] : Toggle local echo
*** [C-w] : Write hex
*** [C-s] : Send file
*** [C-r] : Receive file
*** [C-v] : Show port settings
*** [C-h] : Show this message

I would say neat after you explore further.

For current moment, it is suffice for my usage.

Two basic proof of concept are done, now it is time to do it on actual platform.
Still pending for my relay. Till next time then.