Setting up MotoReco Logger

Preparing for Raspbian Buster Lite

Download Raspbian Buster Lite image from official site.

Write image file to your SD card.

Edit config.txt under boot partition of your SD card.

Add following line at the end of config.txt,

dtoverlay=dwc2

Also edit commandline.txt. Insert modules-load=dwc2,g_etherĀ after rootwait so whole command is like,

console=serial0,115200 console=tty1 root=PARTUUID=738a4d67-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet init=/usr/lib/raspi-config/init_resize.sh

Finally, put empty file named “ssh” .

Boot and initial settings

Connect your computer and raspberry pi zero with USB cable.

Raspberry Pi Zero have two micro USB port and use micro USB port pointed by green arrow in picture above.

When raspberry pi is recognized as serial port, you need to install USB ether driver. You can download RPI Driver OTG from following webpage,

Pi Zero OTG Ethernet

When your computer recognize Raspberry Pi Zero as an ethernet device, you can see on device manager as an USB Ethernet/RNDIS Gadget.

Since windows 10 rev 1909, mDNS is implemented so Bonjour is no longer not need to install.

Now open your SSH client and connect to raspberrypi.local.

User name is pi and passphrase is raspberry.

Set up raspi-config

pi@raspberrypi:~ $ sudo raspi-config
  • Change User Password -> change password for pi. motoreco is default password for MotoReco Logger.
  • Network Options -> Hostname -> change host name. MotoReco is default host name for MotoReco Logger.
  • Localisation Options
    • Change Timezone -> change timezone where you use.Tokyo is default timezone for MotoReco Logger.
    • Change Wi-fi Country -> changeĀ  to country name where you use. Japan is default Wi-fi country for MotoReco Logger.
  • Interfacing option->
    • Camera:Disable
    • SSH:Enable
    • VNC:Disable
    • SPI:Enable
    • I2C:Disable
    • Serial:Serial Login:NO, Serial Port:Yes
    • 1-Wire:Disable
    • Remote GPIO:Disable
  • Advanced Option->
    • Expand Filesystem
    • Memory Split -> 16

after finish, reboot Raspberry Pi Zero.

Change apt repository server

pi@MotoReco:~ $ sudo nano /etc/apt/sources.list

change

deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

to

#deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://ftp.jaist.ac.jp/raspbian buster main contrib non-free rpi

This is sample for Japanese so use nearest server in your country.

Update Raspbian

Now it’s time to update raspbian, but before to do that, you need to configure your computer to able to share internet connection for your raspberry pi.

Open network adaptor configuration dialogue.

In my computer, network adaptor pointed by green arrow is connected to internet and orange one is connection to Raspberry Pi Zero.

So to let share internet connection to Orange adapter, right click and open property of Green adaptor.

  1. Select tab for share setting.
  2. Check option.
  3. Select network interface name of Raspberry Pi.

After configuring your computer, renew IP of Raspberry Pi.

pi@MotoReco:~ $ dhclient -r usb0

Now you can check internet connection,

pi@MotoReco:~ $ ping www.yahoo.co.jp

If you have connection to internet, ping respond will come.

Now time to update Raspbian,

pi@MotoReco:~ $ sudo apt-get update
pi@MotoReco:~ $ sudo apt-get upgrade

Configure as Access Point

Install hostapd and dnsmasq.

pi@MotoReco:~ $ sudo apt-get install hostapd dnsmasq -y

Edit dhcpcd.conf

pi@MotoReco:~ $ sudo nano /etc/dhcpcd.conf

Add these two lines at the end of the file.

interface wlan0
static ip_address=192.168.100.1/24

Create hostapd.conf,

pi@MotoReco:~ $ sudo nano /etc/hostapd/hostapd.conf

Just copy these,

interface=wlan0
driver=nl80211
ssid=MotoReco
hw_mode=g
channel=11
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=MotoReco
rsn_pairwise=CCMP

Edit hostapd.conf,

pi@MotoReco:~ $ sudo nano /etc/default/hostapd

Insert following,

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Back up original dnsmasq.conf

pi@MotoReco:~ $ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

Create dnsmasq.conf,

pi@MotoReco:~ $ sudo nano /etc/dnsmasq.conf 

Copy following,

interface=wlan0
listen-address=192.168.100.1
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.100.50,192.168.100.100,12h

Enabling hostapd and dnsmasq service,

pi@MotoReco:~ $ sudo systemctl unmask hostapd
pi@MotoReco:~ $ sudo systemctl enable hostapd
pi@MotoReco:~ $ sudo systemctl enable dnsmasq

Edit rc.local

pi@MotoReco:~ $ sudo nano /etc/rc.local

Copy following,

#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

service dnsmasq stop
sleep 8
service dnsmasq start

exit 0

Reboot,

pi@MotoReco:~ $ sudo reboot

After rebooted, you can see ssid:MotoReco as WiFi access point.

Setting up Samba

Install samba,

pi@MotoReco:~ $ sudo apt-get install samba

During installation, you will be asked question and select No.

Open samba conf file with editor,

pi@MotoReco:~ $ sudo nano /etc/samba/smb.conf

Add these settings on global section,

[global]
    max protocol = SMB2
    security = user
    log level = 1

Also add these settings on the end of file,

[pi]
    comment = Raspberry Pi
    path = /home/pi
    guest ok = yes
    read only = no
    public = yes
    browsable = yes
    force user = pi

Restart samba,

pi@MotoReco:~ $ sudo service smbd restart

Now you can access Raspberry Pi Zero with Windows explorer. Access “\\192.168.100.1”. You will see your motorcycle logging data inside of this folder.

Install MotoReco Logger related packages

Install gpsd.

pi@MotoReco:~ $ sudo apt-get install gpsd gpsd-clients

Open gpsd conf file,

sudo nano /etc/default/gpsd

Configure conf file,

sudo nano /etc/default/gpsd
# Default settings for the gpsd init script and the hotplug wrapper.

# Start the gpsd daemon automatically at boot time
START_DAEMON="true"

# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="false"

# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyAMA0 /dev/pps0"

# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"

GPSD_SOCKET="/var/run/gpds.socket"

Install wireing pi,

pi@MotoReco:~ $ sudo apt-get install wiringpi

Install libgps,

pi@MotoReco:~ $ sudo apt-get install libgps-dev

Configure MotoReco Logger specific setting

Modifying /boot/config.txt

pi@MotoReco:~ $ sudo nano /boot/config.txt

Add CAN setting, enabling GPS PPS, disabling audio and enabling Watch Dog at the end of config.txt

# CAN0 setting
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835

dtoverlay=pi3-miniuart-bt
dtparam=watchdog=on
dtoverlay=pps-gpio,gpiopin=18,assert_falling_edge=true

Also, comment out

#dtparam=audio=on

Modifying /etc/network/interfaces

pi@MotoReco:~ $ sudo nano /etc/network/interfaces

Add these setting at the end of file,

#CAN interface setting
auto can0
iface can0 inet manual
pre-up /sbin/ip link set can0 type can bitrate 500000 triple-sampling on listen-only on
up /sbin/ifconfig can0 up
down /sbin/ifconfig can0 down

auto usb0

Setting up ntp

Install ntp,

pi@MotoReco:~ $ sudo apt-get install ntp

Edit /etc/ntp.conf

pi@MotoReco:~ $ sudo nano /etc/ntp.conf

Comment out these,

#statistics loopstats peerstats clockstats
#filegen loopstats file loopstats type day enable
#filegen peerstats file peerstats type day enable
#filegen clockstats file clockstats type day enable

#pool 0.debian.pool.ntp.org iburst
#pool 1.debian.pool.ntp.org iburst
#pool 2.debian.pool.ntp.org iburst
#pool 3.debian.pool.ntp.org iburst

Adding these just after the comment out

server ntp.nict.jp iburst
server 127.127.28.0 prefer minpoll 4 maxpoll 4
fudge  127.127.28.0 time1 0.32 refid GPS stratum 14
server 127.127.28.2
fudge  127.127.28.2 time1 -0.03 refid PPS stratum 3

Use your nearest ntp server instead of ntp.nict.jp

Create bash script that configure system date and time from GPS,

pi@MotoReco:~ $ sudo touch /usr/local/bin/setdatefromgps.sh
pi@MotoReco:~ $ sudo chmod 755 /usr/local/bin/setdatefromgps.sh
pi@MotoReco:~ $ sudo nano /usr/local/bin/setdatefromgps.sh

Copy these,

#!/bin/sh
echo start at `/bin/date`
for i in 1m 1m; do
  echo sleep $i
  /bin/sleep $i
  GPSDATE="`/usr/bin/gpspipe -w | /usr/bin/head -10 | /bin/grep TPV | /bin/sed -r 's/.*"time":"([^"]*)".*/\1/' | /usr/bin/head -1`"
  echo $GPSDATE
  /bin/date -s "$GPSDATE"
done
echo end at `/bin/date`

Execute this script when reboot,

pi@MotoReco:~ $ crontab -e

Add this at the end of the file,

@reboot sudo /usr/local/bin/setdatefromgps.sh

Setting Up MotoReco Logger Programs

Modify /etc/rc.local again,

pi@MotoReco:~ $ sudo nano /etc/rc.local

Copy these,

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

# turen off HDMI
/opt/vc/bin/tvservice -o

/usr/local/bin/start.sh

service dnsmasq stop
sleep 8
service dnsmasq start

exit 0

Create /usr/local/bin/start.sh

pi@MotoReco:~ $ sudo touch /usr/local/bin/start.sh
pi@MotoReco:~ $ sudo chmod 755 /usr/local/bin/start.sh
pi@MotoReco:~ $ sudo nano /usr/local/bin/start.sh

Copy these,

#!/bin/bash

#check update program is available
if [[ -f /home/pi/update/mrlogger ]]; then
        mv /home/pi/update/mrlogger /usr/local/bin/mrlogger
        chmod 755 /usr/local/bin/mrlogger
fi

if [[ -f /home/pi/update/mrserver ]]; then
        mv /home/pi/update/mrserver /usr/local/bin/mrserver
        chmod 755 /usr/local/bin/mrserver
fi

if [[ -f /home/pi/update/mrgpio ]]; then
        mv /home/pi/update/mrgpio /usr/local/bin/mrgpio
        chmod 755 /usr/local/bin/mrgpio
fi

#execute logger program
/usr/local/bin/mrgpio &
/usr/local/bin/mrlogger &
/usr/local/bin/mrserver &

exit 0

Next, download MotoReco Logger programs,

Extract zip file, and copy “update” folder into MotoReco Logger shared folder.

Next , just reboot logger.

pi@MotoReco:~ $ sudo reboot

When next reboot timing, /usr/local/bin/start.sh invoked by /etc/rc.local will automatically copy program files under /home/pi/update to /usr/local/bin and start mrgpio, mrlogger and mrserver.

Tweak Raspberry Pi Zero

Add timeout for dhcpcd service,

pi@MotoReco:~ $ sudo nano /etc/systemd/system/dhcpcd.service.d/wait.conf 

Modify like this,

[Service]
ExecStart=
ExecStart=/sbin/dhcpcd -q -w -t 5

Disable not using services,

pi@MotoReco:~ $ sudo systemctl disable dphys-swapfile
pi@MotoReco:~ $ sudo systemctl disable keyboard-setup
pi@MotoReco:~ $ sudo systemctl disable triggerhappy
pi@MotoReco:~ $ sudo systemctl disable bluetooth
pi@MotoReco:~ $ sudo systemctl disable hciuart
pi@MotoReco:~ $ sudo systemctl disable raspi-config
pi@MotoReco:~ $ sudo systemctl disable avahi-daemon

Removing not using packages,

pi@MotoReco:~ $ sudo apt-get purge -y --auto-remove dphys-swapfile
pi@MotoReco:~ $ sudo apt-get purge -y --auto-remove dbus

Modify /boot/cmdline.txt again,

pi@MotoReco:~ $ sudo nano /boot/cmdline.txt

Use this setting, but YOU MUST KEEP ORIGINAL PARTUUID,

dwc_otg.lpm_enable=0 root=PARTUUID=738a4d67-02 rootfstype=ext4 elevator=deadline rootwait quiet

Modify /boot/config.txt again,

pi@MotoReco:~ $ sudo nano /boot/config.txt

Modify overclock section from

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

to

#uncomment to overclock the arm. 700 MHz is the default.
arm_freq=1000
sdram_freq=500
force_turbo=1
dtoverlay=sdtweak,overclock_50=100

Now your MotoReco Logger is as same setting as MotoReco Logger Image. After this tweaking, you can not connect MotoReco Logger by USB cable, so connect WiFi access point.