Skip to content
Snippets Groups Projects
Commit 76863068 authored by adityaom's avatar adityaom
Browse files

Particle Board Firmware: Final

parent c3fc461f
Branches main
No related tags found
No related merge requests found
lang:java
lang:python
lang:arduino
lang:particle
lang:C
sku:SI7005_I2CS
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// SI7005
// This code is designed to work with the SI7005_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Temperature?sku=SI7005_I2CS#tabs-0-product_tabset-2
#include<Wire.h>
// SI7005 I2C address is 0x40(64)
#define Addr 0x40
void setup()
{
// Initialise I2C communication as Master
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
delay(300);
}
void loop()
{
unsigned int data[3];
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x03);
// Command for temperature measurement
Wire.write(0x11);
// Stop I2C transmission
Wire.endTransmission();
delay(500);
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, temp_msb, temp_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
// Keep checking for valid data
while ((data[0] & 0x01) != 0)
{
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, temp_msb, temp_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
}
// Convert the data to 14-bits
int temp = ((data[1] * 256) + (data[2] & 0xFC)) / 4;
float cTemp = (temp / 32.0) - 50.0;
float fTemp = cTemp * 1.8 + 32;
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x03);
// Command for humidity measurement
Wire.write(0x01);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, humidity_msb, humidity_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
// Keep checking for valid data
while ((data[0] & 0x01) != 0)
{
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, humidity_msb, humidity_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
}
// Convert the data to 12-bits
float humidity = ((data[1] * 256.0) + (data[2] & 0xF0)) / 16;
humidity = (humidity / 16.0) - 24.0;
// Output data to serial monitor
Serial.print("Relative humidity : ");
Serial.print(humidity);
Serial.println(" %RH");
Serial.print("Temperature in Celsius : ");
Serial.print(cTemp);
Serial.println(" C");
Serial.print("Temperature in Fahrenheit : ");
Serial.print(fTemp);
Serial.println(" F");
delay(500);
}
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// SI7005
// This code is designed to work with the SI7005_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Temperature?sku=SI7005_I2CS#tabs-0-product_tabset-2
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
void main()
{
// Create I2C bus
int file;
char *bus = "/dev/i2c-1";
if((file = open(bus, O_RDWR)) < 0)
{
printf("Failed to open the bus. \n");
exit(1);
}
// Get I2C device, SI7005 I2C address is 0x40(64)
ioctl(file, I2C_SLAVE, 0x40);
// Send temperature measurement command(0x11)
char config[2] = {0};
config[0] = 0x03;
config[1] = 0x11;
write(file, config, 2);
sleep(1);
// Read 3 bytes of data from register(0x00)
// cTemp msb, cTemp lsb
char reg[1] = {0x00};
write(file, reg, 1);
char data[3] = {0};
if(read(file, data, 3) != 3)
{
printf("Erorr : Input/output Erorr \n");
}
else
{
// Checking the status, Poll RDY in status until it is low(=0)
while((data[0] & 0x01) != 0)
{
read(file, data, 3);
}
// Convert the data to 14-bits
float cTemp = (((data[1] * 256 + (data[2] & 0xFC)) / 4.0) / 32.0) - 50.0;
float fTemp = cTemp * 1.8 + 32;
// Output data to screen
printf("Temperature in Celsius : %.2f \n", cTemp);
printf("Temperature in Fahrenheit : %.2f \n", fTemp);
}
// Send humidity measurement command
config[0] = 0x03;
config[1] = 0x01;
write(file, config, 2);
sleep(1);
// Read 2 bytes of data from register(0x00)
// humidity msb, humidity lsb
reg[0] = 0x00;
write(file, reg, 1);
if(read(file, data, 3) != 3)
{
printf("Erorr : Input/output Erorr \n");
}
else
{
// Checking the status, Poll RDY in status until it is low(=0)
while((data[0] & 0x01) != 0)
{
read(file, data, 3);
}
// Convert the data to 12-bits
double humidity = (((data[1] * 256 + (data[2] & 0xF0)) / 16.0) / 16.0) - 24.0;
// Output data to screen
printf("Relative Humidity : %.2f \n", humidity);
}
}
# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# SI7005
# This code is designed to work with the SI7005_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Temperature?sku=SI7005_I2CS#tabs-0-product_tabset-2
from OmegaExpansion import onionI2C
import time
# Get I2C bus
i2c = onionI2C.OnionI2C()
# SI7005 address, 0x40(64)
# Select Configuration register, 0x03(03)
# 0x11(11) Temperature, Fast mode enable, Heater Off
i2c.writeByte(0x40, 0x03, 0x11)
time.sleep(0.5)
# SI7005 address, 0x40(64)
# Read data back from 0x00(00), 3 bytes
# Status register, ctemp MSB, ctemp LSB
# Checking the status, Poll RDY in status until it is low(=0)
data = i2c.readBytes(0x40, 0x00, 3)
while (data[0] & 0x01) != 0 :
data = i2c.readBytes(0x40, 0x00, 3)
# Convert the data to 14-bits
ctemp = ((data[1] * 256 + data[2]) / 4.0) / 32.0 - 50.0
ftemp = ctemp * 1.8 + 32
# SI7005 address, 0x40(64)
# Select Configuration register, 0x03(03)
# 0x01(01) Relative Humidity, Fast mode enable, Heater Off
i2c.writeByte(0x40, 0x03, 0x01)
time.sleep(0.5)
# SI7005 address, 0x40(64)
# Read data back from 0x00(00), 3 bytes
# Status register, humidity MSB, humidity LSB
# Checking the status, Poll RDY in status until it is low(=0)
data = i2c.readBytes(0x40, 0x00, 3)
while (data[0] & 0x01) != 0 :
data = i2c.readBytes(0x40, 0x00, 3)
# Convert the data to 12-bits
humidity = ((data[1] * 256 + data[2]) / 16.0) / 16.0 - 24.0
# Output data to screen
print "Relative Humidity : %.2f %%" %humidity
print "Temperature in Celsius : %.2f C" %ctemp
print "Temperature in Fahrenheit : %.2f F" %ftemp
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// SI7005
// This code is designed to work with the SI7005_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Temperature?sku=SI7005_I2CS#tabs-0-product_tabset-2
#include <application.h>
#include <spark_wiring_i2c.h>
// SI7005 I2C address is 0x40(64)
#define Addr 0x40
double cTemp = 0.0, fTemp = 0.0, humidity = 0.0;
int temp = 0;
void setup()
{
// Set variable
Particle.variable("i2cdevice", "SI7005");
Particle.variable("Humidity", humidity);
Particle.variable("cTemp", cTemp);
// Initialise I2C communication as Master
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
delay(300);
}
void loop()
{
unsigned int data[3];
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x03);
// Command for temperature measurement
Wire.write(0x11);
// Stop I2C transmission
Wire.endTransmission();
delay(500);
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, temp_msb, temp_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
// Keep checking for valid data
while ((data[0] & 0x01) != 0)
{
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, humidity_msb, humidity_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
}
// Convert the data to 14-bits
temp = ((data[1] * 256) + (data[2] & 0xFC)) / 4;
cTemp = (temp / 32.0) - 50.0;
fTemp = cTemp * 1.8 + 32;
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x03);
// Command for humidity measurement
Wire.write(0x01);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, humidity_msb, humidity_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
// Keep checking for valid data
while ((data[0] & 0x01) != 0)
{
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
// Request 3 byte of data
Wire.requestFrom(Addr, 3);
// Read 3 byte of data
// status, humidity_msb, humidity_lsb
if (Wire.available() == 3)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
}
}
// Convert the data to 12-bits
humidity = ((data[1] * 256) + (data[2] & 0xF0)) / 16;
humidity = (humidity / 16) - 24;
// Output data to dashboard
Particle.publish("Relative humidity : ", String(humidity));
Particle.publish("Temperature in Celsius : ", String(cTemp));
Particle.publish("Temperature in Farhenheit : ", String(fTemp));
delay(500);
}
# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# SI7005
# This code is designed to work with the SI7005_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Temperature?sku=SI7005_I2CS#tabs-0-product_tabset-2
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# SI7005 address, 0x40(64)
# Select Configuration register, 0x03(03)
# 0x11(11) Temperature, Fast mode enable, Heater Off
bus.write_byte_data(0x40, 0x03, 0x11)
time.sleep(0.5)
# SI7005 address, 0x40(64)
# Read data back from 0x00(00), 3 bytes
# Status register, ctemp MSB, ctemp LSB
# Checking the status, Poll RDY in status until it is low(=0)
data = bus.read_i2c_block_data(0x40, 0x00, 3)
while (data[0] & 0x01) != 0 :
data = bus.read_i2c_block_data(0x40, 0x00, 3)
# Convert the data to 14-bits
ctemp = ((data[1] * 256 + data[2]) / 4.0) / 32.0 - 50.0
ftemp = ctemp * 1.8 + 32
# SI7005 address, 0x40(64)
# Select Configuration register, 0x03(03)
# 0x01(01) Relative Humidity, Fast mode enable, Heater Off
bus.write_byte_data(0x40, 0x03, 0x01)
time.sleep(0.5)
# SI7005 address, 0x40(64)
# Read data back from 0x00(00), 3 bytes
# Status register, humidity MSB, humidity LSB
# Checking the status, Poll RDY in status until it is low(=0)
data = bus.read_i2c_block_data(0x40, 0x00, 3)
while (data[0] & 0x01) != 0 :
data = bus.read_i2c_block_data(0x40, 0x00, 3)
# Convert the data to 12-bits
humidity = ((data[1] * 256 + data[2]) / 16.0) / 16.0 - 24.0
# Output data to screen
print "Relative Humidity : %.2f %%" %humidity
print "Temperature in Celsius : %.2f C" %ctemp
print "Temperature in Fahrenheit : %.2f F" %ftemp
# SI7005 Board IoT
[![SI7005](SI7005_I2CS.png)](https://www.controleverything.com/content/Temperature?sku=SI7005_I2CS)
# SI7005
SI7005 Humidity and Temperature Sensor
Humidity and Temperature Sensor for dhaarav0.5
\ No newline at end of file
The SI7005 is a Humidity and Temperature Sensor.
This Device is available from ControlEverything.com [SKU: SI7005_I2CS]
https://www.controleverything.com/content/Temperature?sku=SI7005_I2CS
This Sample code can be used with Raspberry Pi, Arduino, Particle Photon, Beaglebone Black and Onion Omega.
## Java
Download and install pi4j library on Raspberry pi. Steps to install pi4j are provided at:
http://pi4j.com/install.html
Download (or git pull) the code in pi.
Compile the java program.
```cpp
$> pi4j SI7005.java
```
Run the java program.
```cpp
$> pi4j SI7005
```
## Python
Download and install smbus library on Raspberry pi. Steps to install smbus are provided at:
https://pypi.python.org/pypi/smbus-cffi/0.5.1
Download (or git pull) the code in pi. Run the program.
```cpp
$> python SI7005.py
```
## Arduino
Download and install Arduino Software (IDE) on your machine. Steps to install Arduino are provided at:
https://www.arduino.cc/en/Main/Software
Download (or git pull) the code and double click the file to run the program.
Compile and upload the code on Arduino IDE and see the output on Serial Monitor.
## Particle Photon
Login to your Photon and setup your device according to steps provided at:
https://docs.particle.io/guide/getting-started/connect/photon/
Download (or git pull) the code. Go to online IDE and copy the code.
https://build.particle.io/build/
Verify and flash the code on your Photon. Code output is shown in logs at dashboard:
https://dashboard.particle.io/user/logs
## C
Download (or git pull) the code in Beaglebone Black.
Compile the c program.
```cpp
$>gcc SI7005.c -o SI7005
```
Run the c program.
```cpp
$>./SI7005
```
## Onion Omega
Get Started and setting up the Onion Omega according to steps provided at :
https://wiki.onion.io/Get-Started
To install the Python module, run the following commands:
```cpp
opkg update
```
```cpp
opkg install python-light pyOnionI2C
```
Download (or git pull) the code in Onion Omega. Run the program.
```cpp
$> python SI7005.py
```
#####The code output is the relative humidity and temperature reading in degree celsius and fahrenheit.
SI7005_I2CS.png

115 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment