preparing raspberry pi - atlas scientificraspberry pi sample code atlas-scientific.com cot tl et c...

18
Raspberry Pi Sample Code & Wiring Diagram Circuit center sheild BNC / SMA NC VCC GND SDA SCL Pin 4 Pin 6 Pin 3 Pin 5 4.7K pull-up resistors 4.7K pull-up resistors

Upload: others

Post on 04-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 1

Revised 12/20Raspberry Pi

Sample Code & Wiring Diagram

Circuit

center

sheild

BNC / SMA

NC

VCCGNDSDASCL

Pin 4Pin 6Pin 3Pin 5

4.7K pull-upresistors

4.7K pull-upresistors

Page 2: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 2

Revised 12/20

Preparing Raspberry PiInstall the latest Raspberry Pi OS

Click HERE and follow the instructions to get the Raspberry Pi OS running.

Run the following command line within the Raspberry Pi’s terminal.

You should see a blue screen with options in a gray box in the center, like so

Choose “Expand Filesystem”

Expand file system

sudo raspi-config

Choosing this option will expand your installation to fill the rest of the SD card, giving you more space to use for files. You will need to reboot the Raspberry Pi to make this available.

Page 3: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 3

Revised 12/20

First, you will need to update your system’s package list by entering the following command in terminal.

Next, upgrade your installed packages to their latest versions with the command.

Update and Upgrade Packages

sudo apt-get update

sudo apt-get upgrade

Running the upgrade may take up to 30 minuets depending on which version of the Raspberry Pi you have.

Download the sample codeTo download the Atlas Scientific™ sample code,run the following commands within the Raspberry Pi’s terminal.

Once the sample code has finished downloading, you will be almost ready to begin using the Atlas Scientific™ EZO™ class circuits with your updated Raspberry Pi.

There are three different ways to interact with the Atlas Scientific™ EZO™ class circuits with your Raspberry Pi.

- USB Mode- I2C Mode- UART Mode

cd ~

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

Page 4: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 4

Revised 12/20

Sample code compatibility chart

Pi ZeroPi 2 Pi 3 Pi 4

I2C

UART

USB (FTDI)

The Raspberry Pi Foundation has failed to make a working UART on the Pi 3. Because of this no UART connected devices can run on a Raspberry Pi 3.

Page 5: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 5

Revised 12/20

USB Mode

Page 6: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 6

Revised 12/20

sudo apt-get install libftdi-dev

sudo pip install pylibftdi

sudo pip3 install pylibftdi

sudo nano /etc/udev/rules.d/99-libftdi.rules

SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0403”, ATTRS{idProduct}==”6015”,GROUP=”dialout”, MODE=”0660”, SYMLINK+=”FTDISerial_Converter_$attr{serial}”

USB ModeUSB mode will let you communicate through the Raspberry Pi’s USB port to any FTDI based USB device. This includes all USB based Atlas Scientific™ devices.

First, we need to install the libftdi package.

Next, we need to install the pylibftdi python package.

Python 2

Python 3

We need to create a udev rule file by entering the following command in terminal.

Replace the current rule with following revised rule below.

Press “CTRL+X”, then “Y” and hit Enter to save & exit.

Page 7: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 7

Revised 12/20

Once the updated udev rule has been saved, a restart is required in order to apply changes to the rule.

sudo service udev restart

sudo nano /usr/local/lib/python2.7/dist-packages/pylibftdi/driver.py

USB_PID_LIST = [0x6001, 0x6010, 0x6011, 0x6014]

USB_PID_LIST = [0x6001, 0x6010, 0x6011, 0x6014, 0x6015]

Lastly, we need to modify the FTDI python driver.

Move down to the line 70 and add 0x6015 at the end of line.

Original line

Modified line

Since Atlas Scientific™ FTDI devices use USB PID (0x6015), we need to tweak the original FTDI driver, by entering the following command in terminal.

Press “CTRL+X”, then “Y” and hit Enter to save & exit.

line 70

Page 8: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 8

Revised 12/20

sudo python -m pylibftdi.examples.list_devices

cd ~/Raspberry-Pi-sample-code

sudo python ftdi.py

Your Atlas Scientific™ EZO™ class circuits are almost ready to work with your Raspberry Pi, we just have to run a simple test first.

Connect your FTDI based USB device and run the following command in the terminal.

The program will report information about each connected device.You will get result like this:

Each FTDI adaptor has its own unique serial number.

In the result above, serial number is DA00TN6Q

The program will present a list of available FTDI devies. Enter the index of the device you wish to use, and you will now be able to control an Atlas Scientific™ EZO™ class circuit via the USB port.

For more details on the commands and responses, please refer to the datasheets of each Atlas Scientific™ EZO™ class circuit in use.

Run the following commands in terminal.

FTDI:FT230X Basic UART:DA00TN6Q

Using pylibftdi module for Atlas Scientific™ EZO™ class circuits

Page 9: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 9

Revised 12/20

I2C Mode

Page 10: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 10

Revised 12/20

I2C Mode

Before we can start using the EZO™ class circuits with your Raspberry Pi, we have to install and enable I2C bus on the Raspberry Pi.

Make sure the Atlas Scientific™ EZO™ class circuits are in I2C mode before moving further with the following instructions.

Once those have finished installing, we need to head back to the Raspberry Pi config.

sudo raspi-config

You should see a blue screen with options in a grey box in the center, like so

Choose “Advanced Options”

sudo apt-get install python-smbus

sudo apt-get install i2c-tools

Run the following commands in terminal.

Page 11: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 11

Revised 12/20

Choose “I2C”

Choose “YES”

Page 12: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 12

Revised 12/20

Hit “OK” and reboot the Raspberry Pi.

sudo reboot

Page 13: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 13

Revised 12/20

99:

List

The program will report information about each connected I2C device.This shows that an I2C address (0x63) is in use.

cd ~/Raspberry-Pi-sample-code

sudo python i2c.py

Each Atlas Scientific™ device has a different default I2C address. To see a list of connected I2C devices from the program, use the command.

For more details on the commands, responses and I2C addresses, please refer to the datasheets of each Atlas Scientific™ EZO™ class circuit in use.

Run the following commands in terminal.

This will now tell the Raspberry Pi to communicate with the EZO™ pH circuit 99 (0x63)

The last step is to tell the Raspberry Pi which circuit you want to talk to. By default the program will talk to the circuit pointed to by the arrow in the list shown by the list command. To talk to other circuits type their I2C address followed by a colon. For example to talk to the pH circuit, type 99: you can also add commands like “I”, “status” or “R”.

sudo i2cdetect -y 1

Your Atlas Scientific™ EZO™ class circuits are almost ready to work with your Raspberry Pi, we just have to run a simple test first.

Connect your EZO™ class circuit, and run the following command in terminal.

pHORPDOECRTDPMP

Device Decimal Hex

999897100102103

0x630x620x610x640x660x67

I2C address list

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved

Page 14: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 14

Revised 12/20

UART Mode

Page 15: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 15

Revised 12/20

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved

UART Mode

Before we can start using the Atlas Scientific™ EZO™ class circuits with your Raspberry Pi, we have to make a small tweak to the boot command line.

The Raspberry Pi Foundation has failed to make a working UART on the Pi 3. Because of this no UART connected devices can run on a Raspberry Pi 3 GPIO pins.

Run the following command line.

You should see something that looks a lot like this:

The command line should now look like this:

To correct this issue, delete the command:console=serial0,115200

sudo nano /boot/cmdline.txt

You might see two seperate commands listed for the “console”.console=tty1 console=serial0,115200

This can cause a conflict in the serial port.

1 2

1 2

Press “CTRL+X”, then “Y” and hit Enter to save & exit.

Page 16: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 16

Revised 12/20

Alternate UARTs on Pi 4

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.

sudo nano /boot/config.txt

usbport = ‘/dev/ttyAMA1’

enable_uart=1dtoverlay=uart5

sudo pip install pyserial

We need to ensure PySerial is installed for Python

The raspberry pi 4 has 6 UARTs.

cd ~/Raspberry-Pi-sample-code

sudo python uart.py

Run the following commands in terminal.

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

Go into the boot configuration

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

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

and add the lines

Page 17: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 17

Revised 12/20

Does your Raspberry Pi have an annoying black border around the OS?

If so, here is how to remove it.

*Side note*

Run the following command line within the Raspberry Pi’s terminal.

sudo raspi-config

Choose the option “Advanced Options”

Page 18: Preparing Raspberry Pi - Atlas ScientificRaspberry Pi sample code Atlas-Scientific.com Cot tl et C ll t eeed 9 Revised 620 I2C Mode Before we can start using the EZO™ class circuits

Raspberry Pi sample code

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved 18

Revised 12/20

Then, choose the option “A1 Overscan”

It will ask if you would like to enable compensation for displays with overscan?say “NO”

The black border will know be gone. Enjoy!