/*
Prototypical arduino/teensy code.
This one sends things as chars, which allows it to be a bit more flexible,
at the cost of efficiency. For example, sending the timestamp + two analog
channels takes 8 bytes in the more efficient code, but ~15 bytes in this code.
Additionally, you would need to parse the string on the other side.
The plus is that the output is human-readable.
*/

#include "ADC.h"
#include "IntervalTimer.h"

// only the lines below needs to change
// first line does which analog channels to read,
// second line sets the sampling interval (in microseconds)
const unsigned int channel_array[2] = {A0, A7};
const unsigned long period_0 = 100000;
const unsigned int array_size = sizeof(channel_array) / sizeof(int);

unsigned int value_array[array_size];
unsigned int ii = 0;
volatile bool go_flag = false;
bool go_flag_copy = false;
elapsedMicros current_time;
unsigned long current_time_copy = 0;
IntervalTimer timer_0;

ADC *adc = new ADC();

void setup() {
  for(ii = 0; ii < array_size; ii++) {
    pinMode(channel_array[ii], INPUT);
  }

  Serial.begin(9600);
  delay(1000);

  adc->setReference(ADC_REF_3V3, ADC_0);
  adc->setAveraging(8);
  adc->setResolution(12);
  adc->setConversionSpeed(ADC_HIGH_SPEED);
  adc->setSamplingSpeed(ADC_HIGH_SPEED);
  timer_0.priority(10);
  timer_0.begin(timerCallback, period_0);
  delay(500);
}

FASTRUN void timerCallback(void) {
  go_flag = true;
}

void loop() {

  while(!go_flag_copy) {
    noInterrupts();
    go_flag_copy = go_flag;
    interrupts();
  }
  go_flag_copy = false;
  go_flag = false;

  current_time_copy = current_time;
  for (ii = 0; ii < array_size; ii++) {
    value_array[ii] = adc->analogRead(channel_array[ii]);
  }

  Serial.print(current_time_copy);
  Serial.print(" ");

  for (ii = 0; ii < array_size; ii++) {
    Serial.print(value_array[ii]);
    Serial.print(" ");
  }
  Serial.print("\n");
}

Add string equivalent example for teensy


// This example demonstrates how to use the HIH61xx class with the Wire library. The HIH61xx state machine
// enables others tasks to run whilst the HIH61xx is powering up etc.

#include <Wire.h>
#include <HIH61xx.h>
#include <AsyncDelay.h>

// The "hih" object must be created with a reference to the "Wire" object which represents the I2C bus it is using.
// Note that the class for the Wire object is called "TwoWire", and must be included in the templated class name.
HIH61xx<TwoWire> hih(Wire);

AsyncDelay samplingInterval;

void setup(void)
{
#if F_CPU >= 12000000UL
    Serial.begin(115200);
#else
	Serial.begin(9600);
#endif

	Wire.begin();

	hih.initialise();
	samplingInterval.start(3000, AsyncDelay::MILLIS);
}

bool printed = true;
void loop(void)
{
	if (samplingInterval.isExpired() && !hih.isSampling()) {
		hih.start();
		printed = false;
		samplingInterval.repeat();
		Serial.println("Sampling started (using Wire library)");
	}

	hih.process();

	if (hih.isFinished() && !printed) {
		printed = true;
		// Print saved values
		Serial.print("RH: ");
		Serial.print(hih.getRelHumidity() / 100.0);
		Serial.println(" %");
		Serial.print("Ambient: ");
		Serial.print(hih.getAmbientTemp() / 100.0);
		Serial.println(" deg C");
		Serial.print("Status: ");
		Serial.println(hih.getStatus());
	}

}

Add demo which uses the Wire library

Add demo which uses the Wire library


#include <SPI.h>
#include <SdFat.h>
#include <FAB_LED.h>

apa106<D, 6>   LEDstrip;
rgb frame[200];

// Test with reduced SPI speed for breadboards.
// Change spiSpeed to SPI_FULL_SPEED for better performance
// Use SPI_QUARTER_SPEED for even slower SPI bus speed
const uint8_t spiSpeed = SPI_FULL_SPEED;

//------------------------------------------------------------------------------
// File system object.
SdFat sd;

// Serial streams
ArduinoOutStream cout(Serial);

// SD card chip select
const int chipSelect = 4;

void setup()
{
  Serial.begin(9600);

  // Wait for USB Serial
  while (!Serial) {
    SysCall::yield();
  }

  cout << F("\nInitializing SD.\n");
  if (!sd.begin(chipSelect, spiSpeed)) {
    if (sd.card()->errorCode()) {
      cout << F("SD initialization failed.\n");
      cout << F("errorCode: ") << hex << showbase;
      cout << int(sd.card()->errorCode());
      cout << F(", errorData: ") << int(sd.card()->errorData());
      cout << dec << noshowbase << endl;
      return;
    }

    cout << F("\nCard successfully initialized.\n");
    if (sd.vol()->fatType() == 0) {
      cout << F("Can't find a valid FAT16/FAT32 partition.\n");
      return;
    }
    if (!sd.vwd()->isOpen()) {
      cout << F("Can't open root directory.\n");
      return;
    }
    cout << F("Can't determine error type\n");
    return;
  }
  cout << F("\nCard successfully initialized.\n");
  cout << endl;

  if (!sd.exists("FRACTAL1.DAT")) {
    cout << F("FRACTAL1.DAT file not found.\n");
    return;
  }

  File infile = sd.open("FRACTAL1.DAT");
  if (!infile.isOpen()) {
    cout << F("Failed to open FRACTAL1.DAT\n");
    return;
  }

  int bytes_read = infile.read(frame, sizeof(frame));
  unsigned long prev_millis = millis();

  cout << F("\nFrame size in bytes: ") << sizeof(frame);
  cout << F("\nStarting millis: ") << prev_millis;
  int i = 0;
  while (bytes_read == sizeof(frame)) {
    ++i;
    while (millis() - prev_millis < 50UL) {
      // busy loop until its time to paint the lights
    }
    prev_millis += 50UL;
    LEDstrip.sendPixels(sizeof(frame) / sizeof(*frame), frame);
    bytes_read = infile.read(frame, sizeof(frame));
  }
  cout << F("\nFinal millis: ") << prev_millis;
  cout << F("\nNum frames: ") << i;
}

void loop()
{
}

Add draft of Arduino Read SD/Write Lights loop

Lots of debugging in here.  Currently only handles one file on the SD
card - no logic yet to switch to the next when the file runs out.
Timing is correct, though: every 50 ms, one LED refresh of all 200
lights is sent, then a new frame is read and we busy loop for the
remainder of the 50ms time slice.


/*
  AnalogReadEasyctrl
  Reads an analog input on pin 0.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

 This example code is based on the Arduino example AnalogReadSerial
 */

#include "easyctrl.h"

Monitored<int> sensorValue("sensorValue");

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 115200 bits per second:
  Serial.begin(115200);
  Easyctrl.begin("AnalogReadEasyctrl", Serial);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  sensorValue = analogRead(A0);

  // Let easyctrl run
  Easyctrl.update();

  delay(1);        // delay in between reads for stability
}

Add example of outputting an analog read value


#include <IRKelvinator.h>

IRKelvinatorAC kelvir(D1);  // IR led controlled by Pin D1.

void printState() {
  // Display the settings.
  Serial.println("Kelvinator A/C remote is in the following state:");
  Serial.printf("  Basic\n  Power: %d,  Mode: %d, Temp: %dC, Fan Speed: %d\n",
                kelvir.getPower(), kelvir.getMode(), kelvir.getTemp(),
                kelvir.getFan());
  Serial.printf("  Options\n  X-Fan: %d,  Light: %d, Ion Filter: %d\n",
                kelvir.getXFan(), kelvir.getLight(), kelvir.getIonFilter());
  Serial.printf("  Swing (V): %d, Swing (H): %d, Turbo: %d, Quiet: %d\n",
                kelvir.getSwingVertical(), kelvir.getSwingHorizontal(),
                kelvir.getTurbo(), kelvir.getQuiet());
  // Display the encoded IR sequence.
  unsigned char* ir_code = kelvir.getRaw();
  Serial.print("IR Code: 0x");
  for (int i = 0; i < KELVINATOR_STATE_LENGTH; i++)
    Serial.printf("%02X", ir_code[i]);
  Serial.println();
}

void setup(){
  kelvir.begin();
  Serial.begin(115200);
  delay(200);

  // Set up what we want to send. See IRKelvinator.cpp for all the options.
  // Most things default to off.
  Serial.println("Default state of the remote.");
  printState();
  Serial.println("Setting desired state for A/C.");
  kelvir.on();
  kelvir.setFan(1);
  kelvir.setMode(KELVINATOR_COOL);
  kelvir.setTemp(26);
  kelvir.setSwingVertical(false);
  kelvir.setSwingHorizontal(true);
  kelvir.setXFan(true);
  kelvir.setIonFilter(false);
  kelvir.setLight(true);
}

void loop() {
  // Now send the IR signal.
  Serial.println("Sending IR command to A/C ...");
  kelvir.send();
  printState();
  delay(5000);
}

Add example code for Kelvinator A/C control.


/**
 * @file CosaDS18B20calc.ino
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2015, Mikael Patel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * @section Description
 *
 * This file is part of the Arduino Che Cosa project.
 */

#include "Cosa/Trace.hh"
#include "Cosa/IOStream/Driver/UART.hh"
#include "Cosa/Watchdog.hh"

void setup()
{
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaDS18B20calc: started"));
}

int32_t iscale(int16_t temp)
{
  bool negative = false;
  if (temp < 0) {
    temp = -temp;
    negative = true;
  }
  int32_t res = (temp >> 4) * 1000L + (625 * (temp & 0xf));
  return (negative ? -res : res);
}

float32_t fscale(int16_t temp)
{
  return (temp * 0.0625);
}

#define CHECK(c,t) trace << PSTR(#c "=") << fscale(t) << endl

void loop()
{
  CHECK(+125, 0x07D0);
  CHECK(+85, 0x0550);
  CHECK(+25.0625, 0x0191);
  CHECK(+10.125, 0x00A2);
  CHECK(+0.5, 0x0008);
  CHECK(0, 0x0000);
  CHECK(-0.5, 0xFFF8);
  CHECK(-10.125, 0xFF5E);
  CHECK(-25.0625, 0xFE6F);
  CHECK(-55, 0xFC90);
  ASSERT(true == false);
}

Add validation of DS18B20 temperature calculation.


/*

  Kevyn McPhail
  Deeplocal
  FOB Receiving module code

  If Button A is pressed the the arduino returns 1, if button 2 is pressed the arduino returns 2
  Button A input is PIN 3, Button B input is PIN 2, and the momentary button press input is PIN 4.
  On the R02A receiving module, Button A is output D2, Button B is output D3, Momentary button press
  is output VT.

  Hardware: Sparkfun Pro Micro 5V/16MHz

*/

void setup(){
  Serial.begin(9600);
  for (int i = 2; i<5; i++){
    pinMode(i, INPUT);
  }
}

int firstPin;
int secondPin;
int thirdPin;

void loop(){
  firstPin = digitalRead(3);
  secondPin = digitalRead(2);
  thirdPin = digitalRead(4);

  if (firstPin == 1 & secondPin == 0 & thirdPin == 1) {
    Serial.println(1);
    delay(200);
  }
  if (firstPin == 0 & secondPin == 1 & thirdPin == 1) {
    Serial.println(2);
    delay(200);
  }

}

Add Kevyn's original clear button sketch


/* Header file that allows for writing of data from arduino to pi */

#ifndef serial-print_h
#define serial-print_h

#include "Arduino.h"

import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
   mySerial = new Serial( this, Serial.list()[0], 9600 );
   output = createWriter( "data.txt" );
}
void draw() {
    if (mySerial.available() > 0 ) {
         String value = mySerial.readString();
         if ( value != null ) {
              output.println( value );
         }
    }
}

void keyPressed() {
    output.flush();  // Writes the remaining data to the file
    output.close();  // Finishes the file
    exit();  // Stops the program
}

#endif

Add file to allow saving arduino output from serial


#include <Arduino.h>
#include <SPI.h>
#include <ssd1351.h>

// use this to do Color c = RGB(...) instead of `RGB c = RGB(...)` or ssd1351::LowColor c = RGB(...)
// because it's slightly faster and guarantees you won't be sending wrong colours to the display.

// Choose color depth - LowColor and HighColor currently supported
// typedef ssd1351::LowColor Color;
typedef ssd1351::HighColor Color;

// Choose display buffering - NoBuffer or SingleBuffer currently supported
// auto display = ssd1351::SSD1351<Color, ssd1351::NoBuffer, 128, 96>();
auto display = ssd1351::SSD1351<Color, ssd1351::SingleBuffer, 128, 96>();

bool up = false;
int pos = 127;
const int particles = 256;
int offsets[particles];
int x_pos[particles];
int y_pos[particles];
Color particle_colors[particles];

void setup() {
  Serial.begin(9600);
  Serial.println("Booting...");
  display.begin();
  Serial.println("Display set up.");

  for (int i = 0; i < particles; i++) {
    x_pos[i] = random(0, 128);
    y_pos[i] = random(0, 96);
    particle_colors[i] = ssd1351::RGB(0, i + 10, i/2 + 10);
  }
}

void loop() {
  unsigned long before = millis();
  display.fillScreen(ssd1351::RGB());
  Color circleColor = ssd1351::RGB(0, 128, 255);

  for (int i = 0; i < particles; i++) {
    offsets[i] += random(-2, 3);
    display.drawLine(
      x_pos[i] + offsets[i],
      y_pos[i] + offsets[i],
      pos,
      80 + sin(pos / 4.0) * 20,
      particle_colors[i]
    );
    display.drawCircle(
      x_pos[i] + offsets[i],
      y_pos[i] + offsets[i],
      1,
      circleColor
    );
  }
  display.updateScreen();
  Serial.println(millis() - before);

  if (up) {
    pos++;
    if (pos >= 127) {
      up = false;
    }
  } else {
    pos--;
    if (pos < 0) {
      up = true;
    }
  }
}

Add simple example for the library

Add simple example for the library


#include <SPI.h>
#include <Ethernet.h>
#include "VdlkinoEthernet.h"

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
EthernetServer server(80);
VdlkinoEthernet vdlkino(14, 6, &server);

void url_get_analog_byte(void *block, char *url) {
  VdlkinoBlock *vblock = (VdlkinoBlock*) block;
  char buffer[256];
  char *pc = buffer;

  strcpy(pc, url);
  if (pc[0] == '/') {
    pc++;
  }

  pc = strtok(pc, "/");
  if (strcmp(pc, "analogbyte")) {
    return;
  }

  pc = strtok(NULL, "/");
  if (pc == NULL) {
    return;
  }
  vblock->pin = atoi(pc);

  pc = strtok(NULL, "/");
  if (pc != NULL) {
    return;
  }
  vblock->oper = 8;
  vblock->value = 0;
  vblock->valid = 1;
}

uint16_t get_analog_byte(void *block) {
  VdlkinoBlock *vblock = (VdlkinoBlock*) block;
  return map(analogRead(vblock->pin), 0, 1023, 0, 255);
}

void setup() {
  Ethernet.begin(mac, ip);
  server.begin();
  vdlkino.operations[8] = &get_analog_byte;
  vdlkino.addUrl(&url_get_analog_byte);
}

void loop() {
  vdlkino.run();
}

Add example of a custom function in ethernet


// Copyright 2013 David Turnbull AE9RB
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This is an example application for Arduino to read band
// data from the Peaberry V2 ATU port. Typical usage is to
// change the band on your amplifier or switch antennas.

// No support circuitry is needed.
// Connect a 1/8" jack directly to Arduino pin.
// Leave the ring unconnected, it is not used.
#define ATU_0_PIN 2

void setup() {
  Serial.begin(9600);
}

// This example prints the band number to the serial
// port whenever a change is detected.
void loop() {
  static int band = 0;
  int i = atu_read();

  if (i) {
    if (band != i) {
      Serial.println(i);
    }
    band = i;
  }
}

// Returns a non-zero value when the read is complete.
int atu_read() {
  static int state = 5, data[4], previous;
  static long t;
  long m = micros();
  int i, ret = 0;

  if (state < 6) switch(state) {
  default:
    i = digitalRead(ATU_0_PIN);
    if (m - t > 7000) state = 5;
    if (previous == HIGH && i == LOW) {
      data[state] = m - t;
      state++;
    }
    if (previous == LOW && i == HIGH) {
      t = m;
    }
    previous = i;
    break;
  case 4:
    for (i=0; i<4; i++) {
      ret <<= 1;
      if (data[i] > 2750) ret |= 0x01;
    }
    //nobreak;
  case 5:
    t = m + 50000;
    digitalWrite(ATU_0_PIN, LOW);
    state = 6;
    break;
  }
  else if (t - m < 0) switch(state) {
  case 6:
    t = m + 50000;
    digitalWrite(ATU_0_PIN, HIGH);
    state = 7;
    break;
  case 7:
    t = m + 5000;
    digitalWrite(ATU_0_PIN, LOW);
    state = 8;
    break;
  case 8:
    t = m;
    previous = LOW;
    state = 0;
    break;
  }

  return ret;
}

Add example for using Arduino to read ATU data


#include <DSPI.h>
#include <OpenBCI_32bit_Library.h>
#include <OpenBCI_32Bit_Library_Definitions.h>

unsigned long timer = 0;
byte LEDState = 0;

void setup() {
  // Bring up the OpenBCI Board
  board.begin();

  timer = millis();

  LEDState = 1;
  digitalWrite(OPENBCI_PIN_LED,HIGH);

}

void loop() {

  // Downsample
  if ((millis() - timer) > 20) {
    // Save new time
    timer = millis();
    sendLEDStatus();
  }

  // Check the serial port for new data
  if (board.hasDataSerial0()) {
    // Read one char and process it
    char c = board.getCharSerial0();

    if (c == '0') {
      // Make the LED turn OFF when a '0' is sent from the PC
      digitalWrite(OPENBCI_PIN_LED,LOW);
      LEDState = 0;
    } else if (c == '1') {
      // Make the LED turn ON when a '1' is sent from the PC
      digitalWrite(OPENBCI_PIN_LED,HIGH);
      LEDState = 1;
    }
  }
}

void sendLEDStatus() {
  // Must have header byte
  Serial0.write('A'); // 0x41 1 byte
  // Write the LED state
  Serial0.write(LEDState); // 1 byte
  // Fill the rest with fake data
  for (int i = 0; i < 30; i++) {
    Serial0.write(0x00);
  }
  // Send a stop byte with an `B` or `1011` in the last nibble to indicate a
  //  different packet type.
  Serial0.write(0xCB); // 1 byte
}

Add example for sending custom data packets


#define LED P1_3
#define Sensor P1_4

float reading;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  pinMode(LED, OUTPUT);

  pinMode(Sensor, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  // Turn on LED
  digitalWrite(LED, HIGH);

  // Read sensor
  int i;
  for (i=1;i<10;i++) {
    reading = analogRead(Sensor);
    Serial.print(reading);
    Serial.print(",\n");
    delay(100);
  }

  // Turn on LED
  digitalWrite(LED, LOW);

  for (i=1;i<10;i++) {
    reading = analogRead(Sensor);
    Serial.print(reading);
    Serial.print(",\n");
    delay(100);
  }

}

Test for photoresistor on sensor board made in class.


// Test L9110 library

#include <L9110.h>

L9110 L9110;

// setup pin for LiPo monitor
int LiPoMonitor = 2;

void setup()
{
  pinMode(LiPoMonitor, INPUT);
}

void loop()
{
  if (digitalRead(LiPoMonitor) == LOW)
  {
    L9110.forward();
    delay(3000);
    L9110.fullStop();
    delay(500);
    L9110.reverse();
    delay(3000);
    L9110.fullStop();
    delay(500);
    L9110.forwardSlow();
    delay(3000);
    L9110.fullStop();
    delay(500);
    L9110.reverseSlow();
    delay(3000);
    L9110.fullStop();
    delay(500);
    L9110.left();
    delay(1500);
    L9110.fullStop();
    delay(500);
    L9110.right();
    delay(1500);
    L9110.fullStop();
    delay(3000);
  }
}

Test of new simple functions in L9110 library


/*  Example sketch for the PCF8574 for the purposes of showing how to use the interrupt-pin.

    Attach the positive lead of an LED to PIN7 on the PCF8574 and the negative lead to GND,
    a wire from Arduino-pin 13 to pin 3 on the PCF8474, a wire from the int-pin on the PCF8574
    to Arduino-pin 7 and wires for SDA and SCL to Arduino-pins 2 and 3, respectively.

    If all goes well you should see the small blue LED on the ESP-module lighting up and the
    LED connected to the PCF going off, and vice versa. */

#include <pcf8574_esp.h>

/*  We need to set up the I2C-bus for the library to use */
#include <Wire.h>

// Initialize a PCF8574 at I2C-address 0x20
PCF857x pcf8574(0x20, &Wire);

//If you had a PCF8575 instead you'd use the below format
//PCF857x pcf8575(0x20, &Wire, true);

bool PCFInterruptFlag = false;

void PCFInterrupt() {
  PCFInterruptFlag = true;
}

void setup() {
  Serial.begin(115200);
  delay(5000);
  Serial.println(F("Firing up..."));
  pinMode(13, OUTPUT);

  Wire.begin();
  //Set to 400KHz
  Wire.setClock(400000L);
  pcf8574.begin();
  // Most ready-made PCF8574-modules seem to lack an internal pullup-resistor, so you have to use the MCU-internal one.
  pinMode(7, INPUT_PULLUP);
  pcf8574.resetInterruptPin();

  attachInterrupt(digitalPinToInterrupt(7), PCFInterrupt, FALLING);
}

void loop() {
  if(PCFInterruptFlag){
    Serial.println(F("Got an interrupt: "));
    if(pcf8574.read(3)==1) Serial.println("Pin 3 is HIGH!");
    else Serial.println("Pin 3 is LOW!");
    // DO NOTE: When you write LOW to a pin on a PCF8574 it becomes an OUTPUT.
    // It wouldn't generate an interrupt if you were to connect a button to it that pulls it HIGH when you press the button.
    // Any pin you wish to use as input must be written HIGH and be pulled LOW to generate an interrupt.
    pcf8574.write(7, pcf8574.read(3));
    PCFInterruptFlag=false;
  }
  Serial.println(F("Blink."));
  if(digitalRead(13)==HIGH) digitalWrite(13, LOW);
  else digitalWrite(13, HIGH);
  delay(1000);
}

Add an example for Arduino Micro (Atmega32u4)


void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  SerialUSB.begin(2000000);
}

void loop() {
  static int counter = 0;
  SerialUSB.println(counter, DEC);
  counter = (counter + 1) % (1 << 8);
  digitalWrite(LED_BUILTIN, counter >> 7 ? HIGH : LOW);
  delay(20);
}

Add low speed serial transmitter example


#include<CS5490.h>

#define rx 11
#define tx 12

/* Choose your board */

/* Arduino UNO and ESP8622 */
CS5490 line(MCLK_default,rx,tx);

/* ESP and MEGA  (Uses Serial2)*/
//CS5490 line(MCLK_default);

void setup() {
  //Initializing communication with CS5490
  //600 is the default baud rate velocity.
  line.begin(600);
  //Initializing communication arduino/PC to show results in Monitor Serial
  Serial.begin(115200);
  // wait for serial port to connect. Needed for Leonardo only
  while (!Serial);
  //Set to continous conversion
  line.contConv();
  delay(100);
}

void loop() {

  double foo;

  Serial.println("\n\nWithout calibration");
  line.setDcOffsetI(0); //Reset previous calibration
  foo = line.getInstI();
  Serial.print("DC current value: ");
  Serial.println(foo, 5);
  foo = line.getDcOffsetI();
  Serial.print("DC offset current value: ");
  Serial.println(foo, 5);

  /*
  -------->Types
  DCoffset
  ACoffset
  Gain
  -------->Channels
  Current
  Voltage
  CurrentAndVoltage
  -------->How to use?
  line.calibrate(type,channel)
  */
  line.calibrate(DCoffset,Current);

  Serial.println("\n\nCalibrated");
  foo = line.getInstI();
  Serial.print("DC current value: ");
  Serial.println(foo, 5);
  foo = line.getDcOffsetI();
  Serial.print("DC offset current value: ");
  Serial.println(foo, 5);

  Serial.println("\nReset arduino to see it again... ");
  while(1);

}

Add On Chip Calibration example

Add On Chip Calibration example