RPi3 serial connection to SleepyPi2

Update: I researched a little more and specified my questions.

I am trying to connenct my RPi3 to the extension Board SleepyPi2.
I want to restart the RPi3 every night by force or definde on/off times and be able to change the script on the arduino from the RPi3.

I have to confess that I am not very familiar with serial connections and have only used the SleepyPi2 with the official install script and ArduinoIDE. I would love to get some input from you on how to do it and on what i have done so far.

The Prerequisited for using this Board are the following (I’ll call them original documentation) and I would like to know how to achieve them with resin:

  1. Disable Serial Port Login

I found this thread from mid '17 which suggest to do

systemctl mask serial-getty@ttyAMA0.service

The original documentation with a standard Raspbian Software tells me todo:

sudo systemctl stop serial-getty@ttyS0.service 
sudo systemctl disable serial-getty@ttyS0.service

because the mapping of the port has been changed with the newest raspbian release.
Which one is right if I use

resin/%%RESIN_MACHINE_NAME%%-python:3.6

in my Dockerfile? (My device is currently on Resin OS 2.12.5+rev2 (dev) and Supervisor Version 7.1.18)
And I guess that I have to run this in the host-os but is there a possibility to do this automatically so I dont have to do it for every device I build (~100 in the next months)

  1. Enable UART

I have activated the Setting Enable UART in my Fleet Configurations, which should be equivalent to

sudo nano /boot/config.txt

and add the line:
enable_uart=1

in the original documentation?

  1. Disable Boot Info

The original documentation tells me to

sudo nano /boot/cmdline.txt

It will look something like:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait

Delete the “console=serail0,115200″ parts so that you are left with:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait

What is the equivalent to this in Resin?

  1. Set up the Reset (DTR) Pin at GPIO 22

The original documentation uses a modified version of avrdude and links it to the /usr/bin/avrdude:

wget https://github.com/SpellFoundry/avrdude-rpi/archive/master.zip
sudo unzip master.zip
cd ./avrdude-rpi-master/
sudo cp autoreset /usr/bin
sudo cp avrdude-autoreset /usr/bin
sudo mv /usr/bin/avrdude /usr/bin/avrdude-original
sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude

Can I just do the same process inside my container or do I have to perform it on my hostOS?

Currently I have a copy of the repo added to my Container and perform the actions within the container with a setup-script:

echo 'Copying autoreset to /usr/bin'
cp /sonah/src/sleepypi/install/autoreset /usr/bin
echo 'Copying avrdude-autoreset to /usr/bin'
cp /sonah/src/sleepypi/install/avrdude-autoreset /usr/bin
echo 'rename avrdude as avrdude-original'
mv /usr/bin/avrdude /usr/bin/avrdude-original
echo 'link avrdude-autoreset to avrdude'
ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude
  1. Addind the SleepyPi to the Arduino environment

The original documentation copies a boards.txt to

/home/pi/sketchbook/hardware/Sleepy_pi.

But but as I dont have a user in the docker container I don’t know where to copy these files to.

  1. Adding Libraries

The original documentations adds some needed Libraries to

/home/pi/sketchbook/libraries

The only suitable folder for this I found in my Docker Image was:

/usr/share/arduino/libraries

Is it possible to put the libraries I want to use here?

  1. Using I2C to change a jumpers state

The RPi3 has to override the SleepyPi2’s functionality to controll the RPi3’s Power when it uploads new software. This can be done via Software using I2C (link):

The Power Bypass can alternatively be enabled in software via an 12c GPIO chip

After installing i2c tools, the Jumper Powerbypass can be switched by the commands

switch the Software Jumper ON type:
i2cset -y 1 0x24 0xFD

to switch the Software Jumper OFF (power on default) type:
i2cset -y 1 0x24 0xFF

Do I only need to run

CMD modprobe i2c-dev && python ...

to make this work?

  1. Using I2C to access the RTC

The original documentation tells me to add

dtoverlay=i2c-rtc,pcf8523

to /boot/config.txt.
The resin equivalent should be a Fleet Configuration like:

[RESIN_HOST_CONFIG_dtoverlay] = i2c-rtc,pcf8523

?

In addition to that I have to out-comment some lines in

/udev/hwclock-set

can I also do this just inside the container or do i have to do it on the host-os?
And If i have to do it on the host os, is there a way to automate it, if I want to do this on ~100 devices?

  1. Handshake for Shutdown

The following GPIOs are used for the handshake (link):

GPIO 24: – Command the RPi to shutdown
GPIO 25: – RPi is running

the original documentation tells me to call the following script from /etc/rc.local:

import RPi.GPIO as GPIO
import os, time

GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.OUT)
GPIO.output(25, GPIO.HIGH)
print ("[Info] Telling Sleepy Pi we are running pin 25")

while True:
   if (GPIO.input(24)):
      print ("Sleepy Pi requesting shutdown on pin 24")
      os.system("sudo shutdown -h now")
      break
   time.sleep(0.5)

Will this work on resin as well or do i have to change something?

  1. Upload Code to Arduino

As I can’t use the Arduino IDE I was thinking of doing the upload of new code with
http://ed.am/dev/make/arduino-mk
If i understoof this correctly, I can specify my board, used libraries and my actual script with this, is that right?

2 Likes

I am also interested in this topic. :+1: