jimmie
Junior Member

Posts: 86
|
Post by jimmie on Jul 9, 2019 1:37:41 GMT
I am converting a statement from an Arduino library so I can use it on the ShieldBuddy.
The original statement uses "Serial", I want to use "Serial1" instead.
Here is the original statement:
Leddar16( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial& Port = Serial, unsigned char Pin = 0, unsigned char Action = 0) : BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action) , SerialPort(Port) { }
when I convert it to:
Leddar16( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial& Port = Serial1, unsigned char Pin = 0, unsigned char Action = 0) : BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action) , SerialPort(Port) { }
private: unsigned long BaudRate; unsigned char SlaveAddress; unsigned char TxEn_Pin; unsigned char TxEn_Action; HardwareSerial& SerialPort;
I get the following compile error:
could not convert 'Serial1' from 'SerialClass2' to 'SerialClassRXTx&'
How can this error be fixed?
Thanks in advance to the community for their input.
|
|
|
Post by Admin on Jul 9, 2019 7:30:48 GMT
You could try:
Leddar16( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial1& Port = Serial1, unsigned char Pin = 0, unsigned char Action = 0) : BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action) , SerialPort(Port) { }
private: unsigned long BaudRate; unsigned char SlaveAddress; unsigned char TxEn_Pin; unsigned char TxEn_Action; HardwareSerial1& SerialPort;
|
|
jimmie
Junior Member

Posts: 86
|
Post by jimmie on Jul 9, 2019 8:18:41 GMT
Thank you.
I tried it but getting the compile error:
'HardwareSerial1' has not been declared.
======================
I also forgot to mention that my modified code above compiles fine with an Arduino Mega so it must have to do with the ShieldBuddy implementation.
|
|
|
Post by Admin on Jul 9, 2019 8:55:57 GMT
HardwareSerial1 is declared in variant.h so this is odd. Please send a small sketch that shows the problem so that we can find out what is going on.
|
|
jimmie
Junior Member

Posts: 86
|
Post by jimmie on Jul 9, 2019 9:35:07 GMT
Thank you very much, I appreciate the help.
Please see the attached code. This code works with "Serial" but I am trying to connect to "Serial1" and "Serial0" as I will need to connect sensors to each serial port.
Attachments:Leddar_SB.zip (4.86 KB)
|
|
|
Post by Admin on Jul 9, 2019 9:45:04 GMT
This seems to compile and link: Leddar_SB.h (3.11 KB) We cannot test that it runs though!
|
|
jimmie
Junior Member

Posts: 86
|
Post by jimmie on Jul 9, 2019 9:53:08 GMT
Thank you again.
It gives the same error "'HardwareSerial1' has not been declared." Please see attached.
I am using the latest Arduino (1.8.9) and selected Board "ShieldBuddyTC275_Dx"
Attachments:
|
|
|
Post by Admin on Jul 9, 2019 9:58:11 GMT
Please try this: Leddar_SB.h (3.11 KB) Something strange is happening with the Arduino IDE. The definition of HardwareSerial1 seems to go missing so it is now in the Leddar_SB.h file.
|
|
jimmie
Junior Member

Posts: 86
|
Post by jimmie on Jul 9, 2019 10:07:47 GMT
Thank you very much.
This did work. I appreciate your time in helping me resolve this pesky issue.
======================================================================
If I may bother you with one last question as I am new to multi-core programming. Since I will be using all three serial ports, how can I have the selected serial port as a variable so I can use the same library for Serial, Serial0 and Serial1?
Thanks again for all your help.
|
|
jimmie
Junior Member

Posts: 86
|
Post by jimmie on Nov 8, 2019 2:30:24 GMT
Please try this: Something strange is happening with the Arduino IDE. The definition of HardwareSerial1 seems to go missing so it is now in the Leddar_SB.h file. Hello:
Do I still need to include the statement below in the .h file:
#define HardwareSerial SerialClass2
This is very problematic in my application as I need to instantiate three instances each connected to a different serial port. I am using the attached library.
If I use the following statement, I get a compile error (Leddar1 cannot be used as a function):
Leddar16 Leddar1[3] = {Leddar1(115200,1,Serial0), Leddar1(115200,1,Serial1), Leddar1(115200,1,Serial)};
I would really appreciate any help as this has been a serious problem that is preventing me from using the board. I have already purchased three SB boards and hope to get many more but it is all contingent on being able to solve this programming problem which is ShieldBuddy specific.
Attachments:ArduinoLeddar.zip (13.36 KB)
|
|
|
Post by Admin on Nov 8, 2019 10:12:23 GMT
|
|
|
Post by Admin on Nov 12, 2019 14:34:26 GMT
This now works with some changes to the Leddar1 declaration. The latest ShieldBuddy add-in is required. This can be found at: www.hitex.co.uk/fileadmin/uk-files/downloads/ShieldBuddy/ShieldBuddyMulticoreIDE.zipPassword "ShieldBuddy". This compiles and links: #include <Leddar.h> unsigned int Distance[3]; unsigned int Amplitude[3]; Leddar16 Leddar1[3] = { { 115200,1,Serial0 }, { 115200,1,Serial1 }, { 115200,1,Serial }}; /*** Core 0 ***/ void setup() { // put your setup code for core 0 here, to run once: Leddar1[0].init(); Leddar1[1].init(); Leddar1[2].init(); } void loop() { // put your main code for core 0 here, to run repeatedly: Distance[0] = Leddar1[0].Detections[0].Distance; Amplitude[0] = Leddar1[0].Detections[0].Amplitude; }
|
|