using serial communication
My control board is arduino mega pro based
the Monitor doesn't receive any data from arduino mega pro USB cable, Therefore the Gauge and other controls doesn't respond
but by using exactly the same code on arduino Uno it works well, the monitor receives serial data and the Gauge responds.
Is there any additional configurations i should use with arduino mega pro ???
I attached my board photo and the progect photo
This is my code
Code: Select all
#include "MegunoLink.h" // Helpful functions for communicating with MegunoLink Pro.
const int flowSensorPin = 3; // The pin the sensor is connected to
volatile int pulseCount = 0; // Counter for pulses
float flowRate = 0.0; // Calculated flow rate
unsigned long lastMillis = 0; // Time of last reading
const float calibrationFactor = 7.5; // Sensor specific calibration factor (pulses per liter)
void SendToIPGauge1(float vv)
{
InterfacePanel MyPanel;
// Set control value
MyPanel.SetNumber(F("IPGauge1"), vv);
}
void setup()
{
Serial.begin(9600);
pinMode(flowSensorPin, INPUT_PULLUP); // Set the sensor pin as input with internal pull-up resistor
attachInterrupt(digitalPinToInterrupt(flowSensorPin), flowSensorISR, RISING); // Interrupt on rising edge
}
void loop()
{
// Calculate flow rate every second
if (millis() - lastMillis >= 100) {
noInterrupts(); // Disable interrupts during calculation
flowRate = ((1000.0 / (millis() - lastMillis)) * pulseCount) / calibrationFactor;
lastMillis = millis();
pulseCount = 0; // Reset pulse count
interrupts(); // Re-enable interrupts
Serial.print("Flow Rate: ");
Serial.print(flowRate);
Serial.println(" L/min");
//SendToIPGauge1(flowRate);
MyPanel.SetNumber(F("IPGauge1"), flowRate);
}
}
// Interrupt Service Routine (ISR)
void flowSensorISR() {
pulseCount++;
}