Solar Power System Monitoring with an Arduino

Sometimes, people wonder about the practical side of using an arduino. I do get asked what is the real use for some of the articles I post here.  Are these ‘gadgets‘ just toys or do they have a practical use?  Most people who ask though, are not that familiar with arduinos or microcontrollers in general.

So, this post is a partial answer to some of those questions and a place I can refer people to.  Although, if people were really curious, a search would show them a number of practical uses for arduinos and microcontrollers in general.

For example, I recently posted articles on using an arduino to communicate via the RS485 protocol here and here. Another post shows how to use an LCD (using only 3 pins) with an arduino here.

This post will show how to use the knowledge gained from those posts (plus a bit more) to build an arduino ‘gadget’ which can be used to monitor an inverter. Hence, the title of this post:  “Solar Power System Monitoring with an Arduino”.

An inverter is an essential part of a solar power system which uses sun light (solar energy) to produce electricity.

A solar power system (initial investment) can be quite expensive, depending on energy needs. Replacing parts is also expensive.  Monitoring what is happening with the solar energy conversion to electricity and its subsequent usage, is a very important part of the system to make sure it is being used efficiently and properly. If we can use an arduino for monitoring (which we can), we thus have a practical use for it (especially considering the price of buying commercial products versus do it yourself with an arduino).

I happen to have a Magnum inverter which is connected (and controlled) by an ME-ARC remote monitor. I was wondering if the ME-ARC is really needed and if it could be replaced with an arduino and an LCD screen. In my testing, I found out that the ME-ARC is not needed to actually run the inverter and it can be replaced with an arduino. What follows documents how it can be done.

The only connection into the ME-ARC is an RJ11 cable from the inverter. This RJ11 cable is the same type of cable used to connect telephones to wall jacks.

Since there is no external power cable, the RJ11 connection must be supplying both power (volts/ground) and data.  Further information is needed on how the remote gets power and data from the inverter. This information is in the Magnum Network Communications Protocol document found via a search.

From the document, we can see that the RJ11 cable does indeed provide power (14 Volts, Ground) and data. The protocol in use for data interchange is RS485. So we can use the information from my earlier posts to see how we can attach an arduino to the inverter. Note: The end of the document has a ‘Third Party Notes’ section which concerns  connecting your own device to the Magnum Network. How did they know we were going to connect an arduino ?  🙂

The RJ11 (4 wire) connection is wired like this:

Looking at the ‘front’ of the RJ11 connector with the ‘tab’  at the top, pin 1 is on the right side,  pin 4 is on the left side.

Since the arduino and the LCD need 5 volts to work and the inverter is sending 14 volts, we need a way to regulate the 14 volts down to 5 volts.

Here is the simple circuit to accomplish that.

LM7805 Voltage Regulator


Get the Fritzing code for that circuit image here.



LM7805 Circuit

This is what the circuit looks like when built.





I used an RJ11 splitter to attach both the ME-ARC and my arduino at the same time.

The splitter RJ11 Splitterwas connected to the back of the ME-ARC. The RJ11 cable from the inverter was plugged into one side of the splitter and the cable to the arduino was plugged into the other side of the splitter. Wiring that way allows viewing the ME-ARC and checking what it is showing versus what the arduino is showing. This is a good way to check that the code in the arduino is providing the same (accurate) results.

Since the communications from the inverter uses the RS485 protocol, we will use the wiring shown in a previous post which uses the SN75176BP IC for the protocol conversion.

If you haven’t taken the time to read that post, here are the wiring diagrams for the SN75176BP (left) and the complete circuit (below). The diagram shows RS485 communications between two arduinos, however, we can just pretend that one of the arduinos is the inverter. In fact, one of the arduinos was running code to emulate the inverter for testing purposes but I did not mention that in the original post.  Now you know. 🙂

SN75176BP RS485 Communications using Arduinos

Get the Fritzing code for that diagram here.  For connecting just one arduino to the actual inverter, the ‘A’ pin (from the RJ11 connector pin 4) connects to the ‘A’ pin of the SN75176BP and the ‘B’ pin (from the RJ11 connector pin 1) connects to the ‘B’ pin of the SN75176BP.

LCD Shift Register Circuit for an LCD


In hooking up the LCD to the arduino, we will also use the information from a previous post.  There we show how to use a shift register IC to minimize the number of pins used to connect the LCD to the arduino.


Now that we have all of the hardware details, we can hook it all up. The RJ11 splitter is connected to the ME-ARC. The RJ11 cable from the inverter is connected to one side of the splitter. The other side of the splitter is connected to the arduino circuit this way:

Here is what it looks like all attached and working:

Solar Power System Monitoring with an Arduino

From the picture, you can see the RJ11 cable (on the right) dropped down from the splitter on the ME-ARC. I have an RJ11 female/female connector to the cable and to an RJ11 connector which breaks out the 4 wires connecting to the arduino and the voltage regulator circuits.

You are probably wondering about the output on the LCD? Since the LCD has only 16 characters x 2 lines, it has limited space to display things. The first line has ‘codes’ for what it is displaying:

The 2nd line displays the DC volts and  amps being used just like the ‘Meter’ on the ME-ARC. The code in the arduino gets these values from a data packet sent by the inverter every 100 milliseconds. The Magnum Network Communications Protocol document (mentioned earlier) details the communications and values being sent.

Here is the arduino code so you can see how the arduino captures the inverter data, waits for the 100 millisecond ‘gap’ and then decodes and displays the values.

One serial port is used for communications to the inverter and another is used to optionally communicate with a PC and get commands to send to the inverter. Note: The code for transmitting data to the inverter is there but commented out.  I am using the Software Serial library (to emulate an additional serial port) because the Arduino Nano I am using for this project only has one serial port. The other library (LiquidCrystal595) is needed to control the LCD with only 3 pins. Make sure, if you use that library, to patch it according to the comments in my post about it mentioned above and referenced again here.

Since the inverter sends a data packet every 100 milliseconds, we can check for that ‘gap’ (no data being sent) and know that we have a complete packet.  However,  since it will take some time to run the code to display on the LCD we need to pick a ‘safe’ value for checking that timing. You will notice in the code:

the timer holds the number of milliseconds since the last input byte from the inverter. I chose a ‘safe’ value of 30 (milliseconds) which should give enough time to display on the LCD and get back to checking for inverter data.

The next step would be to test sending data to the inverter as does the actual ME-ARC remote. Only then would we have something to be able to totally replace the ME-ARC.

So now you can see that there are ‘building blocks’ (so to speak) in my posts which used together can produce something practical, Solar Power System Monitoring with an Arduino.

How a Web Server on an STM32F103C8T6 can be used to control a Relay Switch

Here is the circuit showing how a Web Server on an STM32F103C8T6 can be used to control a Relay Switch:

BluePill As A Web Server With A Relay SwitchThe Fritzing code used to create that diagram/image can be downloaded here.

An ENC28J60 ethernet module is used to connect the STM32F103C8T6 (BluePill) to a network.

Here is the source code for the sketch to load into the STM32F103C8T6 (BluePill):

This is an updated and enhanced sketch from a previous post on a WEB server using both the BluePill (STM32F103C8T6) and the ENC28J60 module. It seems the UIPEthernet  library has changed since then. I had to add these lines to the code to define the correct pin settings:

The source code has the IP address and network settings for the ENC28J60 ethernet module hard coded. Those settings may need changed for use on a different network.

The relay switch can be attached to any number of AC type low current devices and turned ON/OFF by accessing the WEB server. (The relay switch can possibly handle low current DC devices as well). I used a 2N3904 NPN transistor in my circuit to allow the STM32F103CT6 to turn the relay OFF and ON. This circuit also has a red LED to visually show when the relay is ON or OFF.

The WEB server accepts several ‘commands’:

‘LED’ toggles the internal LED On/Off, ‘analog’ displays the analog values of the first 4 analog pins and ‘switch’ toggles the relay On/Off.  So now you know how a Web Server on an STM32F103C8T6 can be used to control a Relay Switch.

SN75176 RS485 Communications between two Arduinos

Previously, I wrote about RS485 communications between two Arduinos using a MAX485 IC. The link for that post is HERE.  It showed one Arduino as a tranmitter and the other as a receiver. This post is very similar, however, I am using a different IC, the SN75176BP. This post is about SN75176 RS485 communications between two Arduinos which allows either one to transmit and receive at the same time.

The SN75176 IC is also an RS485 transceiver like the MAX485 however it is full duplex where as the MAX485 is only half duplex. Full duplex allows sending and receiving at the same time.

Here is the pin layout for the SN75176BP IC which I am using:

SN75176 RS485 Transceiver






This chart shows the function of each pin of the SN75176:

Using two Arduinos, each with an SN75176BP, we can establish two way communications:

SN75176 RS485 Communications between two Arduinos

SN75176 RS485 Communications between two Arduinos

The Fritzing diagram source is HERE in case you would like to modify it.  Note that the RE (Receiver Enable) pin is wired permanently low. The DE (Driver Enable) pin is turned on (high) only when data is sent.

The Arduino UNO that is used here only has one serial device, so the software serial library is used to add another serial device on pins 8 and 9. The software serial port is used to communicate (via RS232) to the SN75176 and the built in serial port (via USB) is used to communicate (via RS232) with the host computer the Arduino is attached to.

Load the following code into each  Arduino:

Attach a serial connection to each Arduino and data can be sent back and forth thru the  connection between the two SN75176 ICs.  Use my handy updated Python serial communications program for that purpose:

Once this is working, you have a ‘prototype’ to emulate other equipment or use ‘half’ (one Arduino and one SN75176) to attach to other devices using the RS485 interface such as Modbus RTU.

Use An Arduino Leonardo and a Button for a USB Foot Pedal

It is possible to use an Arduino Leonardo and a Button for a USB Foot Pedal.  Here is the story on how one was built.

A long time ago, my daughter used to transcribe audio cassette tapes using a transcribing machine. It had a nice foot pedal to start, stop and rewind the cassette tape. Recently, she decided to get back into transcribing. Instead of audio from cassette tapes, she is transcribing MP3 audio files on the computer. She choose a software program called ‘Express Scribe Transcription Software’ from NCH Software for that purpose. It allows her to use any sort of word processing software to key in the text transcription while she listens to the audio it plays. Express Scribe allows her to map keys, which it intercepts, to stop and restart playing the audio. A nice feature that it has, is that it automatically goes back several seconds when stopped so no ‘rewind’ is really needed.

Here is a screen shot of what that software looks like:

Express Scribe Transcription Software
The Express Scribe Software also works with several different USB foot pedals.  The USB foot pedal acts as an extra keyboard and sends keystrokes when the pedal is pressed. If you have ever done any transcribing, you will know how handy using your foot is, versus using the keyboard for stopping and starting the audio.

Rather than buying a USB foot pedal, Dad was asked if there was an Arduino solution. Dad of course took up the challenge.

The first step in the process was to set up a prototype of the process. An Arduino Leonardo was chosen (due to Dad having several around) and due to the Leonardo being able to plug into the computer and function as a USB keyboard.

Every USB device is assigned a device class, which defines what exactly its general purpose is. The Leonardo can  be programmed  to act  like a mouse, keyboard or other HID (Human Interface Device) class USB device, so it is just right for this project.

A simple circuit was constructed to test the functionality of the Leonardo sending keystrokes when a button is pressed.

Here is the circuit (just a basic button circuit):


You can get the Fritzing code used to create that diagram HERE.

The Express Scribe software was configured to use the ` key for stopping playback (and rewinding) and the Tab key was configured to start the playback. So the Arduino Leonardo sketch was coded to send those keys when a button was pressed.

Here is the sketch (i.e. the code which is compiled via the Arduino IDE and loaded into the Leonardo):

You will notice that only one button is used. There is not a separate button for stop and start. There is really no need. The sketch keeps track of what comes next. Pressing the button alternates between sending the Stop and Start keystrokes. Since the software takes care of the rewind (on stop) there is no need for that function via the button.

That code and the sample circuit was plugged into the PC via a USB cable to the Arduino Leonardo for testing and worked very well. The next step was to build something that could function as a foot pedal (i.e. allowing the foot to press the button).

An important consideration in this project is that whatever is used as a ‘button’ for the foot pedal be easy to push and still function as a ‘button’.   Here are some pictures of the large ‘gaming’  type buttons that works well for our purpose:








To use an Arduino Leonardo and a Button for a USB Foot Pedal we also needed something to house the Arduino and keep the button stable on the floor.  Here is where the brother (or son depending on who’s view you are looking from) comes into the picture.   The brother is adept at wood work so he was tasked with coming up with that.

RS485 Arduino Communications

There are various ways for two Arduinos to communicate information. A common way is serially via RS232. However, RS232 has distance limitations. If there is a need to serially communication over a longer distance consider using RS485 instead.  A couple of MAX485 ICs can facilitate RS485 Arduino communications over that longer distance.

Two MAX485 ICs connected together will take RS232 signals and perform the voltage level conversions required to turn them into RS485 signals and back again to RS232 signals. That will allow two Arduinos to communicate serially over a longer distance.

This chart shows the specific pin functions on the MAX485:

Here is how to connect the two Arduinos using two MAX485 ICs:

Max485 Arduino Communications

Get the Fritzing source HERE.  5V is used in this simple demonstration. For longer distances a higher voltage will be needed to power the MAX485. Also the BAUD rate will need to be adjusted (the longer the distance, the slower the speed).

This is the source code for the Transmitter:

This is the source code for the Receiver:

Here is what it looks like (messy wiring and all):

MAX485 ArduinoMAX485 Arduino

Nuttx on the STM32F103C8T6

Wouldn’t it be  C 🙄 🙄 L to have a Linux prompt on the STM32F103C8T6.  Not likely, however, Nuttx on the STM32F103C8T6 is about as close as you will get.

Nuttx is a RTOS which runs on a wide range of microcontrollers including the STM32F103C8T6.

To compile Nuttx for the STM32F103C8T6, a development environment needs set up with the right tools. My development OS of choice is a Linux distribution called Fedora (Fedora 29 is the current version at the time of this post).

To install the tools needed, I used these commands:

The first DNF command installs the ARM development tools needed to compile Nuttx for the ARM based STM32F103C8T6. The second command installs the GIT tool used to grab the source code. The third command installs other development tools necessary for the compile process.

To begin the process, create a directory to store the downloaded source and tools:

The Nuttx source code is downloaded with these git commands:

The Nuttx configuration process needs the  kconfig-frontends installed via these commands:

The reason for the aclocal and autoconf is to update the configuration files due to the newer versions of Fedoras’ development tools.

Next, create the Nuttx specific compile for the STM32F103C8T6 via these commands:

That last command should have set up everything correctly for the compile. however,  this next step allows verification of all settings and options.

A menu will appear like this:

Nuttx Configuration Menu





Optionally, verify the build setup and other options. Save and Exit when done.

This last step compiles the code and creates the nuttx.bin binary file to load into the STM32F103C8T6.

Attach the STM32F103C8T6 to a USB/Serial converter to load the Nuttx binary image:

STM32F103C8T6 with CP2102

To load Nuttx on the STM32F103C8T6 va the serial to USB converter, I used the stm32flash utility downloaded from  HERE.  Use these commands to install it:

Use this command to load the nuttx.bin file into the STM32F103C8T6:

Once loaded with the nuttx binary, the STM32F103C8T6 is ready to send the nsh (NuttShell) prompt. Connect your PC to the USB/Serial converter port with any serial communications program (115200 baud)  (like MINICOM ) and press the reset button.

Even the linux screen program can be used:

screen /dev/ttyUSB0 115200

I  like using  my Python serial program  (documented here) via the command:

For more info on Nuttx and what can be done with it, check out the site HERE.

Turn an STM32F103C8T6 (BluePill) into an STLink Programmer

It is relatively easy to turn an STM32F103C8T6 (BluePill) into an STLink programmer. All that is needed is a copy of the STLink firmware and a means to flash it. Do a search for STLinkV2.J16.S4 and download it. Flash that binary file into the STM32F103C8T6.

The new STM32F103C8T6 STLink can then be upgraded to the latest firmware version from

Here is the wiring diagram on how to connect the new STM32F103C8T6 STLink programmer to another STM32F103C8T6 to program it:

BluePill as an Stlink ProgrammerDownload the Fritzing Diagram from HERE. Actually, the capacitor and 4k7 resistors on the right side of the diagram are not needed (it works fine without them).

The Arduino Command Line Interface (CLI)

The Arduino folks just came out with the Arduino Command Line Interface (CLI) :

A while back, I wrote about the  Arduino-Builder which is what the Arduino IDE invokes behind the scenes to compile the sketch. (That post is here.) Now, with the Arduino Command Line Interface, everything that can be done from the IDE can now be done on the command line.

The Arduino Command Line Interface can be downloaded from here. By the way, it is also written in the Go language.

I downloaded the file for my system (Linux 64 bit):

Extracted it:

and moved it to an easier name:

I tried it out and got it working OK for the BluePill but had to make some changes to the boards.txt configuration file.

Here is how I got it working for both the Arduino Uno and  the BluePill (STM32F103C8T6):

Create these directories first (the are needed and not created if they don’t exist):

Create a basic config file since it will need to be modified to add the BluePill info:

Edit the .cli-config.yml and add these lines at the end:

Next, create a basic test sketch (and optionally edit it):

Next, create the index json files via:

Optionally look and see what boards are available to install:

Then install the stm32duino files for the BluePill:

Optionally install the core files for the Arduino Uno (etc.):

You can see a list of the installed boards via:

If you try and compile the test sketch now via:

You will see a bunch of errors, so you will need to edit the boards.txt file:

To eliminate the errors, change some of the genericSTM32F103C lines with  the string….build. in them to just lines. Make sure there are no duplicates. (The .menu. lines are for selections in the Arduino IDE.)

Once all the correct options are fixed in the boards.txt config file, the sketch should compile fine via:

To see if the arduino-cli recognizes your attached BluePill (or other Arduino), run:

To upload the sketch:

Libraries can be found with a search:

And installed via:


At no time did my fingers leave the keyboard… I like the cli !

STM32F103C8T6 DIY Programming Cradle

I recently created an STM32F103C8T6 DIY programming cradle. Here is what it looks like:

STM32F103C8T6 DIY Programming CradleIt comes in handy when you need to program a bunch of STM32F103C8T6s. (Note: I made a similar ‘cradle’ for programming bunches of ESP8266s’.  Read about that here.)

A standard USB to serial converter is attached to the 6 pin header shown on the right side. Here are some pictures. When the STM32F103C8T6 is ‘plugged in’:

STM32F103C8T6 DIY Programming CradleWhen it is attached to a USB / Serial converter:

STM32F103C8T6 DIY Programming Cradle

This Fritzing graphic shows how the connections are made from the USB to serial converter to the STM32F103C8T6:

STM32F103C8T6 Serial Connections

Download the Fritzing source here.

Push a Button and Play a Video

To motivate and engage sales people, have a big red button to push when a sale is made. They push a button and play a video. Something fun! Add flashing lights for extra effect!

Here are two different means to accomplish this. One solution involves an Arduino UNO serially attached to a PC running  the Windows OS. The other solution is just a Raspberry Pi running OSMC. OSMC basically turns a Raspberry Pi into an entertainment system.

A large screen can be attached to either the Raspberry Pi or a PC to display the video.  A Raspberry PI has GPIO pins which allow it to connect to the outside world. This makes it a standalone solution for this application. A normal PC has no such connections, so that is why something like the Arduino is needed.

The Arduino UNO connects to the PC via a USB to serial cable. This is how the Arduino can be wired to a button:

Push a button and play a videoDownload the fritzing source HERE.  Note: The wiring is basically the same for a larger big red button which would be easier to push (and more fun!)

Notice how the standard 4 pin push button is wired:

4 Pin ButtonWhen the button is pushed,  all four pins are connected. This is the Arduino sketch for monitoring the button push:

The  Arduino communicates serially to a Python script. The Python script, when notified of a button push, will start the video player to play the video. Here is the script:

Since that python script was designed to run on a Windows PC, VLC and Python need to be installed for it to work. The command to run VLC will need to be modified to the URL or file for the specific video to play.

The alternative solution to “Push a Button and Play a Video” is just a Raspberry Pi.  After installing the OSMC distribution,  use these commands to install the prerequisite software :

The prerequisite software is needed to allow a Python script to access the GPIO pins and interface with OSMC.  Next, wire the Raspberry Pi  to the button as show here:

Push a Button and Play a Video

Download the fritzing source HERE. A Python script (running on the Raspberry Pi) is used to monitor for the button push and run the video:

The Raspberry Pi running OSMC uses the xbmc_json python library to control  the native OSMC video player. The command to open the player and run the video will need to be modified to the URL or file for the specific video to play.

Which ever solution you choose, push a button and play a video! Fun!

Load more