Hello,
I am creating my own small library for a project, and I see how the SerialUSB in the SODAQ one seems to get stuck, for now I am only printing certain values to check that everything goes fine, and I see that after load the port sometimes dissapear from Arduino IDE and I don’t get an output in the serial monitor of the IDE.
I have tested as well the code in other platform The Things Uno ( Arduino Leonardo) and it does work fine there.
Any hint?
Thanks in advance!
EDIT: I have noticed that my SODAQ ONE is listed as Arduino Zero under devices, is this normal?
My .ino
> #include "myLib.h"
> int printArray(int idx, int l, unsigned char a[]) {
> for (int i = idx; i < l; i++) {
> SerialUSB.print("Index:" + String(i + idx) + " :");
> SerialUSB.print(a[i], DEC);
> SerialUSB.println(" , ");
> SerialUSB.write(a[i]);
> SerialUSB.println();
> }
> }
> myClass* pp = new myClass();
> void setup() {
> SerialUSB.println("STARTING");
> SerialUSB.begin(115200);
> while ((!SerialUSB) && (millis() < 30000)) {
> // Wait for SerialUSB or start after 30 seconds
> }
> pp->data.battery = 20;
> // SerialUSB.println(pp->data.battery,DEC);
> pp->data.counter = 10;
> // SerialUSB.println(pp->data.counter,DEC);
> pp->data.sw = 30;
> // SerialUSB.println(pp->data.sw,DEC);
> pp->data.sensor->light = 101;
> // SerialUSB.println(pp->data.sensor->light,DEC);
> pp->data.sensor->humidity = 102;
> pp->data.sensor->pressure = 103;
> // SerialUSB.println(pp->data.sensor->pressure,DEC);
> pp->data.sensor->temperature = 104;
> // SerialUSB.println(pp->data.sensor->temperature,DEC);
> pp->data.sensor->ultraViolet = 105;
> // SerialUSB.println(pp->data.sensor->ultraViolet,DEC);
> pp->data.acc->x = 106;
> // SerialUSB.println(pp->data.acc->x,DEC);
> pp->data.acc->y = 107;
> // SerialUSB.println(pp->data.acc->y,DEC);
> pp->data.acc->z = 108;
> // SerialUSB.println(pp->data.acc->z,DEC);
> // pp->data.nb = 109;
> pp->createPayload(myClass::POSITION);
> }
> void loop() {
> SerialUSB.println("testing!");
> delay(3000);
> //----------
> if (pp->isPayloadEmpty(pp->payloadPosition, 0,pp->payloadLengths.lenPosition))
> SerialUSB.println("POSITION It's empty!");
> else
> SerialUSB.println("NOT empty! size"+String(pp->payloadLengths.lenPosition+pp->payloadLengths.lenHeader));
>
> printArray(0,pp->payloadLengths.lenPosition+pp->payloadLengths.lenHeader,pp->payloadPosition);
> SerialUSB.println("-------------------------------------------------");
> printArray(0,pp->payloadLengths.lenPosition+pp->payloadLengths.lenHeader,pp->createPayload(myClass::POSITION));
> SerialUSB.println("-----------------------kk--------------------------");
> }
Some insights of “myLib.h”
class myClass {
/*
* Basic structure that store the payloads lengths
* */
typedef struct payloadLenghts {
/*
* Basic structure to store data from an accelerometer
* */
struct accelerometerSensor {
} m_tacc;
struct basicSensor {
} m_tsensor;
public:
/*
* Struct to check payloadLengths
* */
payloadLenghts payloadLengths;
/* Enumeration of all the kind of myClass payloads
* */
enum myClassPayload { NONE, LOCATION
};
struct completeDatamyClass {
basicSensor* sensor;
accelerometerSensor* acc;
} data;
//Defining the lenght of our payload
unsigned char payloadLocation[LEN_HEADER + LEN_LOCATION];
/*
* Constructor that initializes the messages to be used in myClass
* */
myClass();
virtual ~myClass();
/*
* Function that initializes the payload variable according to the kind of myClass payload that is defined by
* the variable @messageType giving a different kind of Payload will initialize the payload vector as the desired payload
* */
unsigned char* createPayload(myClassPayload messageType);
/**
* Function that checks whether the payload is empty or not,from the index indx till the value maxLength,
* if the payload is empty that means that likely one of the payload elements was not assigned
*/
bool isPayloadEmpty(unsigned char payload[],uint8_t indx,uint8_t length);
};
//extern myClass frame;
#endif /* myClass_H_ */
myClass.cpp
/*
* Constructor that initializes the messages to be used
* */
myClass::myClass() {
memset(payloadPosition,EMPTY,LEN_HEADER + LEN_POSITION);
basicSensor* sensor = &m_tsensor ;
accelerometerSensor* acc = &m_tacc ;
}
myClass::~myClass() {
if (data.sensor != NULL)
delete data.sensor;
if(data.acc !=NULL)
delete data.acc;
}