You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get two sensors to read simultaneously and Arduino seems to have an issue as soon as there are multiples of the same sensors plugged in.
Both sensors use the same PGN numbers for different parameters being read but when multiple sensors are plugged in they reassign the source address based on the address claim "Name".
We determined what the address claim was for each sensor and used that as an integer value for Name1, Name2.
The code then masks and filters the PGN and address claim which are supposed to be used to determine which sensor is sending out the specific signal.
So far we have only been trying to get the temperature signal functioning so the lines including viscosity, density, dielectric and resistivity are all commented out.
Is there a proper way to be reading these signals at the same time? Thanks
`
// Arduino Due - Displays all traffic found on either canbus port
// By Thibaut Viard/Wilfredo Molina/Collin Kidder 2013-2014
// Initialize the LCD object, set the LCD I2C address to 0x27 for a 20x4 display
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Leave defined if you use native port, comment if using programming port
//This sketch could provide a lot of traffic so it might be best to use the
//native port
/* The timing for heater cycle is based on the blink without delay
program written by David A. Mellis.
If this needs to be referenced it can be found in UNO IDE
Examples -> Digital -> Blink without delay
or https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay
*/
#define Serial SerialUSB
unsigned int tempint = 0;
unsigned int viscint = 0;
unsigned int densint = 0;
unsigned int dielint = 0;
unsigned int Rpint = 0;
unsigned int Name = 0;
unsigned int Name1 = 534775405;
unsigned int Name2 = 534775403;
unsigned int PGN =0;
unsigned int Address =0;
unsigned int Address1 =0;
unsigned int Address2 =0;
float temp = 0;
float visc = 0;
float dens = 0;
float diel = 0;
float Rp = 0;
// Initialize CAN0 and CAN1, Set the proper baud rates here
Can0.begin(CAN_BPS_250K);
Can1.begin(CAN_BPS_250K);
//By default there are 7 mailboxes for each device that are RX boxes
//This sets each mailbox to have an open filter that will accept extended
//or standard frames
int filter;
//extended
for (filter = 0; filter < 3; filter++) {
Can0.setRXFilter(filter, 0, 0, true);
Can1.setRXFilter(filter, 0, 0, true);
}
//standard
for (int filter = 3; filter < 7; filter++) {
Can0.setRXFilter(filter, 0, 0, false);
Can1.setRXFilter(filter, 0, 0, false);
}
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
// Set cursor to the top left corner and print the string on the first row
lcd.setCursor(0, 0);
lcd.print("Oil Property Sensor ");
// Move to the second row and print the string
lcd.setCursor(0, 1);
lcd.print(" Ascentek ");
// Move to the third row and print the string
lcd.setCursor(0, 2);
lcd.print("Please wait while I ");
// Move to the fourth row and print the string
lcd.setCursor(0, 3);
lcd.print("access that data... ");
I am trying to get two sensors to read simultaneously and Arduino seems to have an issue as soon as there are multiples of the same sensors plugged in.
Both sensors use the same PGN numbers for different parameters being read but when multiple sensors are plugged in they reassign the source address based on the address claim "Name".
We determined what the address claim was for each sensor and used that as an integer value for Name1, Name2.
The code then masks and filters the PGN and address claim which are supposed to be used to determine which sensor is sending out the specific signal.
So far we have only been trying to get the temperature signal functioning so the lines including viscosity, density, dielectric and resistivity are all commented out.
Is there a proper way to be reading these signals at the same time? Thanks
`
// Arduino Due - Displays all traffic found on either canbus port
// By Thibaut Viard/Wilfredo Molina/Collin Kidder 2013-2014
// Required libraries
#include "variant.h"
#include <due_can.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
// Initialize the LCD object, set the LCD I2C address to 0x27 for a 20x4 display
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Leave defined if you use native port, comment if using programming port
//This sketch could provide a lot of traffic so it might be best to use the
//native port
/* The timing for heater cycle is based on the blink without delay
program written by David A. Mellis.
If this needs to be referenced it can be found in UNO IDE
Examples -> Digital -> Blink without delay
or https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay
*/
#define Serial SerialUSB
unsigned int tempint = 0;
unsigned int viscint = 0;
unsigned int densint = 0;
unsigned int dielint = 0;
unsigned int Rpint = 0;
unsigned int Name = 0;
unsigned int Name1 = 534775405;
unsigned int Name2 = 534775403;
unsigned int PGN =0;
unsigned int Address =0;
unsigned int Address1 =0;
unsigned int Address2 =0;
float temp = 0;
float visc = 0;
float dens = 0;
float diel = 0;
float Rp = 0;
float temp1 = 0;
float visc1 = 0;
float dens1 = 0;
float diel1 = 0;
float Rp1 = 0;
float temp2 = 0;
float visc2 = 0;
float dens2 = 0;
float diel2 = 0;
float Rp2 = 0;
int Heater = 10;
int TempSP = 45;
void setup()
{
Serial.begin(115200);
// Initialize CAN0 and CAN1, Set the proper baud rates here
Can0.begin(CAN_BPS_250K);
Can1.begin(CAN_BPS_250K);
//By default there are 7 mailboxes for each device that are RX boxes
//This sets each mailbox to have an open filter that will accept extended
//or standard frames
int filter;
//extended
for (filter = 0; filter < 3; filter++) {
Can0.setRXFilter(filter, 0, 0, true);
Can1.setRXFilter(filter, 0, 0, true);
}
//standard
for (int filter = 3; filter < 7; filter++) {
Can0.setRXFilter(filter, 0, 0, false);
Can1.setRXFilter(filter, 0, 0, false);
}
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
// Set cursor to the top left corner and print the string on the first row
lcd.setCursor(0, 0);
lcd.print("Oil Property Sensor ");
// Move to the second row and print the string
lcd.setCursor(0, 1);
lcd.print(" Ascentek ");
// Move to the third row and print the string
lcd.setCursor(0, 2);
lcd.print("Please wait while I ");
// Move to the fourth row and print the string
lcd.setCursor(0, 3);
lcd.print("access that data... ");
pinMode(10, OUTPUT); //Heat controller Relay output pin
}
void processFrame(CAN_FRAME &frame) {
// shift HEX ID two digits ">>8"
// mask to find last two HEX address "& 0x000000FF"
//
Address = (frame.id & 0X000000FF);
PGN = ((frame.id >>8) & 0x00FFFF);
}
}
}
}
*/
}
void printFrame(CAN_FRAME &frame) {
// Serial.print("ID: 0x");
//Serial.print(frame.id, HEX);
//Serial.print(" Len: ");
//Serial.print(frame.length);
//Serial.print(" Data: 0x");
for (int count = 0; count < frame.length; count++) {
Serial.print(frame.data.bytes[count], DEC);
Serial.print(" ");
}
Serial.println(" ");
Serial.print("PGN is:");
Serial.println(PGN,HEX);
// Serial.print("Name is:");
//Serial.println(Name1);
//Serial.println(Name2);
Serial.print("Temp1: ");
Serial.println(temp1);
Serial.print("Temp2: ");
Serial.println(temp2);
Serial.print("Address: ");
Serial.println(Address,HEX);
Serial.print("Address1: ");
Serial.println(Address1,HEX);
Serial.print("Address2: ");
Serial.println(Address2,HEX);
/* if (PGN == 0x18FEEE) {
//Serial.print("tempint ");
//Serial.println(tempint);
if (Address == Address1){
Serial.print("temp1 ");
Serial.println(temp1, 1);
}
if (Address == Address2){
Serial.print("temp2 ");
Serial.println(temp2, 1);
}
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.setCursor(6, 0);
lcd.print(temp, 1);
}
if (PGN == 0x1CFD08) {
//Serial.print("viscint ");
//Serial.println(viscint);
if (Address == Address1){
Serial.print("visc1 ");
Serial.println(visc1, 1);
Serial.print("dens1 ");
Serial.println(dens1, 4);
Serial.print("diel1 ");
Serial.println(diel, 4);
}
if (Address == Address2){
Serial.print("visc2 ");
Serial.println(visc2, 1);
Serial.print("dens2 ");
Serial.println(dens2, 4);
Serial.print("diel2 ");
Serial.println(diel2, 4);
}
lcd.setCursor(0, 1);
lcd.print("Viscosity: ");
lcd.setCursor(11, 1);
lcd.print(visc, 2);
//Serial.print("densint ");
//Serial.println(densint);
lcd.setCursor(0, 2);
lcd.print("Density: ");
lcd.setCursor(9, 2);
lcd.print(dens, 4);
//Serial.print("dielint ");
//Serial.println(dielint);
lcd.setCursor(0, 3);
lcd.print("Dielectric: ");
lcd.setCursor(12, 3);
lcd.print(diel, 4);
}
if (PGN == 0x18EEFF) {
Serial.print("Name: ");
Serial.println(Name);
Serial.print("ID: 0x");
Serial.println(frame.id, HEX);
Serial.print("\r\n");
if (PGN == 0x1CFA67) {
if (Address == Address1){
Serial.print("Rp1 ");
Serial.println(Rp1);
}
if (Address == Address2){
Serial.print("Rp2 ");
Serial.println(Rp2);
}
lcd.setCursor(11, 0);
lcd.print("Rp: ");
lcd.setCursor(15, 0);
lcd.print(Rp,1);
Serial.print("\r\n");
}
}
*/
}
void loop() {
unsigned long currentMillis = millis();
CAN_FRAME incoming;
if (Can0.available() > 0) {
Can0.read(incoming);
processFrame(incoming);
printFrame(incoming);
}
if (Can1.available() > 0) {
Can1.read(incoming);
processFrame(incoming);
printFrame(incoming);
}
}
else {
digitalWrite(10,LOW);
}
}
`
The text was updated successfully, but these errors were encountered: