Hi,
I’m using an Adafruit Feather M0 Adalogger on my NOTECARRIER-F V1.0. Currently, I’m using a very simple code based on the examples but can’t make a serial connection to send the data to the blues notehub. When I’m using the I2C interface, everything is working and I can see the data in the notehub. However, when I’m using the serial by uncommenting the line “#define txRxPinsSerial Serial1” I get “notecard not responding” in the ArduinoIDE serial and no data in the notehub. I feel like I’m missing something basic, but not sure what it is.
Thank you,
Elad.
#include <Notecard.h>
#define txRxPinsSerial Serial1
#define usbSerial Serial#ifndef PRODUCT_UID
#define PRODUCT_UID “…” //in the code I uploaded, I inserted my UID - it worked with I2C communication but not with serial
#endif#define myProductID PRODUCT_UID
Notecard notecard;void setup()
{
// Set up for debug output (if available).
#ifdef usbSerial
// If you open Arduino’s serial terminal window, you’ll be able to watch
// JSON objects being transferred to and from the Notecard for each request.
usbSerial.begin(115200);
const size_t usb_timeout_ms = 3000;
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
;
notecard.setDebugOutputStream(usbSerial);
#endif// Initialize the physical I/O channel to the Notecard
#ifdef txRxPinsSerial
notecard.begin(txRxPinsSerial, 9600);
#else
notecard.begin();
#endif// "newRequest()" uses the bundled "J" json package to allocate a "req", // which is a JSON object for the request to which we will then add Request // arguments. The function allocates a "req" request structure using // malloc() and initializes its "req" field with the type of request. J *req = notecard.newRequest("hub.set"); // This command (required) causes the data to be delivered to the Project // on notehub.io that has claimed this Product ID (see above). if (myProductID[0]) { JAddStringToObject(req, "product", myProductID); } // This command determines how often the Notecard connects to the service. // If "continuous", the Notecard immediately establishes a session with the // service at notehub.io, and keeps it active continuously. Due to the power // requirements of a continuous connection, a battery powered device would // instead only sample its sensors occasionally, and would only upload to // the service on a "periodic" basis. JAddStringToObject(req, "mode", "continuous"); // Issue the request, telling the Notecard how and how often to access the // service. // This results in a JSON message to Notecard formatted like: // { // "req" : "service.set", // "product" : myProductID, // "mode" : "continuous" // } // Note that `notecard.sendRequestWithRetry()` always frees the request data // structure, and it returns "true" if success or "false" if there is any // failure. It is important to use `sendRequestWithRetry()` on the first // message from the MCU to the Notecard, because there will always be a // hardware race condition on cold boot and the Notecard must be ready to // receive and process the message. notecard.sendRequestWithRetry(req, 5); // 5 seconds
}
void loop()
{// Count the simulated measurements that we send to the cloud, and stop the // demo before long. static unsigned eventCounter = 0; if (++eventCounter > 25) { return; } // Rather than simulating a temperature reading, use a Notecard request to // read the temp from the Notecard's built-in temperature sensor. We use // `requestAndResponse()` to indicate that we would like to examine the // response of the transaction. This method takes a JSON data structure, // "request" as input, then processes it and returns a JSON data structure, // "response", with the response. Note that because the Notecard library // uses malloc(), developers must always check for `NULL` to ensure that // there was enough memory available on the microcontroller to satisfy the // allocation request. double temperature = 0; J *rsp = notecard.requestAndResponse(notecard.newRequest("card.temp")); if (rsp != NULL) { temperature = JGetNumber(rsp, "value"); notecard.deleteResponse(rsp); } // Do the same to retrieve the voltage that is detected by the Notecard on // its `V+` pin. double voltage = 0; rsp = notecard.requestAndResponse(notecard.newRequest("card.voltage")); if (rsp != NULL) { voltage = JGetNumber(rsp, "value"); notecard.deleteResponse(rsp); } // Enqueue the measurement to the Notecard for transmission to the Notehub, // adding the "sync" flag for demonstration purposes to upload the data // instantaneously. If you are looking at this on notehub.io you will see // the data appearing 'live'. J *req = notecard.newRequest("note.add"); if (req != NULL) { JAddBoolToObject(req, "sync", true); J *body = JAddObjectToObject(req, "body"); if (body != NULL) { JAddNumberToObject(body, "temp", temperature); JAddNumberToObject(body, "voltage", voltage); JAddNumberToObject(body, "count", eventCounter); } notecard.sendRequest(req); } // Delay between samples delay(15 * 1000); // 15 seconds
}