Communicate with a Modbus RTU RS485 device using a Raspberry Pi

A Raspberry Pi is a tiny computer that can talk to other devices using something called Modbus protocol. This allows us to read information from these devices, like temperature values, which is very important in many industries. For example, if we want to know the temperature of a machine in a factory, we can use a Raspberry Pi to read this information and make sure the machine is working correctly. This is very helpful because it can save us time and money by detecting problems early and fixing them before they become bigger issues. Plus, a Raspberry Pi is small, cheap, and easy to use, which makes it a great tool for controlling and automating many different devices. All we need is a little bit of code, and we can read and control all kinds of machines and sensors.

To communicate with a Modbus RTU RS485 device using a Raspberry Pi, you will need to install the “pymodbus” package in your Raspberry Pi. To install the package, you can use the pip package manager with the following command:

sudo pip install pymodbus

You will also need to connect a USB to RS485 adapter to your Raspberry Pi and connect it to the Modbus RTU device. Once you have done that, you can use the following Python code to read temperature values from the device:

#!/usr/bin/env python
from pymodbus.client.sync import ModbusSerialClient
from pymodbus.register_read_message import ReadInputRegistersResponse

# Configuration
baudrate = 9600
parity = 'N'
bytesize = 8
stopbits = 1
timeout = 1
unit_id = 1
start_address = 0
num_registers = 1

# Create a Modbus client
client = ModbusSerialClient(method='rtu', port='/dev/ttyUSB0', baudrate=baudrate, parity=parity, bytesize=bytesize, stopbits=stopbits, timeout=timeout)

# Open the communication port
client.connect()

# Read temperature value from the device
response: ReadInputRegistersResponse = client.read_input_registers(start_address, num_registers, unit=unit_id)
if response.isError():
    print(f"Error: {response}")
else:
    temperature = response.registers[0] / 10.0 # assuming the temperature value is stored in a 16-bit register and multiplied by 10
    print(f"Temperature: {temperature}°C")

# Close the communication port
client.close()

This code assumes that the temperature value is stored in a 16-bit register and multiplied by 10. You may need to adjust the start_address and num_registers variables depending on the register where the temperature value is stored and the number of registers it occupies.

It's only fair to share...Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Share on linkedin
Linkedin
Alfa LEDs

Alfa Romeo RGB Grill LEDs with Bluetooth

Update (9-12-2022)

I am now selling this for $99 + $4.99 Shipping
-Comes 12V to 5V adapter and 3 feet of wire for wiring to Car’s 12V supply
-Comes with iOS and Android Apps. 
They will ship starting: 9-30-2022
Order from the PayPal buttons below and let me know if you have any questions.

Built to ship in 1 week
___________________________________________________

The Look

I wanted to make my new Alfa stand out from the couple others I’ve seen round rarely. As if the front end of the Giulia isn’t beautiful enough. It seemed like it was a necessary and obvious mod.

The Guts & Brains

I made this 49 LED strip out of SK6812 addressable RGB LED strips. Similar to the common WS2812b strips but brighter and with a true white. Check them out here on amazon: https://www.amazon.com/gp/product/B07FVRR4KL/. I also used an Arduino Nano clone that has its own USB to serial chip built-in. Another new key component is the HC-05 serial Bluetooth module. It’s an older V2.0+EDR version of Bluetooth but it has great range. The only downside is that iOS/Apple devices don’t support 3rd party Bluetooth unless it’s made for iPhone/iPad or its the newer Bluetooth 3.0/4.0+LE

The Interface

I wanted to create a menu system and be able to hit buttons to ascii characters to change the light show modes. So far I have the default/power on mode of pure white. Then by Bluetooth you can choose “Demo” to change to an animated demo reel that comes with the LED library FastLED on the Arduino. Then I have added a Knight Rider mode. Even a special Alfa Knight Rider mode that doubles up the “V” in the grill. And finally, I have a “Fire” mode that looks like flames.

There is a menu display when you first connect with a Bluetooth terminal app on Android. I use, “Bluetooth Terminal HC-05”. It lets you assign rows of buttons to macros of strings of text to send to the device. It also allows to to see the available options in the device and you can enter, “H” to see the menu at any time.

The Code

The code is still in progress, feel free to check it out on GitHub. I hope to be updating and completing code so I can add this to my car permanently.

The Bugs & Improvements

I hope to add a few more modes and brightness control very soon. Currently the only bug in the system is the Bluetooth communication is talking to the Arduino over software serial. There are a lot of timer interupts between the FastLED library to control the lights that sometimes (30% of the time) the Bluetooth message to change a mode is missed and a different ascii character comes through. This means you have to enter the command or hit the button a couple, few times. This is easily fixed by changing over to the hardware serial UART. I have not yet done this but feel free to make a pull request for an alternative sketch.

I also have plans to design and print a circuit board to easily house the Arduino, Bluetooth module, connectors for lights and power. I have already 3D printed a couple cases to protect the guts on the road.

It's only fair to share...Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Share on linkedin
Linkedin

Lip-Sync Singing Skeleton for Halloween with A.I.

I’ve been getting more and more into programming with A.I. to let a computer find solutions to problems I give it with reinforcement training or a neural network and a bunch of data. It’s not as simple as it sounds. I recently found a couple music projects that use A.I. to separate vocals, drums, bass, piano and other sounds from each other into their own audio tracks. One is called Spleeter and the other is Facebook Research’s Demucs. They both use Python and TensorFlow (a popular machine learning programming library).

I wrote an application with Node.js that will take advantage of Spleeter and use Youtube to download songs from a playlist and automatically separate them and save the music tracks. Then play the original and silently watches the RMS volume of the vocals and drums to determine when to open his mouth or turn his neck.

When Halloween comes I hope to tie these to lights out front with relays and add a couple more singers to the stage.
I’m working on changing the high voltage servo for the mouth to a stepper motor with a bike brake cable for remote jaw actuation.
Take a look below to see behind the scenes of how the skeleton is controlled.

It's only fair to share...Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Share on linkedin
Linkedin

The BarBot – Touchscreen Automated Drink Maker

I’ve been working with 3D printers for a while now. Watching them move and print can be mesmerizing. I wanted to make a fun gadget that would demonstrate my skills and create an interactive conversation piece for a party. Hence The BarBot. It’s not a new idea but, I knew I could do it better than most that I’ve seen online and take it a step or two further.

Custom Designed Printed Circuit Board

My BarBot features two stepper motors to create linear actuation in two directions; Move the drink from bottle to bottle and dispense the ingredients. I wanted to keep it as simple as possible. Along with the motors there are two end switches to home the motors so they know their positions. I designed and printed all the plastic parts. The horizontal linear actuator is a single steal rail with two rail guides. eBay Link to Steal Rails

Also my dispensers measure one shot every time. Making it do half shots and quarter shots is much tricker. Here’s a link to those racks where I used two for 12 bottles. https://www.amazon.com/gp/product/B07Q42XL9Q

I have an Arduino Uno controlling the motors and acting as the I/O controller. From there I have the Uno connected via USB Serial to the Raspberry Pi. Connected to the Raspberry Pi is a 7″ touchscreen and a 1080p Camera with an extended ribbon cable for camera placement.

The main brains (RasPi) boots up directly to my custom application that holds the drink database, system state (making drink, current ingredient, motors homed, etc), and real-time communication to the motors. I developed the applications using Javascript with Node.JS, C programming language, Socket.IO and JSON.

This project is intended to demonstrate my Software, Electrical, Mechanical and Automation skills. I hope you like it. I am still adding more features and fine tuning the system. Stay tuned for more. Check out my YouTube Channel for updates. https://www.youtube.com/c/ConsultingjoeOnline

It's only fair to share...Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Share on linkedin
Linkedin
Siri Toilet Flusher

Siri Enabled Toilet Flusher

This was a fun project just because. My friend gave me a challenge a while back to see if I could flush my toilet with Siri. So I did. Here’s How.

Above is a video demonstration. Basically I used and Arduino Yún. Can check them out here: https://store.arduino.cc/usa/arduino-yun
They have since retired this product. It was a $75 microprocessor with a Linux SoC or System on a Chip. It included wifi and bridge software to link the Arduino Microprocessor with the Linux computer. Using that I wrote a virtual home automation device that was called, Toilet Flusher. Then you just ask Siri to, “Turn on the Toilet Flusher”, and voila.

Check out the ConsultingJoe YouTube Channel for More!
https://www.youtube.com/c/ConsultingjoeOnline

It's only fair to share...Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Share on linkedin
Linkedin

USB Distance Sensor and Software

I have created a simple distance sensing device with an Arduino Mega and an ultrasonic distance sensor to measure up to 5 feet. Also it is communicating to the host computer via USB at 115200 baud which allows for fast data updates and precision.

Below is a mockup of the software to customize and extend the uses of the device. Do anything from scroll through the web with hand gestures or create an invisible tripwire in your room or doorway. You can even use it to count customers entering your store or how many times your front door opened throughout the day.

Use if for real world data analytics or to improve energy efficiency around the house .

I plan to sell my distance device for a low price to get it into people’s hands and to cover my time in the software. I believe the software to this product will create the most value to average customers of all ages. My price point in mind is $24 on a production scale. But if you have a useful idea for this that has distance measuring needs I would create a custom one with some basic software for $50. It can be expanded on and it’s open source so all the code is available online.

Over the weekend my friends and I had a chuckle by creating a tripline to play randomized fart sound effects. Anything someone would grab a beer in the kitchen they would get a new fart noise. Goofy but a good example of the many uses it can serve. My favorite is scrolling through web pages when reading articles online. You can control volume or skip the song on iTunes. My devices is like a one dimensional Leap Motion. A Leap motion can see your hands in 3D and can do endless number of gestures. to control your computer, interface with software or play guys with your hands being the controllers.

Checkout the Store to see if it pops up in the near future. 😉

Goodbye for now.
-Joe