Categories

Arduino and DS1624 temperature sensor

The DS1624 consists of two separate functional units: a 256-byte nonvolatile E2 memory and a direct-to-digital temperature sensor.

The nonvolatile memory is made up of 256 bytes of E2 memory. This memory can be used to store any type of information the user wishes. These memory locations are accessed through the 2-wire serial bus.

The direct-to-digital temperature sensor allows the DS1624 to measure the ambient temperature and report the temperature in a 12-bit word with 0.0625°C resolution. The temperature sensor and its related registers are accessed through the 2-wire serial interface. Figure 1 in the full data sheet shows a block diagram of the DS1624.

Features

Reduces Component Count with Integrated Temperature Sensor and Nonvolatile E2 Memory
Measures Temperatures from -55°C to +125°C in 0.0625°C Increments
±0.5°C Accuracy from 0°C to 70°C
256 Bytes of E2 Memory for Storing Information Such as Frequency Compensation Coefficients
No External Components
Easy-to-Use 2-Wire Serial Interface
Temperature is Read as a 12-Bit Value (2-Byte Transfer)
Available in 8-Pin SO and DIP Packages

 

Connection

Module Arduino
VDD 5v
Gnd Gnd
SDA SDA – A4
SCL SCL – A5

 

Code

I downloaded and imported the following library – https://github.com/bluemurder/DS1624

This is the example so some of the hard graft has already been done for you

#include <DS1624.h>
 
// Sensor presents all address pins connected to ground
DS1624 ds1624(0x00);
 
void setup()
{ 
// Begin serial connection at 9600 baud
Serial.begin(9600);
}
 
void loop()
{
float temperature;
bool valid;
 
// Get current temperature
ds1624.GetTemperature(temperature, valid);
 
// Print it
Serial.println(temperature);
 
// Wait a while
delay(1000);
}

Testing

Open the serial monitor and you should see the following

24.31
24.31
24.87
25.94
26.44
27.06
27.37
27.81
27.81
27.69

 

Link

https://datasheets.maximintegrated.com/en/ds/DS1624.pdf

Share

A basic Simba OS example on an Arduino

Ok, I had heard of Simba OS but hadn’t managed to try it, as quoted “2Simba is an RTOS and build framework. It aims to make embedded programming easy and portable”

Install it

Install Simba in the Arduino IDE 1.6.10+ as a third party board using the Boards Manager.

Open File -> Preferences.

Add this URL to Additional Boards Manager URLs and press OK.

https://raw.githubusercontent.com/eerimoq/simba-releases/master/arduino/avr/package_simba_avr_index.json
Open Tools -> Board: … -> Boards Manager… and type simba in the search box.
Click on Simba by Erik Moqivst version x.y.z and click Install and press Close.
Open Tools -> Board: … -> Boards Manager… and select one of the Simba boards in the list.

Now my setup was slightly different, I had an Arduino Nano fitted to a NANo_UNO shield adaptor and a Easy Module Shield fitted to that as well, this was so I can get access to the many onbaord components on that shield via my Nano.

In this case basically we are using 2 LEDs connected to D12 and D13 and we will flash them on and off, so the schematic looks like this

 

Schematic

 

Code

#include "simba.h"
 
int main()
{
    struct pin_driver_t led1;
    struct pin_driver_t led2;
    /* Start the system. */
    sys_start();
 
    /* Initialize the LED pin as output and set its value to 1. */
    pin_init(&led1, &pin_d12_dev, PIN_OUTPUT);
    pin_init(&led2, &pin_d13_dev, PIN_OUTPUT);
    pin_write(&led1, 12);
    pin_write(&led2, 13);
    while (1) {
        /* Wait half a second. */
        thrd_sleep_ms(500);
        /* Toggle the LED on/off. */
        pin_toggle(&led1);
        thrd_sleep_ms(500);
        pin_toggle(&led2);
    }
 
    return (0);
}

 

Upload the sketch and all going well, flashy led’s. I like the look of Simba, it will be something that I play about with.

Share

ATmega328 and for ESP8266 Arduino board

RobotDyn UNO+WIFI R3  is a customized version of the classic ARDUINO UNO R3 board which has two Processors: Atmel ATmega328 microcontroller and ESP8266 WiFi chip with 8 MB flash memory. Each processor has its own pinout headers. The board also has USB-TTL converter based on CH340G on same board.

The convenient solution for the development of new projects requiring Uno and WiFi. Via USB you can update sketches and firmware for ATmega328 and for ESP8266. The board has DIP-switch, to connect the processors.

Features

  • Two CPUs: ATMEGA328P (8-Bit) and ESP8266 (32-Bit)
  • 8mb ESP8266 Flash Memory
  • External U.FL Antenna Connector for WiFi
  • Micro USB connection
  • Power jack, 7-12V power input.
  • Compatible with Arduino
  • Compatible with nodemcu
  • Can be used with existing Arduino Shields

 

Specifications

Microcontrollers 1x ATMEGA328P and 1x ESP-8266EX
Operating Voltage 5V for ATMEGA328P and 3.3V for ESP8266
Digital I/O Pins 13 for ATMEGA328P (5v compliant)+ 8 for ESP8266 (3.3V compliant)
Analog Input Pins 6 for ATMEGA328P (5V compliant) + 1 for ESP8266 (3.3V compliant)
Clock Speed 16MHz for ATMEGA328P and 80MHz/160MHz for ESP8266
ESP8266 Flash 8M bytes

 

The key for operation is the dip switches, here are the combinations

 

Connection

DIP

1

2

3

4

5

6

7

ATmega328<->ESP8266

ON

ON

OFF

OFF

OFF

OFF

OFF

USB <->ATmega328

OFF

OFF

ON

ON

OFF

OFF

OFF

USB<->ESP8266 (Update firmware or sketch)

OFF

OFF

OFF

OFF

ON

ON

ON

USB<->ESP8266 (communication)

OFF

OFF

OFF

OFF

ON

ON

OFF

All independent

OFF

OFF

OFF

OFF

OFF

OFF

OFF

Initially I had difficulty uploading a sketch but these settings work with regards the dip switch, I selected an Arduin/Genuino Uno

CH340 connect to ATmega328 (upload sketch) OFF OFF ON ON OFF OFF OFF NoUSE

Code

This was a modified version of the blink sketch, only difference is that I had an LED connected to D6

void setup() 
{
  pinMode(6, OUTPUT);
}
 
// the loop function runs over and over again forever
void loop() 
{
  digitalWrite(6, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(6, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

 

Links

http://robotdyn.com/downloads/comp_docs/CH340/CH341SER.ZIP

http://robotdyn.com/downloads/comp_docs/CH340/CH340_driver_instruction.pdf

PINOUT=UNO+WiFi-R3-AT328-ESP8266-CH340G.pdf

 

Purchase

UNO+WiFi R3 ATmega328P+ESP8266 (32Mb memory), USB-TTL CH340G. Compatible for Arduino Uno, NodeMCU, WeMos ESP8266

Share

Arduino and MPU-9250 example

The MPU-9250 is the company’s second generation 9-axis MotionTracking device for smartphones, tablets, wearable sensors, and other consumer markets. The MPU-9250, delivered in a 3x3x1mm QFN package, is the world’s smallest 9-axis MotionTracking device and incorporates the latest InvenSense design innovations, enabling dramatically reduced chip size and power consumption, while at the same time improving performance and cost.

The MPU-9250 MotionTracking device sets a new benchmark for 9-axis performance with power consumption only 9.3µA and a size that is 44% smaller than the company’s first-generation device. Gyro noise performance is 3x better, and compass full scale range is over 4x better than competitive offerings.

The MPU-9250 is a System in Package (SiP) that combines two chips: the MPU-6500, which contains a 3-axis gyroscope, a 3-axis accelerometer, and an onboard Digital Motion Processor™ (DMP™) capable of processing complex MotionFusion algorithms; and the AK8963, the market leading 3-axis digital compass. The MPU-9250 supports InvenSense’s market proven MotionFusion. A single design can support the MPU-9250 or MPU-6500, providing customers the flexibility to support either device in different product SKUs.

Improvements include supporting the accelerometer low power mode with as little as 6.4µA of and it provides improved compass data resolution of 16-bits (0.15 µT per LSB). The full scale measurement range of ±4800µT helps alleviate compass placement challenges on complex pcb’s

 

Schematic

 

Code

I found the code below on the internet – link below

 

#include <Wire.h>
#include <TimerOne.h>
 
#define MPU9250_ADDRESS 0x68
#define MAG_ADDRESS 0x0C
 
#define GYRO_FULL_SCALE_250_DPS 0x00 
#define GYRO_FULL_SCALE_500_DPS 0x08
#define GYRO_FULL_SCALE_1000_DPS 0x10
#define GYRO_FULL_SCALE_2000_DPS 0x18
 
#define ACC_FULL_SCALE_2_G 0x00 
#define ACC_FULL_SCALE_4_G 0x08
#define ACC_FULL_SCALE_8_G 0x10
#define ACC_FULL_SCALE_16_G 0x18
 
// This function read Nbytes bytes from I2C device at address Address. 
// Put read bytes starting at register Register in the Data array. 
void I2Cread(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data)
{
// Set register address
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.endTransmission();
 
// Read Nbytes
Wire.requestFrom(Address, Nbytes); 
uint8_t index=0;
while (Wire.available())
Data[index++]=Wire.read();
}
 
 
// Write a byte (Data) in device (Address) at register (Register)
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data)
{
// Set register address
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.write(Data);
Wire.endTransmission();
}
 
// Initial time
long int ti;
volatile bool intFlag=false;
 
// Initializations
void setup()
{
// Arduino initializations
Wire.begin();
Serial.begin(115200);
 
// Set accelerometers low pass filter at 5Hz
I2CwriteByte(MPU9250_ADDRESS,29,0x06);
// Set gyroscope low pass filter at 5Hz
I2CwriteByte(MPU9250_ADDRESS,26,0x06);
 
 
// Configure gyroscope range
I2CwriteByte(MPU9250_ADDRESS,27,GYRO_FULL_SCALE_1000_DPS);
// Configure accelerometers range
I2CwriteByte(MPU9250_ADDRESS,28,ACC_FULL_SCALE_4_G);
// Set by pass mode for the magnetometers
I2CwriteByte(MPU9250_ADDRESS,0x37,0x02);
 
// Request continuous magnetometer measurements in 16 bits
I2CwriteByte(MAG_ADDRESS,0x0A,0x16);
 
pinMode(13, OUTPUT);
Timer1.initialize(10000); // initialize timer1, and set a 1/2 second period
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
 
 
// Store initial time
ti=millis();
}
 
// Counter
long int cpt=0;
 
void callback()
{ 
intFlag=true;
digitalWrite(13, digitalRead(13) ^ 1);
}
 
// Main loop, read and display data
void loop()
{
while (!intFlag);
intFlag=false;
 
// Display time
Serial.print (millis()-ti,DEC);
Serial.print ("\t");
 
 
// _______________
// ::: Counter :::
 
// Display data counter
// Serial.print (cpt++,DEC);
// Serial.print ("\t");
 
 
 
// ____________________________________
// ::: accelerometer and gyroscope :::
 
// Read accelerometer and gyroscope
uint8_t Buf[14];
I2Cread(MPU9250_ADDRESS,0x3B,14,Buf);
 
// Create 16 bits values from 8 bits data
 
// Accelerometer
int16_t ax=-(Buf[0]<<8 | Buf[1]);
int16_t ay=-(Buf[2]<<8 | Buf[3]);
int16_t az=Buf[4]<<8 | Buf[5];
 
// Gyroscope
int16_t gx=-(Buf[8]<<8 | Buf[9]);
int16_t gy=-(Buf[10]<<8 | Buf[11]);
int16_t gz=Buf[12]<<8 | Buf[13];
 
// Display values
 
// Accelerometer
Serial.print (ax,DEC); 
Serial.print ("\t");
Serial.print (ay,DEC);
Serial.print ("\t");
Serial.print (az,DEC); 
Serial.print ("\t");
 
// Gyroscope
Serial.print (gx,DEC); 
Serial.print ("\t");
Serial.print (gy,DEC);
Serial.print ("\t");
Serial.print (gz,DEC); 
Serial.print ("\t");
 
 
// _____________________
// ::: Magnetometer :::
 
 
// Read register Status 1 and wait for the DRDY: Data Ready
 
uint8_t ST1;
do
{
I2Cread(MAG_ADDRESS,0x02,1,&ST1);
}
while (!(ST1&0x01));
 
// Read magnetometer data 
uint8_t Mag[7]; 
I2Cread(MAG_ADDRESS,0x03,7,Mag);
 
// Create 16 bits values from 8 bits data
 
// Magnetometer
int16_t mx=-(Mag[3]<<8 | Mag[2]);
int16_t my=-(Mag[1]<<8 | Mag[0]);
int16_t mz=-(Mag[5]<<8 | Mag[4]);
 
 
// Magnetometer
Serial.print (mx+200,DEC); 
Serial.print ("\t");
Serial.print (my-70,DEC);
Serial.print ("\t");
Serial.print (mz-700,DEC); 
Serial.print ("\t");
 
 
 
// End of line
Serial.println("");
// delay(100); 
}

 

 

 

 

Links

Code above – http://www.lucidarme.me/?p=5057
Good examples – https://github.com/kriswiner/MPU9250
Datasheet – https://www.invensense.com/wp-content/uploads/2015/02/PS-MPU-9250A-01-v1.1.pdf

MPU-9250 9-axis sensor module I2C/SPI Communications Thriaxis gyroscope + triaxial accelerometer+triaxial magnetic field

Share