Applications of Raspberry Pi 4DIO UPS Board(IA003)

Raspberry Pi 4DIO UPS Board(IA003)

In this blog we would like to show some of the features of our ARMtronix board- IA003 i.e. Raspberry Pi 4DIO_UPS_Board using Raspberry Pi and Node RED.

Block Diagram:

Components Required:

  • Raspberry pi.
  • ARMtronix board (IA003).
  • 3.7V Li Battery.
  • RTC battery.
  • Push buttons for inputs.
  • 4-20mA input ADC sensors.

Steps to setup the Raspberry Pi:

  • Insert the microSD card into the card slot on the underside of the raspberry pi.
  • Plug the USB keyboard and mouse into the USB ports of the raspberry pi.
  • Plug the HDMI cable into the monitor and connect the other end of the cable into the raspberry pi.
  • Connect the ARMtronic board(IA003- Rpi 4DIO UPS Bord ) to the raspberry pi header and turn on the power supply into the power outlet of the ARMtronix board. This will turn on and boot up the raspberry pi. A power indicator light will begin to glow, which means that the Pi is connected properly.

NOTE: Care must taken while connecting the ARMtronix board to the raspberry Pi, i.e. both are must connect in such manner that the 1st pin of the board is connected to the 1st pin in the header of the raspberry pi as shown in the below diagram.

Setting up the RTC:

  • The first order of business is to setup/enable the i2c bus on the raspberry pi. You do this by uncommenting a line in config.txt. “sudo nano /boot/config.txt
  • Scroll down until you find the line “#dtparam=i2c_arm=on
  • And uncomment it by removing the # then exit and save (ctrl-X then y). This will enable the i2c bus (well it will on your next reboot).
  • Next install the i2c tools by typing: “sudo apt-get install i2c-tools”. This will install some handy utilities for the i2c and then reboot “sudo reboot
  • Now verify that the board has RTC by running “sudo i2cdetect -y 1” at the command line. We will get ID #68 in the terminal (the I2C address of the DS1307 Real Time Clock chip).
  • We need to load the RTC module by running:

sudo modprobe rtc-ds1307

  • Now we need to be running as the super user; type in:

sudo bash

  • and then,

echo ds1307 0x68> /sys/class/i2c-adapter/i2c-1/new_device

  • Type exit to stop being the ‘root’ user.
  • Check the time on the RTC device using

sudo hwclock -r

NOTE:If this is the first time the module has been used, it will report back Jan 1 2000, and need to set the time to the current time. Run “sudo hwclock -w” to write the system time to the RTC board. We can then verify it with “sudo hwclock -r“.

  • So, now the RTC clock is set, but the next time we boot the pi, it will not know that it needs to read the clock from the RTC, so if it is not connected to the internet it will again be showing the wrong time.
  • To Making raspberry pi to use the real time clock, we will need to add the RTC kernel module to the file /etc/modules so it is loaded when the raspberry pi boots. In terminal window run “sudo nano /etc/modules” and add rtc-ds1307 at the end of the file.
  • Next we will need to add the DS1307 device creation at boot by editing the /etc/rc.local file by running the command “sudo nano /etc/rc.local” in the terminal window.
  • Now add the following lines to the file.

echo ds1307 0x68>/sys/class/i2c-adapter/i2c-1/new_device sudo hwclock -s date

  • Then to save the file, press Ctrl+X, Y then return.
  • To check this, we need to shutdown the raspberry pi, unplug any ethernet cable or wifi dongle and then turn the raspberry pi back on. Now use the following command in a terminal window to check the date is set,

date

  • Next time when we reboot our raspberry pi it will read the time from the Real Time Clock(RTC).

Battery monitoring and reading the ADC values:

There are three channels on the board to read the ADC values and one channel is there to read the battery voltage. We are using the channel-0 for the battery voltage and channel-1 to read the current values.

Here for the ADC values we have used the 4-20mA signal generator just because to we can vary the ADC values for testing purpose. You can also use the following 4-20mA signal generator which gives you the analog value output.

And you can use the Inductive Proximity Sensors for testing the Gpio’s of the board as this sensors output value will be in digital for i.e. either 1(high) or 0(low).

Connection:

Make the connections as shown in the above figure. Once you are done with the connections, turn on the system and verify that the board has ADC by running “sudo i2cdetect -y 1” at the command line. You should see ID #48 shown up (the I2C address of the ADS1115 chip).

Now here, we are running the below shown simple program for battery monitoring as well as reading the ADC values from the IA003 board. Execute the code by typing the “python battery_voltage.py” command in terminal window of the raspberry pi.

After executing the program we will get the results as follows. We are getting the battery voltage and the current values of the 4-20mA signal generator readings.

Here we are giving the 24V supply to the board and we are connecting the 4V battery to it. When the board is consuming the 24V, the battery will be charging at that time. When there is no 24V supply to the board, still the raspberry pi will turned on using the battery voltage and we can safely shutdown the raspberry pi. The main purpose of using this board is, when the raspberry pi is running and sudden there is lose of power, automatically the whole system will became off then there is chance of losing the files and also the SD card may corrupt due to improper shutdown of the raspberry pi. But this board will keep the raspberry pi on after the lose of power so we can shutdown the raspberry pi properly.

Node-RED Concept:

For the battery monitor and controling feature here we made simple flow in the Node-RED such that the node ‘test’ will inject the input for every 30 sec. to the node ‘adc’, the node ‘adc’ will read the ADC value of the channel-0 and it will display the adc value through the ‘ADC Value’ debug node. After that we are using the function node (‘Battery Value’), where we wrote small code to convert that adc value to the battery voltage and display the value through the ‘battery converted value’ debug node. Then we have one more function node (‘Battery Monitor’), where we are reading the battery converted value and when that value goes below the certain value it will automatically encounter the shutdown command and the Raspberry pi will shutdown. The following figure is the flow for the battery monitoring.

The below figure shows the code of the function nodes Battery Value and Battery Monitor.

Test for input and output GPIO:

Make the connections as shown in the above figure for testing the input and output gpio. In this case we are using the 24V push buttons for input as well as output. These push buttons contains the 24V LED in them for output. Make sure that the connections are done as above. Now for testing the input and output gpio’s , we are running the following simple code.

After executing the code we will get the output results as follows.

In IA003 board we are using the pull-up for the gpio’s. so initially the inputs and outputs are high. Here GPIO 6,13,19,26 are input gpio’s and GPIO 4,17,22,27 are the outputs. We write the simple code such that when we make input gpio low then the respective output gpio will also become low.

Node-RED Concept:

To test the GPIO’s present in this board we made the following simple flow, where we are selecting the input GPIO using Raspberry Pi input nodes. Then the input nodes connected to the Raspberry Pi output nodes and also connected to the debug nodes to know the state of the input nodes. Here the logic is such that when the input node is low the output node which is connected to that node also goes low. Similarly, when the input node is high then the output node will also became high.

Here we are implemented the some logic gates to test the input as well as output gpio and the flows for each gates are as shown below.

  • AND Gate:
  • OR Gate :
  • NOT Gate :
  • NAND Gate :
  • NOR Gate :

Testing the GPIO-05:

Make the connections as shown in the above figure for testing the GPIO-05. Here we are using the 4V battery. Now to test the GPIO-05 we are running the simple code shown below.

After the execution of the code we will get the results as follows. i.e. when the board is running on mains supply(24V), the gpio-05 will became high and it will print the ‘24V supply’ in the terminal indicating that gpio-05 is high. Similarly, when there is no mains supply and the board is running on battery, the gpio will became low and it will print ‘no supply’ in the terminal window.

Applications:

  • Battery monitoring: Let us take a scenario, In industries, when they are using raspberry pi and sudden power goes off, then the raspberry will became off and there may be chance of memory corruption to happen. But our board has circuit, where we are using GPIO-09 and it will be always high when the board is ON. Here we are using AND logic between the gpio-9 and mains input. So when the power goes off, the Raspberry pi will still powered ON using the battery voltage and when the battery voltage goes below the mentioned value ( must be greater than 3.2V), it will automatically shutdown the Raspberry Pi which is the safe way to turn off the Pi. By this we can avoid the memory corruption. Next on the represence of the mains power, the board will reboot itself automatically and battery will starts to charge. NOTE: For this application, by default we must make the GPIO9 high. It will became low only when the whole system is off. Here we are making it high by using the Node-RED.
  • Input/output GPIO and ADC: For the application purpose of the input/output GPIO and ADC, we have example setup as shown below.

Let us take the above example, here the basic concept is to trigger the relay which is connected to the one of the output GPIO based on the ADC value from the either one of the channel (in this case, we are using the channel-1). We are testing this using the NodeRED application as follows.

In the flow, to read the ADC value we have used the channel-1. Here first we are reading the channel-1 value and then we have fuction node called ‘ADC converter’ where we convert the ADC value to the 20mA. After that we have one more function node ‘Relay Trigger’ and have simple code where if the ADC value crosses the 15mA , relay will trigger which is connected to one of the output gpio and the bulb will glow. Similarly when the ADC value goes below the 15mA, again relay will trigger and the bulb will became off. Below figure shows the codes for the function nodes ‘ADC converter’ and ‘Relay Trigger’ respectively.

Leave a Reply