Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod ISNS20 with Arduino Uno

Application notes for Pmod ISNS20 and Arduino Uno. In this app, the value of the sensed current is displayed on the serial monitor.

BeginnerShowcase (no instructions)1 hour521
Using the Pmod ISNS20 with Arduino Uno

Things used in this project

Story

Read more

Code

Pmod ISNS20 and Arduino Uno Code

Arduino
Using this code will display the sensed current on the serial monitor.
/************************************************************************
*
* Test of Pmod ISNS20
*
*************************************************************************
* Description: Pmod_ISNS20
* The value of the sensed current is displayed on the serial monitor.
*
*
* Material
* 1. Arduino Uno
* 2. Pmod ISNS20 
*
************************************************************************/
#define Correction 100 // Sensor Sensitivity Correction Percent
#define Filtre 0 // Filtre=1 If using the module filters
#define Echantillon 5000 // number of samples
#define CS 10 // Assignment of the CS pin

#include <SPI.h> // call library

int MSB;
int LSB;
signed int valeur;
signed int total = 0;
signed int milli_amps;

void setup()
{
 Serial.begin(9600); // initialization of serial communication
 SPI.begin(); // initialization of SPI port
 SPI.setDataMode(SPI_MODE0); // configuration of SPI communication in mode 0
 SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1MHz
 pinMode(CS, OUTPUT);
}

void loop()
 {
  if(Filtre == 1)
  {
   for(int i; i < Echantillon; i++)
   {
    digitalWrite(CS, LOW); // activation of CS line
    MSB=SPI.transfer(0x00); // MSBs recovery
    LSB=SPI.transfer(0x00); // LSBs recovery
    digitalWrite(CS, HIGH); // deactivation of CS line
    valeur = (Correction / 100) * (10000 * (((MSB<<8) | LSB) - 2048)) / 899; // Formula given in the documentation
documentation
    total = total + valeur;
    }
   milli_amps = total / Echantillon;
  }
  else
  {
   digitalWrite(CS, LOW); // activation of CS line
   MSB=SPI.transfer(0x00); // MSBs recovery
   LSB=SPI.transfer(0x00); // LSBs recovery
   digitalWrite(CS, HIGH); // deactivation of CS line
   milli_amps = (Correction / 100) * (10000 * (((MSB<<8) | LSB) - 2048)) / 899; // Formula given in the
documentation
  }
  Serial.print("Courant=");
  Serial.print(milli_amps);
  Serial.println(" mA");
  delay(10);
}

Credits

Martha Migliacio

Martha Migliacio

5 projects • 7 followers
Alex Wong

Alex Wong

5 projects • 19 followers
I work in Digilent and like creating projects
Thanks to Lextronics.

Comments