Hi all! I’m doing a project on arduino mega, I have a shield for arduino in which the rpm and speed are transferred to digital pins 2 and 3, how can I specify in the xml file and in the sketch so that realdash can see these values?
Am I writing correctly?
In xml:
<frame id="3200">
<!-- 1st CAN frame, RPM, SPD, CLT, TPS -->
<value targetId="37" units="RPM" offset="0" length="2"></value>
<value targetId="81" units="km/h" offset="2" length="2"></value>
<frame id="3202">
<value name="Arduino Example: Digital 2" offset="0" length="2"></value>
<value name="Arduino Example: Digital 3" offset="2" length="2"></value>
In arduino sketch:
unsigned int digitalPins = 0;
int analogPins[7] = {0};
unsigned int rpm = 0;
unsigned int km/h = 0;
void loop()
{
ReadDigitalStatuses();
ReadAnalogStatuses();
SendCANFramesToSerial();
if (rpm++ > 10000)
{
rpm = 500;
}
if (km/h++ > 2500)
{
km/h = 0;
}
delay(5);
}
void ReadDigitalStatuses()
{
// read status of digital pins (1-53)
digitalPins = 0;
int bitposition = 0;
for (int i=1; i<53; i++)
{
if (digitalRead(i) == HIGH) digitalPins |= (1 << bitposition);
bitposition++;
}
}
void SendCANFramesToSerial()
{
byte buf[8];
memcpy(buf, &rpm, 2);
memcpy(buf + 2, &km/h, 2);