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
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
Siri Apple Watch to Indigo Home Automation

Home Automation Bridge for iOS & Indigo Home Automation

Here’s a cool example of some of my software engineering experience and problem solving. I wanted to control my Christmas Tree lights with my Apple Watch and Siri. The problem was my home automation software didn’t support HomeKit, yet. So I did some research and found a piece of software that allowed you to create virtual home automation devices.

My home automation platform and software is a Mac and Indigo Home Automation, the best home automation software on the Mac hands down. So at the time, Indigo didn’t support my Siri commands through HomeKit. I was able to create a fairly simple script that would create a dynamic passthrough of home automation commands on Siri with home automation devices on Indigo. It would map the device and action so when you say, “Turn on the Christmas Tree Lights”, my script would receive the commands then ask Indigo using AppleScript to turn on the Christmas Tree Lights’ device. AppleScript is Apple’s plain english like programming language.

Below is a video demonstration and the open-source code to try it for yourself.

Open Source: https://github.com/jsammarco/IndigoHomekitBridge

Check out The ConsultingJoe YouTube Channel for More.
http://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

My First Gas Plane Flight

I have probably over a thousand hours of electric RC flight time. But this was my first gasser flight. It’s a great plane but unfortunately the engine cutout on takeoff. I luckily saved her. This was my buddy and his dad’s plane but they’ve always had bad luck with it so they trusted me to take her up. We suspect that the line got clogged from some particulate in the tank. The gas dried up once before and it must have loosen up some flakes.

Well watch what happens. Fullscreen the video because my friend Ken is a jerk and doesn’t know how to turn the phone sideways to make a decent video, lol. Also listen to when the engine cuts out on me.
Don’t forget to LIKE & SUBSCRIBE too.

Magic Time-Lapse Video of Mask

Yesterday I started this print last night and it took about 15 hours to complete. It was very large and I experimented with a different pattern for the top and bottom infill, the. It also has a 5% infill on the base with a 3D honeycomb design for strength while saving plastic and print time.

FileFinalMask5.gcode
Filament (Tool 0): 48.91m / 117.65cm³
Approx. Total Print Time15 hours


Print Time14:58:55

My Make on Thingiverse: https://www.thingiverse.com/make:487301
Please watch the video below. It turned out great. LIKE & SUBSCRIBE

 

 

3D Printing – 2 Tone Star Wars Logo

It’s pretty amazing what you can do with a 3D printer. Just the other day I printed a couple of these Star Wars logos with black PLA then paused and switched to what little yellow PLA I had left.

The first “Star” half turned out all black. I forgot to check back on it to change the color. Darn, I could have prevented this by finding the layer and adding a pause command in the Gcode. If I were to do that I would want to move the nozzle off of the print so you don’t ruin it. Then when you change the filament and purge in the next color it should move back. This gives me an idea for a web app to help automate just that! Back to that idea later. Check out my print on Thingiverse.com.

Here is a link to the original 3D print where you can download and print this for yourself.

I recommend getting more into 3D printing. There is a learning curve but you learn a lot!
Check out some of my other Star Wars 3D Prints.

Thanks for stopping by,
Joe