Introduction
According to Wikipedia, a logic analyzer is an electronic instrument that captures and displays multiple signals from a digital system or digital circuit.
In this post, we will learn how to connect a logic analyzer to a MAX485 module and the Raspberry Pi based PLC, and we will learn how to see incoming and outgoing data using Python programmed code.
Latest Posts
Requirements
How to connect MAX485 & Logic Analyzer
First of all, we are going to set the connections.
Connect the hardware, as you can see in the table and picture below:
RASPBERRY PLC | SALEAE LOGIC ANALYZER | MAX485 | PC |
GND | GND | GND, RE, DE | |
5V | VCC | ||
A+ | A | ||
B+ | B | ||
CH1 | RO | ||
USB | USB |
Send data through RS485
1. Access to your Raspberry Pi PLC controller.
2. Create a file called test-rs485.py
touch test-rs485.py
3. Give permissions to the file:
chmod 755 test-rs485.py
4. Edit your file and add this code:
from time import sleep
from serial import Serial
with Serial('/dev/ttySC0', 115200) as s:
while True:
tx = "hello"
sleep(0.5)
s.write(tx.encode())
s.flush
python test-rs485.py
Install Saleae Logic Analyzer Software
Once the hardware is correctly connected and you are sending data from the open source PLC Raspberry Pi RS485 port, you can go to Saleae's website and download the package that fits you better. In our case, we are going to download the Linux 64 bit .zip.
Click on it and download it. Once downloaded, extract files and double-click on the Logic file to launch the software.
Launch the Logic Analyzer Software
Once you launch the software, you should see a window like this:
You can see the 8 channels on the left, and another panel on the right.
1. On the right, click on the symbol next to Analyzers > Async Serial.
2. Set the same baud rate as in the Raspberry code. In our case: 115200. Leave the rest by default. Click on Save.
3. Click on Start.
4. Scroll in and out to get closer to the lines with the bytes, and adjust it so that you can see the data clearly.
Data Representation
The points from the frame received represent the bits from the data in little-endian, so the least significant bit (also LSB) will be the first one to be read.
In this case, we can see that we get the following, from binary to ASCII:
- 01101000: h
- 01100101: e
- 01101100: l
- 01101100: l
- 01101111: o
- (framing error)
Anyway, in the decoded protocols from the panel on the right, you can see the data you get
Now, it is your turn! Would you like to know how to send data through Serial Port?
How to open Logic Analyzer and run RS485 with industrial Raspberry PLC