Sensor_DataLog_Terminal

Description

In this example is shown how to use the CoreSensor library and to manage the Sensors onboard of  Arduino Primo Core.

Hardware

Circuit

primoCore.jpg

Connect the Arduino Primo Core to the Arduino Primo using the SWD connector for uploading the sketch.

IMG_20170525_180159.jpg

For more information, about how to upload a sketch, visit the Getting Started.

Code

The sketch calculates the values of Humidity, Temperature, Accelerometer and Gyroscope.
Furthermore turn on the RGB Led.

Upload the code below.

Warning:
Use the Arduino IDE 1.8.x and check that you have already downloaded the latest platform of Arduino NRF52 from the Board Manager.

/*
Sensors_DataLog_Terminal.ino

Written by Jeff Wu (jeff@arduino.org)

This example for the Arduino Primo Core shows how to use
CoreSensors library.
Gatting data from Humidity, Temperature, Accelerometer
and Gyroscope sensors.

This example code is in the public domain.

*/

#include <CoreSensors.h>

void setup() {
// Led.
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

// Initialize serial for output.
Serial.begin(115200);
coresensors.begin();
}


void loop() {
char report[256];
float humidity, temperature;
int32_t accelerometers[3];
int32_t gyroscope[3];

humidity = coresensors.getHumidity();

temperature = coresensors.getTemperature();

coresensors.getAccelerometer(accelerometers);

coresensors.getGyroscope(gyroscope);

Serial.print("| Hum[%]: ");
Serial.print(humidity);
Serial.print(" | Temp[C]: ");
Serial.print(temperature);
Serial.print(" ");

snprintf(report, sizeof(report), "| Acc[mg]: %6ld %6ld %6ld | Gyr[mdps]: %8ld %8ld %8ld |", accelerometers[0], accelerometers[1], accelerometers[2], gyroscope[0], gyroscope[1], gyroscope[2]);

Serial.println(report);
Serial.println();

digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
delay(100);
digitalWrite(11, HIGH);
delay(100);
digitalWrite(11, LOW);
delay(100);
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}


Output

Uploaded the sketch on Arduino Primo Core, follow the below steps to see the output on a Serial Monitor.

  • Disconnect Arduino Primo Core from Primo;
  • Power the Arduino Primo Core using the Coin battery CR2032;
  • Upload on Arduino Primo board the code below:

void setup() {
// initialize Serial port at the same speed your data are sent from the Primo Core
Serial.begin(115200);
}

void loop() {
// look for available data
if(Serial.available()){
// if a data is present, print it on serial monitor
Serial.write(Serial.read());
}
}

This code allows to print on Serial Monitor all data received from Arduino Primo on RX pin.

  • Now connect the RX pin of the Arduino Primo Core with the RX pin of Arduino Primo;

  • Finally open the Serial Monitor and set the baudrate to 115200:

Sensor data output.jpg