Howto setup Raspbian for serial read: Difference between revisions

From lechacal
Jump to navigation Jump to search
No edit summary
 
(76 intermediate revisions by the same user not shown)
Line 1: Line 1:


[https://lechacal.com/docs/RPICT/Howto_setup_Raspbian_for_serial_read/ VIEW THE NEW DOCUMENTATION INSTEAD HERE]


This howto will cover the steps to setup a Rasperrypi for reading CSV stream from RPICT series board.
This howto will cover the steps to setup a Rasperrypi for reading CSV stream from RPICT series board.
Line 6: Line 7:
This applies to all Raspberrypi. If using the image from Emoncms (emonpi) then this setup is not needed.
This applies to all Raspberrypi. If using the image from Emoncms (emonpi) then this setup is not needed.


Tested with OS: <br>
Latest tested OS for this guide: <br>
Raspbian Jessie '''2017-06-21-raspbian-jessie.img'''<br>
Raspberrypi OS Released: 2023-12-05<br>
Raspbian Stretch '''2017-09-07-raspbian-stretch-lite.img'''<br>
Both for Lite and Desktop variants.
Raspbian Stretch '''2018-06-27-raspbian-stretch-lite.img'''<br>
Raspbian Stretch '''2018-10-09-raspbian-stretch-lite.img'''<br>
Raspbian Stretch '''2018-11-13-raspbian-stretch-lite.img'''<br>
Raspbian Buster  '''2019-06-20-raspbian-buster-lite.img''' <br>
Raspbian Buster  '''2020-02-13-raspbian-buster-lite.img''' <br>
 
Rasberry Pi OS  '''2020-05-27-raspios-buster-armhf.img''' <br>
Rasberry Pi OS  '''2020-08-20-raspios-buster-armhf.img''' <br>
 
 
IMPORTANT NOTICE : WE DO NOT HAVE THE SETUP YET FOR THE 2020-12-02 IMAGE. GET THE [https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-08-24/2020-08-20-raspios-buster-armhf-lite.zip.torrent 2020-08-20] IMAGE INSTEAD FROM THE LINK BELOW.
 
https://downloads.raspberrypi.org/raspios_lite_armhf/images/


=Steps=
=Steps=
Line 27: Line 15:
==-1-==
==-1-==


Download the image from the raspberrypi website.
The Raspberry pi OS must be installed and running.
https://www.raspberrypi.org/downloads/raspberry-pi-os/


==-2-==
To get a Raspberry Pi Os image you can either


Write the image to the SD card. Follow instructions given by the raspberrypi website.
Download the image from the raspberrypi website.


https://www.raspberrypi.org/documentation/installation/installing-images/
https://www.raspberrypi.org/software/operating-systems/


==-3-==
or


Once the image written create an empty file called '''ssh''' in the boot section of the image.
Make an image yourself using the Imager.


==-4-==
https://www.raspberrypi.com/software/


Power up the raspberrypi and connect it to the ethernet network. <br>
If you are running headless with the 'Raspberry Pi OS Lite' you will have to connect a keyboard and monitor for the very first time the raspberry is run. This is to allow access to the first time boot wizard. Also creating an empty 'ssh' file inside the /boot directory will be useful for connecting via ssh. Alternatively you can just use the imager software from above to setup username and ssh before flashing.
Access the raspberrypi with ssh.<br>


===Linux based OS===
==-2-==
This is as simple as issuing.<br>
$ ssh pi@raspberrypi


<small>Use password raspberry</small>
For what follow you must open a terminal window.


===On other systems (windows, ios)===
On the desktop version of Raspberry Pi OS just open a terminal.
We recommend to use the putty tool. [https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html Download here]<br>
As above use<br>
hostname: raspberrypi<br>
user: pi<br>
password: raspberry<br>


This will give you access to a terminal window in which you can issue commands on the raspberrypi.
On the headless version connect to the raspberry via ssh with the user/password you created.


==-5-==
==-3-==


Run the raspi-config tool
Run the raspi-config tool
Line 66: Line 45:


Then disable the login uart
Then disable the login uart
  5 Interfacing Options    <<-- Use option ''3 Interface Options'' instead if using the image from 12 DEC 2020
  3 Interface Options    
P6 Serial
 
I6 Serial Port     <<-- might also be found as ''I5 Serial Port''


'''Would you like a login shell to be accessible over serial?'''<br>
'''Would you like a login shell to be accessible over serial?'''<br>
Select '''No''' to the login shell question.<br>
Select '''No''' to the login shell question.<br>
[[File: 001_login_shell_question.png]]


'''Would you like the serial port hardware to be enabled?'''<br>
'''Would you like the serial port hardware to be enabled?'''<br>
Select '''Yes''' to the serial port hardware to be enabled question.<br>
Select '''Yes''' to the serial port hardware to be enabled question.<br>
[[File: 002_serial_enable.png]]


Select '''Ok''' at the summary.
Select '''Ok''' at the summary.
[[File: 003_serial_setup.png]]


Back at the menu select '''finish'''.
Back at the menu select '''finish'''.
Line 82: Line 68:
Select '''No''' to the reboot question (we will do that later).<br>
Select '''No''' to the reboot question (we will do that later).<br>


==-6-==
==-4-==
[OPTIONAL]<br>
Update the Raspbian OS.
sudo apt-get update
 
==-7-==
 
This step must be performed regardless if you have a Raspberrypi 3 or 4.


Edit the /boot/config.txt file
Edit the /boot/config.txt file
Line 95: Line 74:


At the end of the file add the following line:
At the end of the file add the following line:
  dtoverlay=pi3-disable-bt
  dtoverlay=disable-bt
 
Enter the line exactly as it is show above without adding whitespaces.
 
Save and Exit file.
 
<small>(note the above will disable bluetooth - if bluetooth is needed do not execute this step and use ttyS0 instead of ttyAMA0 for what follows).<br>
<small>(note the above will disable bluetooth - if bluetooth is needed do not execute this step and use ttyS0 instead of ttyAMA0 for what follows).<br>
A one liner of the above command would be<br>
[alternative] A one liner to include the above line in the config file would be<br>
sudo bash -c 'echo "dtoverlay=pi3-disable-bt" >> /boot/config.txt'
sudo bash -c 'echo "dtoverlay=disable-bt" >> /boot/config.txt'
</small>
</small>


Save and Exit file.
For Raspberrypi 5 only also add the line below
dtoverlay=uart0


==-8-==
==-5-==
[OPTIONAL]<br>
[OPTIONAL]<br>
Disable hciuart
Disable hciuart
  sudo systemctl disable hciuart
  sudo systemctl disable hciuart


==-9-==
==-6-==
Reboot
Reboot
  sudo reboot & exit
  sudo reboot & exit
return to the ssh session again once the raspberrypi up and running again.
return to the ssh session again once the raspberrypi is up and running again.
 
==-7-==
 
It might be useful to get the board with all utilities ready at this point. Just issue the commands below to install them:
 
Install python3-serial
sudo apt-get install python3-serial
 
Get the rpict package:
wget lechacal.com/RPICT/tools/lcl-rpict-package_latest.deb
 
Install it with
sudo dpkg -i lcl-rpict-package_latest.deb
 
 
==-8-==
 
Last step is testing the serial port.
 
/!\ DO NOT SKIP THIS TEST /!\<br>
This is the most basic test to confirm you are able to read from the serial port. If it fails do not continue your setup. Instead carefully review the configuration setup described above.<br>
If you encounter issues with your own application or some custom configuration then do run this test again to make sure the serial port is still operational.


==-10-==
Insert the RPICT board on the RPI. Configure and read from serial port
Insert the RPICT board on the RPI. Configure and read from serial port
  stty -F /dev/ttyAMA0 raw speed 38400
  stty -echo -F /dev/ttyAMA0 raw speed 38400
  cat /dev/ttyAMA0
  cat /dev/ttyAMA0


==-11-==
Note these two command above can be run directly using
[OPTIONAL]
 
It might be useful to get the board with all utilities ready at this point. Just issue the commands below:
lcl-run
sudo apt-get install python-serial
 
wget lechacal.com/RPICT/tools/lcl-rpict-config.py.zip
At that point the data will be shown on the terminal. This is an example with the RPICT3T1 below.<br>
unzip lcl-rpict-config.py.zip
[[File:Screenshot_2021-03-12_21-27-04.png]]
sudo mv lcl-rpict-config.py /usr/local/bin
 
Please refer to the dedicated page of the board for the details of each field.

Latest revision as of 11:28, 19 January 2024

VIEW THE NEW DOCUMENTATION INSTEAD HERE

This howto will cover the steps to setup a Rasperrypi for reading CSV stream from RPICT series board.

Hardware and OS

This applies to all Raspberrypi. If using the image from Emoncms (emonpi) then this setup is not needed.

Latest tested OS for this guide:
Raspberrypi OS Released: 2023-12-05
Both for Lite and Desktop variants.

Steps

-1-

The Raspberry pi OS must be installed and running.

To get a Raspberry Pi Os image you can either

Download the image from the raspberrypi website.

https://www.raspberrypi.org/software/operating-systems/

or

Make an image yourself using the Imager.

https://www.raspberrypi.com/software/

If you are running headless with the 'Raspberry Pi OS Lite' you will have to connect a keyboard and monitor for the very first time the raspberry is run. This is to allow access to the first time boot wizard. Also creating an empty 'ssh' file inside the /boot directory will be useful for connecting via ssh. Alternatively you can just use the imager software from above to setup username and ssh before flashing.

-2-

For what follow you must open a terminal window.

On the desktop version of Raspberry Pi OS just open a terminal.

On the headless version connect to the raspberry via ssh with the user/password you created.

-3-

Run the raspi-config tool

$ sudo raspi-config

Then disable the login uart

3 Interface Options     
I6 Serial Port     <<-- might also be found as I5 Serial Port

Would you like a login shell to be accessible over serial?
Select No to the login shell question.

Would you like the serial port hardware to be enabled?
Select Yes to the serial port hardware to be enabled question.

Select Ok at the summary.

Back at the menu select finish.

Would you like to reboot now?
Select No to the reboot question (we will do that later).

-4-

Edit the /boot/config.txt file

$ sudo nano /boot/config.txt

At the end of the file add the following line:

dtoverlay=disable-bt

Enter the line exactly as it is show above without adding whitespaces.

Save and Exit file.

(note the above will disable bluetooth - if bluetooth is needed do not execute this step and use ttyS0 instead of ttyAMA0 for what follows).
[alternative] A one liner to include the above line in the config file would be
sudo bash -c 'echo "dtoverlay=disable-bt" >> /boot/config.txt'

For Raspberrypi 5 only also add the line below

dtoverlay=uart0

-5-

[OPTIONAL]
Disable hciuart

sudo systemctl disable hciuart

-6-

Reboot

sudo reboot & exit

return to the ssh session again once the raspberrypi is up and running again.

-7-

It might be useful to get the board with all utilities ready at this point. Just issue the commands below to install them:

Install python3-serial

sudo apt-get install python3-serial

Get the rpict package:

wget lechacal.com/RPICT/tools/lcl-rpict-package_latest.deb

Install it with

sudo dpkg -i lcl-rpict-package_latest.deb


-8-

Last step is testing the serial port.

/!\ DO NOT SKIP THIS TEST /!\
This is the most basic test to confirm you are able to read from the serial port. If it fails do not continue your setup. Instead carefully review the configuration setup described above.
If you encounter issues with your own application or some custom configuration then do run this test again to make sure the serial port is still operational.

Insert the RPICT board on the RPI. Configure and read from serial port

stty -echo -F /dev/ttyAMA0 raw speed 38400
cat /dev/ttyAMA0

Note these two command above can be run directly using

lcl-run

At that point the data will be shown on the terminal. This is an example with the RPICT3T1 below.

Please refer to the dedicated page of the board for the details of each field.