Call us Now - 0034 938 760 191

SARA-R412M on Raspberry Pi

July 8, 2024 by
Boot & Work Corp. S.L., Arnau Tena

Before we test anything with the SARA module, we must first install Industrial Shield's librpiplc library by following the instructions in this link. We recommend you clone the repository inside of your home directory, as it is where we've cloned it for this blog. When cloning the repository, replace <tagname> with v3.0.0 to select the correct librpiplc version.

LIBRPIPLC Library

After succesfully installing librpiplc, we have to copy one of the compiled files into a different folder. If you installed a librpiplc version older than v3.0.0 you can skip this part. To copy the file, use the following commands:

(Replace [PLC_Version] and [PLC_Model] with your RPIPLC's version and model, like you did when installing librpiplc)

RPIPLC Models and Versions

cd ~/test/[PLC_Version]/[PLC_Model]/
cp set-digital-output ~/test/analog/set-digital-output

Now we must make sure that the config.txt file is set up correctly. To do this, first open /boot/config.txt with your preferred text editor, in this case we use nano:

sudo nano /boot/config.txt

Use your arrow keys to reach the bottom of the file, and make sure you have these lines set up like this:

[all]
dtparam=spi=on
gpio=8=pd
dtoverlay=spi0-1cs,cs0_pin=7
dtoverlay=w5500,cs=0,int_pin=6
dtparam=i2c_arm=on
dtoverlay=i2c-rtc,ds3231
dtoverlay=sc16is752-spi1-rpiplc-v4,xtal=14745600
enable_uart=1

You can now close the text editor. If you opened the file using nano, you can close it by pressing Ctrl+X. If nano asks you for confirmation before closing, type Y to confirm and then press Enter to keep the same filename.

Now we can work with the SARA-R412M module. Depending on where the module is installed, the following steps will be a bit different. The module can either be installed in slot 1 or slot 2, with slot 1 being the closest to the ethernet port.

If the module is installed in the slot 1, execute file setup-gprs.sh which can be found here, using these commands:

wget https://apps.industrialshields.com/main/rpi/rpiplc_v4/setup-gprs.sh
chmod 755 setup-gprs.sh
sudo ./setup-gprs.sh
Steps for slot 2

If the module is installed in the slot 2, you will have to do some extra steps. First download the setup file with:

wget https://apps.industrialshields.com/main/rpi/rpiplc_v4/setup-gprs.sh

Now open the setup-gprs.sh and replace all occurences of ttySC0 to ttySC1 and EXP1_RST to EXP1_RST_2. You can use nano:

nano setup-gprs.sh

To replace all occurences do this:

​1.Press the Alt + R key combination to enter the find and replace mode.

​2. Write ttySC0 and press enter.

​3. Write ttySC1 and press enter. 

​4. Press A to replace all occurences.

Repeat steps 1 to 4 to replace EXP1_RST with EXP2_RST, or replace it with EXP1_RST_2 if you are using a librpiplc version older than v3.0.0.

Now we can give proper permissions to the file and execute it:

chmod 755 setup-gprs.sh
sudo ./setup-gprs.sh

If you followed the steps for your corresponding slot, the executed script will now be asking for APN credentials and AT (Radio Access Technology): LTE Cat M1(4G), NB-IoT (Narrow Band) or GPRS/eGPRS. It will also create a service called pppd located in /lib/systemd/system/pppd.service, which executes a python file created in /usr/src/network-setup.py every time the Raspberry PLC boots. 

About 50-120 seconds after executing setup-gprs.sh, interface ppp0 should be created. The process can be followed with:

tail -f /var/log/messages

or

tail -f /var/log/syslog

You can check that the interface has been created with:

ifconfig ppp0

To ensure everything has gone flawless, you can ping to 8.8.8.8 like so:

ping 8.8.8.8 -c4 -I ppp0

To stop and disable the service, use the commands:

sudo systemctl stop pppd.service
sudo systemctl disable pppd.service

Finally, try to execute the created script newtork-setup.py with the desired RAT:

(replace [RAT] with either gprs, nb-iot or lte-m)

    python /usr/src/network-setup.py [RAT]

​Search in our Blog

Boot & Work Corp. S.L., Arnau Tena July 8, 2024
Share this post
Tags

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>