1223

CAN Bus can be monitored using Arduinos & PHPs. PHP-Serial can gather data effortlessly from arduinos...

CAN Bus for Solar PV cell on PHP

Monitoring of the individual solar PV cell current contribution was our original aim of this project. Therefore, we created Arduino program each for Master and slaves and then on the master serial terminal we monitored the PV cell current output.

But to be frank the output of such an ambitious project on a serial terminal was not very good rather it was very dull and timid. So we tried to create a graphical output on Processing. The processing program was getting data from serial terminal and then it was projecting on the Processing output like this.






















This was better but the problem lies somewhere else. The processing is not so stable and it hangs often at least once in a day besides it’s array sorting command is not that powerful. In CAN bus when one output becomes zero it moves down and the positive one moves up.
Say id1=5 and id2=15 , It’s OK when both are possitives. id1 and id2 will appear as we set in Arduino. If id1=0 and id2=15 then id2 will appear before id1. You may set id1 to appear before but in that case the the id positions will be interchanged. That means every time we have to sort all the ids in an ascending or descending order and then locate the right PV cell.

Sorting in Processing is not that majestic what is there in PHP and the PHP-Serial collects data effortlessly from the serial port.

But PHP-Serial in browser window (www-data) is not that fast, so we created two programs data2.php which is run in a terminal to dump data in a text file ‘newfile.txt’ and then an index.php which will open in the browser to create the dashboard of CAN Bus output like this.

The power of PHP can do all the things – like sorting , change the font color when the value goes below any set limit or change again when it comes back to normal value, speed is very good besides being rock stable.

Since, I put only two solar PV cells and gave them at the last two IDs – 254 and 255 ,I just placed them at the last two cells in PHP.

Procedures:
Upload the slave programs in the slave Arduinos, and upload the master program in the master Arduino. Connect the CAN Transceivers on the SPI bus of the Arduinos as per the diagrams. Connect the CAN bus – the twisted pair shielded cable for the hi and the low bus. Connect the ACS712 output on the A0 port and finally connect the power supply using the Buck charger. The CAN will start communicating with each other. The CAN can communicate with each other and does not depend on any MCU or computer connected on it or not. Connect the USB cord to the master CAN and then open the serial terminal to find the current signal coming from each slaves.












The output is correct but certainly not very ambitious like the CAN bus itself. Note down the serial terminal – ttyACM0, ttyUSB0 or ttyACM1 etc. Now close Arduino and then go to the /var/www/html/serial/ directory and open data2.php in any editor and change the serial port with this one (ttyUSB1 or ttyACM0 etc.)
$ sudo gedit data2.php and change the serial port by the right port number. Now time has come to run it. Go to the /var/www/html/serial director or wherever you have downloaded the data2.php program and run it.

$ php -f data2.php &
The ‘&’ at the last will send the program to the background mode. The program will collect data from the serial terminal using PHP-Serial program of PHP and then dump it in a plain text file anywhere you like. Here it dumps one line data in /home/bera/newfile.txt file.

Browser output: Open the index.php file in any browser window http://localhost/serial/index.php and you will find the beautiful table of PHP and the data will be displayed in the dashboard.

Color change: If the value goes below 500 ,it will turn red else it will be green. The maximum value it can go is 1023. Achieving this in PHP is very easy.

Aftermath: The best way to deploy this whole setup is doing it on a Raspberry Pi computer. Next we will do just that. Hang for my next project – CAN Bus on Raspberry Pi.



Bye bye,

Bera