Homepage of Andino IO

For all downloads, see our GitHub repository!


  1. Release the ttyAMA0 from getty and asign it to GIO14, GPIO15 (used for the Modem)
  2. Add a driver for the SPI UART (RS232 and RS485)
  3. Add a driver for the CAN Bus
  4. Add a driver for the Temperatur Sensor

cd ~/
wget https://github.com/andino-systems/Andino/raw/master/Andino-IO/BaseBoard/sc16is752-spi0-ce1.dtbo
sudo cp sc16is752-spi0-ce1.dtbo /boot/overlays/
sudo nano /boot/config.txt

Stop getty on serial0:

sudo nano /boot/cmdline.txt 

Remove “console=…
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 .....

sudo nano /boot/config.txt

add this at the end of the file..

# -----------------------
# Andino IO from here
# -----------------------

# SPI on
dtparam=spi=on dtoverlay=spi0-cs,cs0_pin=8,cs1_pin=7

# I2C on
dtparam=i2c_arm=on

# RTC
# sudo apt-get install -y i2c-tools
# i2cdetect -y 1
dtoverlay=i2c-rtc,ds3231

# CAN
# sudo apt-get install can-utils
# sudo ip link set can0 up type can bitrate 125000
# sudo ifconfig
# cansend can0 456#43414e2054657374
# candump can0
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25

# 1. UART
# /dev/ttyAMA0 = Modem
enable_uart=1
dtoverlay=pi3-disable-bt-overlay
dtoverlay=pi3-miniuart-bt

# 2. UART
# /dev/ttySC0 = RS485
# /dev/ttySC1 = RS232
dtoverlay=sc16is752-spi0-ce1

# DS1820 Temp sensor
# cat   /sys/bus/w1/devices/28-00000a990ab5/w1_slave
dtoverlay=w1-gpio-pullup,gpiopin=22,extpullup=on
dtoverlay=w1-gpio,gpiopin=22

After that reboot. Now we are ready to go!

The digital inputs are connected to the GPIO:

The Inputs are calculated for 24 Volt Input. Normaly a signal of 24 Volt is applied to Pin 2 and the Ground to Pin 3. (active Mode)

By closing the JumperX the Inputs can be driven in passive Mode or Dry Contact. This means a Switch / Relaycontact can be conneted between Pin 3 and Pin 2.

Andino IO - digital input schematics

Andino IO - digital input configuration

The Relay are controlled by the GPIO:

The Relays can drive 230V and up to 5 ampere. There a no Fuses at the relay contacts!!

The Power Fail Input can be used to inform the Raspberry about a Mains Power loss. This can be done by a Switch- / Relay-Contact. Just bridge Pin1 and Pin2 to signal Power good/fail.

Andino IO - Power Fail Input

This feature can be used together with the Andino UPS

sudo echo "18" > /sys/class/gpio/export
sudo echo "in" > /sys/class/gpio/gpio21/direction
cat /sys/class/gpio/gpio18/value

The RS232 and RS485 based on the SPI Uart from NXP [SC16IS752][1].

After prepare the Debian for the use of the SPI Uart (see Prepare Debian) the /dev/ttySC1 is the RS232 Channel. The Signals on the RS232 Port are +-12 Volt.

You can exit minicom with CTRL-A then X

sudo apt-get install minicom
sudo nano minicom –setup
# press Serial Port Setup

+-----------------------------------------------------------------------+
| A -    Serial Device      : /dev/ttySC1                               |
| B - Lockfile Location     : /var/lock                                 |
| C -   Callin Program      :                                           |
| D -  Callout Program      :                                           |
| E -    Bps/Par/Bits       : 38400 8N1                                 |
| F - Hardware Flow Control : No                                        |
| G - Software Flow Control : No                                        |
|                                                                       |
|    Change which setting?                                              |
+-----------------------------------------------------------------------+
        | Screen and keyboard      |
        | Save setup as dfl        |
        | Save setup as..          |
        | Exit                     |
        | Exit from Minicom        |
        +--------------------------+

sudo apt-get install python-serial

after that you can send data:

import serial
import time

ser = serial.Serial(
               port="/dev/ttySC1",
               baudrate = 9600,
               parity=serial.PARITY_NONE,
               stopbits=serial.STOPBITS_ONE,
               bytesize=serial.EIGHTBITS,
               timeout=3
           )

for i in range(2):
        ser.setRTS(False)
        time.sleep(0.01)
        ser.write(str(i)+ b"Hello 232\n")
        time.sleep(0.1)
        s = ser.readline()
        print( s.rstrip() )
        ser.setRTS(True)
ser.close()

After prepare the Debian for the use of the SPI Uart (see Prepare Debian) the /dev/ttySC0 is the RS485 Channel. It can be used as full duplex RS422 or as two wire RS485. In RS485 Mode the transmitter can be switched on either by the RTS signal or automaticaly.

RS485 Jumper

Send in manual mode

for i in range(2):
        # Transmitter on
        ser.setRTS(False)
        time.sleep(0.01)
        ser.write(str(i)+ b"Hello 485\r\n")
        time.sleep(0.1)
        s = ser.readline()
        print( s.rstrip() )
        # Transmitter off
        ser.setRTS(True)

Send in RS485 Auto mode

for i in range(2):
        ser.write(str(i)+ b"Hello 485\r\n")
        time.sleep(0.1)
        s = ser.readline()
        print( s.rstrip() )

The CAN Bus based on the Microchip MCP2515 and the Tranceiver MCP2551. It is supported by the Raspberry Pi.

sudo apt-get install can-utils
sudo ip link set can0 up type can bitrate 125000
sudo ifconfig can0
cansend can0 456#43414e2054657374
# or
candump can0

The Device has a Build in temperatur Sensor DS1820. The Sensor is wired to GPIO 22.

ls /sys/bus/w1/devices/
cat   /sys/bus/w1/devices/28-00000a990ab5/w1_slave
6a 01 4b 46 7f ff 06 10 5f : crc=5f YES
6a 01 4b 46 7f ff 06 10 5f t=22625

This is 22.6225 Degrees Celsius

The Modem is connected to the internal UART of the Raspberry Pi.

/dev/ttyAMA0

This Port has to configured to GPIO14 and GPIO15 (see Prepare Debian)

Modem Connector

You can find some example python scripts in this folder of the repository. You can test the modem with a simple python script:

#!/usr/bin/python
# -*- encoding: utf-8 -*-
import time
import serial

def send(data):
   p = serial.Serial("/dev/ttyAMA0" , 57600 )
   p.setRTS(False)
   time.sleep(2)
   p.write(data+"\x0d\x0a")
   data.rstrip()
   print(data)
   time.sleep(2)
   rdata=p.readline()
   rdata=rdata[:-1]
   print rdata

send("sys reset")

time.sleep(1)

send("mac get deveui")

And then, in a new terminal, you can get the eui from the device:

$ python get-deveui.py
sys reset
RN2483 1.0.4 Oct 12 2017 14:59:25
mac get deveui
0004A30B002544A2

The OLED Display is connected via the I2C Bus with the address 68. This can be seen when checking the i2c devices:

apt-get install -y i2c-tools
i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

0x3C is the OLED-Display 0x68 is the RTC

To print custom text on the display through external programs, the display driver and custom python script need to be installed. Please refer to Andino IO: Using the OLED display for a detailed installation guide.

Execute this

sudo -s
chmod +x /etc/rc.local 
apt-get purge -y fake-hwclock 
apt-get remove fake-hwclock -y 
dpkg --purge fake-hwclock 
rm -f /etc/adjtime. 
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
ln -s /home/pi/bin/ntp2hwclock.sh /etc/cron.hourly/ntp2hwclock
sudo reboot now

hwclock -w
hwclock -r

This Python script sets the NTP Time to the HWClock as long a NTP connection can established. Place this script at /home/pi/bin/ntp2hwclock.sh (for example, see above)

#!/bin/bash
# Location of logfile
LOGFILE="/usr/local/oeebox/etc/log/ntp.log"
if [ ! -f $LOGFILE ]; then
  touch $LOGFILE
fi
# Set the maximum allowed difference in seconds between Hw-Clock and Sys-Clock
maxDiffSec="2"
msgNoConnection="No connection to time-server"
msgConnection="Connection to time-server"
# Check for NTP connection
if ( ntpq -p | grep -q "^*"  ); then
        echo $msgConnection >> $LOGFILE
        echo "---------------------------------"  >> $LOGFILE
        secHwClock=$(sudo hwclock --debug | grep "^Hw clock time" | awk '{print $(NF-3)}')
        echo "HwClock: $secHwClock sec" >> $LOGFILE
        secSysClock=$(date +"%s")
        echo "SysClock: $secSysClock sec" >> $LOGFILE
        echo "---------------------------------" >> $LOGFILE
        secDiff=$(($secHwClock-$secSysClock))
        # Compute absolute value
        if ( echo $secDiff | grep -q "-" ); then
            secDiff=$(echo $secDiff | cut -d "-" -f 2)
        fi
        echo "Difference: $secDiff sec" >> $LOGFILE
        msgDiff="HwClock difference: $secDiff sec"
        if [ "$secDiff" -gt "$maxDiffSec" ] ; then
                echo "---------------------------------" >> $LOGFILE
                echo "The difference between Hw- and Sys-Clock is more than $maxDiffSec sec." >> $LOGFILE
                echo "Hw-Clock will be updated" >> $LOGFILE
                # Update hwclock from system clock
                sudo hwclock -w
                msgDiff="$msgDiff --> HW-Clock updated." >> $LOGFILE
        fi
        if !(awk '/./{line=$0} END{print line}' $LOGFILE | grep -q "$msgConnection") || [ "$secDiff" -gt "$maxDiffSec" ]; then
                echo $(date)": "$msgConnection". "$msgDiff >> $LOGFILE
        fi
else
        # No NTP connection
        echo $msgNoConnection
        if !(awk '/./{line=$0} END{print line}' $LOGFILE | grep -q "$msgNoConnection"); then
                echo $(date)": $msgNoConnection" >> $LOGFILE
        fi
fi

GPIO Mapping of the Andino IO

To enable WAN communication, please refer to the following setup tutorials:

Andino IO - Raspberry Pi on DIN Rail - Front view Andino IO - Raspberry Pi on DIN Rail - PCB Overview Andino IO - Raspberry Pi on DIN Rail - Block Diagram