Open Tur-Thure opened 3 years ago
I also tried to uncomment the line below, and check with the Arduino serial monitor but could not see any data
// If you want to use simple ascii monitor like Arduino Serial Monitor, uncomment next line // NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.
Below is what I get when I compile. I think it looks ok:
Sketch uses 37684 bytes (7%) of program storage space. Maximum is 524288 bytes. Atmel SMART device 0x285e0a60 found Erase flash done in 0.040 seconds
Write 39904 bytes to flash (156 pages) [==============================] 100% (156/156 pages) done in 7.536 seconds
Verify 39904 bytes of flash [==============================] 100% (156/156 pages) Verify successful done in 4.224 seconds Set boot flash true CPU reset.
Below is the sketch I complied
// Demo: NMEA2000 library. Send main cabin temperature to the bus.
// List here messages your device will transmit. const unsigned long TransmitMessages[] PROGMEM={130310L,130311L,130312L,0};
void setup() {
// Set Product information
NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
100, // Manufacturer's product code
"Simple temp monitor", // Manufacturer's Model ID
"1.1.0.21 (2016-12-31)", // Manufacturer's Software version code
"1.1.0.0 (2016-12-31)" // Manufacturer's Model version
);
// Set device information
NMEA2000.SetDeviceInformation(112233, // Unique number. Use e.g. Serial number.
130, // Device function=Temperature. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
75, // Device class=Sensor Communication Interface. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
2040 // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf
);
// Uncomment 2 rows below to see, what device will send to bus. Use e.g. OpenSkipper or Actisense NMEA Reader
Serial.begin(115200);
NMEA2000.SetForwardStream(&Serial);
// If you want to use simple ascii monitor like Arduino Serial Monitor, uncomment next line
// NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.
// If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below // NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,22); //NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega //NMEA2000.EnableForward(false); // Disable all msg forwarding to USB (=Serial) // Here we tell library, which PGNs we transmit NMEA2000.ExtendTransmitMessages(TransmitMessages); NMEA2000.Open(); }
void loop() { SendN2kTemperature(); NMEA2000.ParseMessages(); }
double ReadCabinTemp() { return CToKelvin(22.5); // Read here the true temperature e.g. from analog input }
double ReadWaterTemp() { return CToKelvin(15.5); // Read here the true temperature e.g. from analog input }
void SendN2kTemperature() { static unsigned long TempUpdated=millis(); tN2kMsg N2kMsg;
if ( TempUpdated+TempUpdatePeriod<millis() ) { TempUpdated=millis(); SetN2kTemperature(N2kMsg, 1, 1, N2kts_MainCabinTemperature, ReadCabinTemp()); NMEA2000.SendMsg(N2kMsg); SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_MainCabinTemperature, ReadCabinTemp()); NMEA2000.SendMsg(N2kMsg); SetN2kOutsideEnvironmentalParameters(N2kMsg, 1, ReadWaterTemp()); NMEA2000.SendMsg(N2kMsg); Serial.print(millis()); Serial.println(", Temperature send ready"); } }
// If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below So uncomment and modify line NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,22);
I Only have the PC and the Arduino Due connected. I uncomment and changed the line as follows:
// If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,22); //NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega //NMEA2000.EnableForward(false); // Disable all msg forwarding to USB (=Serial) // Here we tell library, which PGNs we transmit NMEA2000.ExtendTransmitMessages(TransmitMessages); NMEA2000.Open();
Still no data in NMEA reader and no data in IDE serial monitor with
// If you want to use simple ascii monitor like Arduino Serial Monitor, uncomment next line NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.
Some progress. :) I connected to arduino native port and uploaded the sketch. then I moved the physical USB - cable to the programming port and now I get some data. Should native port be used for flashing? How do I know if serial data is sent on native port or programming port?
Check from DUE documentation. If I remember right native port is SerialUSB and programming port is Serial.
Hi I successfulle uploaded the TemperatureMonitor example after chaning to:
Serial.begin(115200); NMEA2000.SetForwardStream(&Serial);
and
//NMEA2000.EnableForward(false);
I downloaded NMEA reader according to instructions and get the attached error messages timeout and can't see any data. I tried both with the old and the new version. I selected the same com port in NMEA reader as in IDE. The Serial has not been opend in IDE.
What can be wrong?