Skip to content

Commit

Permalink
fixed readmes and added shell
Browse files Browse the repository at this point in the history
  • Loading branch information
justind000 committed Sep 23, 2019
1 parent 1e4c70b commit bfff68f
Show file tree
Hide file tree
Showing 505 changed files with 83 additions and 15,190 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ The library to use it is in the Arduino and Particle.io IDE. A [python](https://

```
#include "uFire_SHT20.h"
uFire_SHT20 sht20;
sht20.temperature()
float temp_c = sht20.temperature();
float rh = sht20.humidity();
```

#### Buy it
Expand Down
46 changes: 0 additions & 46 deletions keywords.txt

This file was deleted.

71 changes: 0 additions & 71 deletions python/Micropython/SHT20.py

This file was deleted.

10 changes: 10 additions & 0 deletions python/RaspberryPi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Isolated EC Probe Interface for Raspberry Pi

API [documentation](https://ufire.co/docs/uFire_SHT20/) has usage and examples for MicroPython.

#### Running the Examples
1. git clone https://github.com/u-fire/uFire_SHT20.git --depth=1
2. cd Isolated_EC/python/RaspberryPi
3. sudo python3 basic.py
4. sudo python3 humidity.py
5. sudo python3 temperature.py
4 changes: 2 additions & 2 deletions python/RaspberryPi/SHT20.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def __init__(self, bus=3, resolution=RESOLUTION_12BITS):

config = self.bus.read_byte_data(SHT20_I2C, SHT20_READ_USER_REG)
config = ((config & _RESERVED_BITMASK) | self._resolution | self._onchip_heater | self._otp_reload)
self.bus.write_byte(SHT20_I2C, SHT20_WRITE_USER_REG)
self.bus.write_byte(SHT20_I2C, config)
#self.bus.write_byte(SHT20_I2C, SHT20_WRITE_USER_REG)
self.bus.write_byte_data(SHT20_I2C, SHT20_WRITE_USER_REG, config)

def humidity(self):
self.bus.write_byte(SHT20_I2C, SHT20_HUMID_HM)
Expand Down
16 changes: 16 additions & 0 deletions python/RaspberryPi/shell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import cmd
from SHT20 import SHT20

sht20 = SHT20()

class SHT20Shell(cmd.Cmd):
prompt = '> '

def do_temperature(self, a):
print("%.2f" %sht20.temperature())


def do_humidity(self, a):
print("%.2f" %sht20.humidity())

SHT20Shell().cmdloop()
28 changes: 16 additions & 12 deletions rust/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
### Isolated EC Probe Interface
### SHT20 Temperature and Humidity Sensor

> Monitor hydroponic nutrient levels or salinity in pools.
- Electrical Conductivity in Siemens (0.5 - 20.0 mS/cm)
- Total Dissolved Solids in PPM (250 - 100,000 PPM)
- Salinity in PSU (2 - 12 PSU)
- Temperature in Celsius/Fahrenheit (-55 - 125 C)
- Electrically Isolated
- Temperature range: -40 to 125 C(-40 to 257 F)
- Humidity range: 0 to 100 % RH
- Temperature accuracy: ± 0.5% C
- Humidity accuracy: ± 5% RH
- Interface: I2C
- Voltage range: 2.1 - 3.6 V

##### What it is
### What it is

An electrically isolated I2C sensor device, a waterproof temperature sensor, and an electrical conductivity probe. It measures the conductivity of a solution and converts it into Siemens (S) total dissolved solids and salinity. The firmware allows for single or dual-point calibration with temperature compensation.
An SHT20 sensor in a plastic enclosure with a 1m length of cable.

The board uses the [Qwiic](https://www.sparkfun.com/qwiic) Connect System for wiring, it's an easy-to-use, polarized, push-to-fit connector. No more mistaken connections or soldering header pins.
The device uses the Qwiic Connect System for wiring, it's an easy-to-use, polarized, push-to-fit connector. No more mistaken connections or soldering header pins.

#### Running this example
From the /rust folder, type `cargo run`. You may run into permission issues and need to run the executable with sudo. `sudo ./target/debug/ufire_ec_bin`. You'll be presented with a `> ` prompt. Type `help` and you'll get a list of commands you can run to perform various tasks with the board like taking an EC or temperature measurement.
### Using it

There is plenty of [documentation](/docs/uFire_SHT20/) on the [specification](/docs/uFire_SHT20/#characteristics), and [setup](/docs/uFire_SHT20/#getting-started) of the sensor.

#### Running this example
From the /rust folder, type `cargo run`. You may run into permission issues and need to run the executable with sudo. `sudo ./target/debug/ufire_sht20_bin`. You'll be presented with a `> ` prompt. Type `help` and you'll get a list of commands you can run.

### Get the board
Visit [uFire.co](https://ufire.co).
Visit [uFire.co](https://ufire.co).
65 changes: 31 additions & 34 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate i2cdev;
use self::i2cdev::core::*;
use self::i2cdev::linux::{LinuxI2CDevice, LinuxI2CError};

//const SHT20_I2C: u8 = 0x40;
const SHT20_I2C: u16 = 0x40;
const SHT20_TEMP_HM: u8 = 0xE3;
const SHT20_HUMID_HM : u8 = 0xE5;
const SHT20_WRITE_USER_REG: u8 = 0xE6;
Expand All @@ -38,50 +38,28 @@ pub struct SHT20 {
}

impl SHT20 {
/// Create a new EcProbe object
/// Create a new SHT20 object
///
/// Pass the i2c port to use, it must be a software overlay device, and I2C address.
/// Pass the i2c port to use.
/// # Example
/// ```
/// let mut ec = ufire_ec::EcProbe::new("/dev/i2c-3", 0x3c).unwrap();
/// let mut sht20 = SHT20::new("/dev/i2c-3").unwrap();
/// ```
pub fn new(filename: &'static str, address: u16) -> Result<Self, Box<LinuxI2CError>> {
let dev = LinuxI2CDevice::new(filename, address)?;
pub fn new(filename: &'static str) -> Result<Self, Box<LinuxI2CError>> {
let dev = LinuxI2CDevice::new(filename, SHT20_I2C)?;

Ok(SHT20 { dev: Box::new(dev) })
}

/// Starts the library
///
/// # Example
/// ```
/// let mut ec = ufire_ec::EcProbe::new("/dev/i2c-3", 0x3c).unwrap();
/// ec.measure_temp();
/// ```
pub fn begin(&mut self, resolution: u8) -> Result<(), Box<LinuxI2CError>> {
self.dev.smbus_write_byte(SHT20_RESET)?;
thread::sleep(Duration::from_millis(SOFT_RESET_DELAY));
let mut _resolution: u8 = resolution;
let _onchip_heater:u8 = _DISABLE_ONCHIP_HEATER;
let _otp_reload: u8 = _DISABLE_OTP_RELOAD;

self._change_register(SHT20_READ_USER_REG)?;
let mut config: u8 = self.dev.smbus_read_byte()?;
config = (config & _RESERVED_BITMASK) | _resolution | _onchip_heater | _otp_reload;
self.dev.smbus_write_byte(SHT20_WRITE_USER_REG)?;
self.dev.smbus_write_byte(config)?;

Ok(())
}

/// Start a temperature measurement
///
/// # Example
/// ```
/// let mut ec = ufire_ec::EcProbe::new("/dev/i2c-3", 0x3c).unwrap();
/// ec.measure_temp();
/// let mut sht20 = SHT20::new("/dev/i2c-3").unwrap();
/// let temp:f32 = sht20.temperature().unwrap();
/// ```
pub fn temperature(&mut self) -> Result<(f32), Box<LinuxI2CError>> {
self._reset()?;
self.dev.smbus_write_byte(SHT20_TEMP_HM)?;
thread::sleep(Duration::from_millis(TEMPERATURE_DELAY));
self._change_register(SHT20_TEMP_HM)?;
Expand All @@ -92,14 +70,15 @@ impl SHT20 {
}


/// Start a temperature measurement
/// Start a humidity measurement
///
/// # Example
/// ```
/// let mut ec = ufire_ec::EcProbe::new("/dev/i2c-3", 0x3c).unwrap();
/// ec.measure_temp();
/// let mut sht20 = SHT20::new("/dev/i2c-3").unwrap();
/// let hum:f32 = sht20.humidity().unwrap();
/// ```
pub fn humidity(&mut self) -> Result<(f32), Box<LinuxI2CError>> {
self._reset()?;
self.dev.smbus_write_byte(SHT20_HUMID_HM)?;
thread::sleep(Duration::from_millis(HUMIDITY_DELAY));
self._change_register(SHT20_HUMID_HM)?;
Expand All @@ -109,6 +88,24 @@ impl SHT20 {
Ok(-6.0 + 125.0 * ((msb as f32) * 256.0 + (lsb as f32)) / 65536.0)
}


pub fn _reset(&mut self) -> Result<(), Box<LinuxI2CError>> {
self.dev.smbus_write_byte(SHT20_RESET)?;
thread::sleep(Duration::from_millis(SOFT_RESET_DELAY));
let mut _resolution: u8 = RESOLUTION_12BITS;
let _onchip_heater:u8 = _DISABLE_ONCHIP_HEATER;
let _otp_reload: u8 = _DISABLE_OTP_RELOAD;

self._change_register(SHT20_READ_USER_REG)?;
let mut config: u8 = self.dev.smbus_read_byte()?;
config = (config & _RESERVED_BITMASK) | _resolution | _onchip_heater | _otp_reload;
//self.dev.smbus_write_byte(SHT20_WRITE_USER_REG)?;
//thread::sleep(Duration::from_millis(1000));
//self.dev.smbus_write_byte(config)?;
self.dev.smbus_write_byte_data(SHT20_WRITE_USER_REG, config)?;
Ok(())
}

pub fn _write_register(&mut self, register: u8, f_val: f32) -> Result<(), Box<LinuxI2CError>> {
unsafe {
let buf: [u8; 4] = mem::transmute(f_val);
Expand Down
13 changes: 5 additions & 8 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ use ufire_sht20::*;
fn main() {
println!("Isolated EC Probe Interface shell");
println!("type `help` for a list of commands");
let v = vec![0x40];
let mut shell = Shell::new(v);
let mut shell = Shell::new(());

shell.new_command_noargs("t", "Measure temperature", move |io, v| {
let mut sht20 = SHT20::new("/dev/i2c-3", v[0]).unwrap();
sht20.begin(::RESOLUTION_12BITS).unwrap();
shell.new_command_noargs("t", "Measure temperature", move |io, _| {
let mut sht20 = SHT20::new("/dev/i2c-3").unwrap();
try!(writeln!(io, "{}", sht20.temperature().unwrap()));
Ok(())
});

shell.new_command_noargs("h", "Measure humidity", move |io, v| {
let mut sht20 = SHT20::new("/dev/i2c-3", v[0]).unwrap();
sht20.begin(::RESOLUTION_12BITS).unwrap();
shell.new_command_noargs("h", "Measure humidity", move |io, _| {
let mut sht20 = SHT20::new("/dev/i2c-3").unwrap();
try!(writeln!(io, "{}", sht20.humidity().unwrap()));
Ok(())
});
Expand Down
1 change: 0 additions & 1 deletion rust/target/.rustc_info.json

This file was deleted.

Empty file removed rust/target/debug/.cargo-lock
Empty file.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.
Loading

0 comments on commit bfff68f

Please sign in to comment.