Victron MPPT data using Arduino serial: Difference between revisions

From Sensors in Schools
Jump to navigation Jump to search
Line 219: Line 219:
     if (label =="V"){
     if (label =="V"){
           XBee.write(55); // DEC 55 = HEX #37
           XBee.write(55); // DEC 55 = HEX #37
    }
  }
  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    Serial.write(XBee.read());
  }
}
</syntaxhighlight>
= XBee - MPPT Test to send Battery Voltage data using XBee =
<syntaxhighlight lang="c++">
/*****************************************************************
XBee_Serial_Passthrough.ino
Set up a software serial port to pass data between an XBee Shield
and the serial monitor.
Hardware Hookup:
  The XBee Shield makes all of the connections you'll need
  between Arduino and XBee. If you have the shield make
  sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
  the XBee's DOUT and DIN pins to Arduino pins 2 and 3.
*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
//For Atmega328P's
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
SoftwareSerial mySerial(7, 8); // RX, TX
String label, val;
char char_array[10]; // for data from MPPT to XBee
void setup()
{
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  XBee.begin(9600);
  mySerial.begin(19200); // baud rate for MPPT is 19200
  Serial.begin(9600);
}
void loop()
{
  if (Serial.available())
  { // If data comes in from serial monitor, send it out to XBee
    XBee.write(Serial.read());
  }
  if (mySerial.available())
  { // If data comes in from serial monitor, send it out to XBee
    //XBee.write(mySerial.read());
    label = mySerial.readStringUntil('\t');     
    val = mySerial.readStringUntil('\r\r\n');
    if (label =="V"){
          //XBee.write(55); // DEC 55 = HEX #37
          int str_len = val.length() + 1;
          val.toCharArray(char_array, str_len);
          XBee.write(char_array);
     }
     }
   }
   }

Revision as of 23:22, 7 July 2023

Reading Victron MPPT Data

References

Parts Required

  • Victron BlueSolar MPPT 75/15 Retail SCC010015050R - $135 (Note that this unit is not Bluetooth enabled) [1]
  • JST Jumper 4 Wire Assembly - $2.75 [2]
  • Arduino Uno

Voltage considerations for different Victron hardware

  • Victron MPPT operates at 5V.
  • Arduino Uno also operates at 5V so no digital converter required.

VE.Direct Pinout

Serial Port Configuration - VE.Direct

Fritzing Circuit Diagram

Photos of Circuit


Arduino Code - Image

Serial Monitor - Example Output

Arduino Code - Code

/* Connections:
    MPPT pin     MPPT        Arduino     Arduino pin
    1            GND         GND         GND
    2            RX          TX          -              do not use!
    3            TX          RX          7 (UNO)
    4            Power+      none        -              do not use!
 */

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX

String label, val;

void setup()  
{
  Serial.begin(9600);
  mySerial.begin(19200);
} 

void loop() 
{
  if (mySerial.available())
   {
        label = mySerial.readStringUntil('\t');      
        val = mySerial.readStringUntil('\r\r\n');
        Serial.println(label + val);
   } 
}

Arduino Code - Code - Reading Battery Voltage - V

/* Connections:
    MPPT pin     MPPT        Arduino     Arduino pin
    1            GND         GND         GND
    2            RX          TX          -              do not use!
    3            TX          RX          7 (UNO)
    4            Power+      none        -              do not use!
 */

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX

String label, val;

void setup()  
{
  Serial.begin(9600);
  mySerial.begin(19200); // baud rate for MPPT
} 

void loop() 
{
  if (mySerial.available())
   {
        label = mySerial.readStringUntil('\t');      
        val = mySerial.readStringUntil('\r\r\n');
        // V = Battery voltage (mV)
        // VPV = Solar Panel voltage (mV)
        // PPV = Solar panel power (W)
        // I = Battery current (mA)
        // IL = Load Current (mA)
        if (label == "V"){
           Serial.println(label + val);
        }
   } 
}


Arduino Code - Code - Reading other Parameters from MPPT

/* Connections:
    MPPT pin     MPPT        Arduino     Arduino pin
    1            GND         GND         GND
    2            RX          TX          -              do not use!
    3            TX          RX          7 (UNO)
    4            Power+      none        -              do not use!
 */

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX

String label, val;

void setup()  
{
  Serial.begin(9600);
  mySerial.begin(19200); // baud rate for MPPT
} 

void loop() 
{
  if (mySerial.available())
   {
        label = mySerial.readStringUntil('\t');      
        val = mySerial.readStringUntil('\r\r\n');
        // V = Battery voltage (mV)
        // VPV = Solar Panel voltage (mV)
        // PPV = Solar panel power (W)
        // I = Battery current (mA)
        // IL = Load Current (mA)
        if (label == "V"){
           Serial.println(label + val);  // Battery Voltage
        }
        
        if (label == "VPV"){
          Serial.println(label + val); // Solar Panel Voltage
        }

        if (label == "PPV"){
          Serial.println(label + val); // Solar Panel Power (Watts)
        }
   } 
}

XBee Test - with MPPT

  • Noticed that as soon as Software Serial added for MPPT communication is only one way from Arduino MPPT to XBee receiver for Pi.
/*****************************************************************
XBee_Serial_Passthrough.ino

Set up a software serial port to pass data between an XBee Shield
and the serial monitor.

Hardware Hookup:
  The XBee Shield makes all of the connections you'll need
  between Arduino and XBee. If you have the shield make
  sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
  the XBee's DOUT and DIN pins to Arduino pins 2 and 3.

*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>

//For Atmega328P's
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
SoftwareSerial mySerial(7, 8); // RX, TX

String label, val;

void setup()
{
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  XBee.begin(9600);
  mySerial.begin(19200); // baud rate for MPPT is 19200
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())
  { // If data comes in from serial monitor, send it out to XBee
    XBee.write(Serial.read());
  }
  if (mySerial.available())
  { // If data comes in from serial monitor, send it out to XBee
    //XBee.write(mySerial.read());
     label = mySerial.readStringUntil('\t');      
     val = mySerial.readStringUntil('\r\r\n');
     if (label =="V"){
          XBee.write(55); // DEC 55 = HEX #37
     }
  }

  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    Serial.write(XBee.read());
  }
}


XBee - MPPT Test to send Battery Voltage data using XBee

/*****************************************************************
XBee_Serial_Passthrough.ino

Set up a software serial port to pass data between an XBee Shield
and the serial monitor.

Hardware Hookup:
  The XBee Shield makes all of the connections you'll need
  between Arduino and XBee. If you have the shield make
  sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
  the XBee's DOUT and DIN pins to Arduino pins 2 and 3.

*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>

//For Atmega328P's
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
SoftwareSerial mySerial(7, 8); // RX, TX

String label, val;
char char_array[10]; // for data from MPPT to XBee

void setup()
{
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  XBee.begin(9600);
  mySerial.begin(19200); // baud rate for MPPT is 19200
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())
  { // If data comes in from serial monitor, send it out to XBee
    XBee.write(Serial.read());
  }
  if (mySerial.available())
  { // If data comes in from serial monitor, send it out to XBee
    //XBee.write(mySerial.read());
     label = mySerial.readStringUntil('\t');      
     val = mySerial.readStringUntil('\r\r\n');
     if (label =="V"){
          //XBee.write(55); // DEC 55 = HEX #37
          int str_len = val.length() + 1; 
          val.toCharArray(char_array, str_len);
          XBee.write(char_array);
     }
  }

  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    Serial.write(XBee.read());
  }
}