AtlasScientific / Raspberry-Pi-sample-code

MIT License
45 stars 52 forks source link

Preparing the Raspberry Pi

Install the latest Raspberry Pi OS

Follow the instructions on this page to get Raspberry Pi OS running https://www.raspberrypi.org/downloads/raspberry-pi-os/

Expand file system

Expand file system by following this: https://www.raspberrypi.org/documentation/configuration/raspi-config.md

Update and Upgrade Packages

sudo apt-get update
sudo apt-get upgrade

Download sample code.

cd ~
git clone https://github.com/AtlasScientific/Raspberry-Pi-sample-code.git

FTDI MODE

Installing dependencies for FTDI adaptors

Using pylibftdi module for Atlas Sensors.

Please remember the serial number of your device and run the sample code.

cd ~/Raspberry-Pi-sample-code
sudo python ftdi.py

Input the serial number and you can see the sensor's information and also sensor's LED status as well.

For more details on the commands & responses, please refer the Datasheets of Atlas Sensors.

I2C MODE

Enable I2C bus on the Raspberry Pi

Enable I2C bus on the Raspberry Pi by following this:

https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

You can confirm that the setup worked and sensors are present with the sudo i2cdetect -y 1 command.

Test Sensor

Run the sample code below:

cd ~/Raspberry-Pi-sample-code
sudo python i2c.py

When the code starts up a list of commands will be shown.

For more details on the commands & responses, please refer to the Datasheets of the Atlas Scientific Sensors.

UART MODE

Preventing Raspberry Pi from using the serial port

The Broadcom UART appears as /dev/ttyS0 under Linux on every Pi. The Pi 4 has additional UARTS, see below for instruction on how to use them

There are several minor things in the way if you want to have dedicated control of the primary serial port on a Raspberry Pi.

To double-check, use

cat /proc/cmdline

to show the current kernel command line, and

ps aux | grep ttyS0

to search for getty processes using the serial port.

Ensure PySerial is installed for Python.

sudo pip install pyserial

Run the below Python script:

cd ~/Raspberry-Pi-sample-code
sudo python uart.py

Alternate UARTS on Pi4:

The raspberry pi 4 has 6 uarts

To demonstrate alternate UART usage, we're going to enable UART 5 Note that other UARTs share their pins with other peripherals, so those peripherals may have to be disabled to use them

UART 5 uses pins 32 (TX) and 33 (RX) on the raspberry pi 40 pin header

Go into the boot configuration

sudo nano /boot/config.txt 

and add the lines

enable_uart=1
dtoverlay=uart5

then restart the raspberry pi

To use this port in the uart sample code uart.py change line 70 to:

usbport = '/dev/ttyAMA1'

Note that it may be a different ttyAMA depending on your setup