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

Web Design & Consulting – RecoveryOneOnOneInc.com

This project was a pressure doing and it turned out beautiful. This website I created with the client gives this business a home Online where existing and potential new client can easily find out what they offer, how they offer their services and give users easy access to contact information and forms along with signup information and forms.

Site View From iPhone X

The site is completely responsive to give users the same look and feel on any device and sized screen. Elegantly, the website elements and photos will slide and fade into view while scrolling scrolling through sections.

The underlying code running the content management system here is WordPress. WordPress is an Open-Source content management system using PHP and MySQL. It has a very large following and support in the Open-Source community and makes for a perfect fit in this situation.

If they required more of a databased system and customizations I may have considered rolling my own web application for them. This wasn’t necessary and time and budget were a major factor as they had a major class event starting at the beginning of the year. There were extensive customizations within the WordPress template and plugins to achieve the look and feel the client had envisioned.

Please take a look at RecoveryOneOnOneInc.com and consider Joe for your next tech project.
Contact Joe Today!

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

3D Design and Printing – Child Invented Board Game

3D modeling and printing is just another way for me to be able to create. It’s a growing field for me. Below are photos from a fun project I did back in 2018 for a grade school student looking to make a permanent version of their prototyped board game for a school project and completion. The prize was the chance to get your game made for real! The winners game would be considered in the creation, marketing and retail with a board game company. How fun?!

I was excited to help with the project. The student and her father already had the game created. It was made from Styrofoam and it was not easily cleanable as it required goo that would go on the board game and needed to be cleaned off and all the goo to be reused. The Styrofoam did not make that easy. So they found Consulting Joe on Google and called. I was able to get a bit more creative and product a foldable plastic donut, which was the game board. I also created different colored game pieces and a more professional looking game top that was secured with packing tape. This was still a prototype of a product and a grade schoolers project along with a limited budget. We were happy all around with results of the project.

If you have ideas about a prototype product or something you would like 3D printed, please contact Consulting Joe.

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

Web Design – TrustColeman.com

TrustColeman.com is a website for local HVAC contractors to connect with customers and Coleman products in the Will County, IL area. It is sponsored by Johnstone Supply and it offers an interactive area map of quality contractors and their locations. It also offer warranty registration data entry forms that store and email data to administrators.

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

Web Design – WholeCellOnline.com

WholeCellOnline.com is the home of WholeCell Accessories. WholeCell is a Chicago based cell phone accessories franchise that offers cell phone, tablet and computer accessories. They are located in Joliet, Lansing, Chicago Heights, Northlake. Locations are popping up all the time.

I was contracted to find a solution to a problem. The company needed a way to look up inventory, sell items in the store and transfer/receive inventory from vendor orders, warehouse and other stores. The system is web based database driven. Technologies used to develop the system include PHP, mySQL and jQuery. The website is mainly for employees only and users must login to access inventory and store information.

Take a look to see their locations: http://wholecellonline.com

Software – Comprehensive Point-of-Sale System

Around 2012 I was contracted to create a custom E-Commerce system to allow for custom categorizing of cell phone, tablet and computer accessories and their associative devices. It was a success. It covered all the business needs to sell online. It was later evolved to also sell on other online marketplaces like Amazon, eBay and Bonanza.

The clients were so happy with what the system can manage as far as inventory, orders and users that they hired me full-time. I was then tasked to build a system for their storefront locations. The system I created showed updated inventory across the company (stores, warehouse and sold online inventory). I created a point-of-sale system to replace a system by B2B soft that focused on phone carriers and phone activations.

My POS system offers phone activations, bill payments, device repair orders and much more. It does sales, exchanges, returns, split tenders, price updates and store credits. My point of sale works with multiple store locations, users, and chip and pin credit card machines. I have experience with Virtual Merchant, Converge Pay API and the Ingenico is250 Touch.

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