still working on random number generation
This commit is contained in:
parent
32c393d035
commit
9b053b3c87
4 changed files with 227 additions and 16 deletions
|
|
@ -1,4 +1,8 @@
|
|||
//This file contains subroutines for the Accelerometer and the Pressure sensor.
|
||||
//This file contains subroutines for the Accelerometer
|
||||
|
||||
#define ACL_ID 0x49 // LMS303D ID register value
|
||||
#define ACL_ID_REG 0x0F // LMS303D ID register address
|
||||
|
||||
|
||||
void AccelSetup(){
|
||||
|
||||
|
|
@ -155,4 +159,4 @@ uint8_t xlo,xhi,ylo,yhi,zlo,zhi;
|
|||
acl_fx = (AccelFullScale * GravityEarth) * ((float) (acl_x) / (float) 0x7FFF);
|
||||
acl_fy = (AccelFullScale * GravityEarth) * ((float) (acl_y) / (float) 0x7FFF);
|
||||
acl_fz = (AccelFullScale * GravityEarth) * ((float) (acl_z) / (float) 0x7FFF);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
//Cosmic Pi Firmware - forked version J.Devine 2017
|
||||
//Bugs: Internal temperature doesn't work when ADC is in free running mode; configuration needs changing in the temp subroutine.
|
||||
|
||||
//This particular build is focused on being a random number generator
|
||||
|
||||
float ADCTempValue = 0; //buffer for the internal temperature
|
||||
String SerialNumberValue = ""; //Buffer for the serial number
|
||||
|
|
@ -26,20 +26,29 @@ bool dump = false; //if there's an event, dump the data.
|
|||
|
||||
//I2C Bus 0 Addresses
|
||||
#define I2CPot 0x28
|
||||
#define I2CPot1_PIN 35
|
||||
#define I2CPot2_PIN 36
|
||||
#define I2CPot3_PIN 37
|
||||
#define I2CPot1_PIN 35 //PA0 on the circuit diagram
|
||||
#define I2CPot2_PIN 36 //PA1 on the circuit diagram
|
||||
#define I2CPot3_PIN 37 //PA2 on the circuit diagram
|
||||
|
||||
#define AccelSA0 26
|
||||
#define AccelSA1 27 // address pin for the LPS25H
|
||||
|
||||
|
||||
//I2C Bus 1 Addresses
|
||||
#define HumAddr 0x40
|
||||
#define AccelAddr 0x1D // LMS303D on the main board on i2c bus 1
|
||||
#define ACL_ID 0x49 // LMS303D ID register value
|
||||
#define ACL_ID_REG 0x0F // LMS303D ID register address
|
||||
#define PressureAddr 0x5C
|
||||
|
||||
|
||||
#define AccelFullScale 2.0 // +-2g 16 bit 2's compliment
|
||||
#define GravityEarth 9.80665 //The earth's gravity
|
||||
|
||||
const int HVSetpoints[50] = {0x8F,0x8F,0x8E,0x8D,0x8D,0x8C,0x8B,0x8B,0x8A,0x89,
|
||||
0x89,0x88,0x87,0x87,0x86,0x86,0x85,0x84,0x84,0x83,
|
||||
0x82,0x82,0x81,0x80,0x80,0x7F,0x7E,0x7E,0x7D,0x7D,
|
||||
0x7C,0x7B,0x7B,0x7A,0x79,0x79,0x78,0x77,0x77,0x76,
|
||||
0x75,0x75,0x74,0x73,0x73,0x72,0x72,0x71,0x70,0x70};
|
||||
//HV setpoints, starting from 0 to 50 degrees (i.e. 0th element is 0 degrees) - add 0.5 and cast as an int for the index.
|
||||
|
||||
String StringEventBuf[3] = {"Output String Buffer Event 1", "Output String Buffer Event 2", "Output String Buffer Event 3"};
|
||||
long EventTimestamp[3] = {0,0,0};
|
||||
|
|
@ -53,16 +62,19 @@ void setup() {
|
|||
//Start Wire (I2C comms)
|
||||
Wire.begin();
|
||||
Wire1.begin();
|
||||
|
||||
//LED output pins
|
||||
pinMode(Power_LED, OUTPUT); //Power LED
|
||||
pinMode(Event_LED, OUTPUT); //Event LED
|
||||
pinMode(Event_Input, INPUT); //Event LED
|
||||
|
||||
//SoftSPI output pins
|
||||
digitalWrite(SS, HIGH); // Start with SS high
|
||||
pinMode(SS_pin, OUTPUT);
|
||||
pinMode(SCK_pin, OUTPUT);
|
||||
pinMode(MISO_pin, INPUT); //note this is the avalanche output from the MAX1932, but not yet used
|
||||
pinMode(MOSI_pin, OUTPUT);
|
||||
|
||||
//I2CPot output pins
|
||||
pinMode(I2CPot1_PIN, OUTPUT);
|
||||
pinMode(I2CPot2_PIN, OUTPUT);
|
||||
|
|
@ -71,18 +83,21 @@ void setup() {
|
|||
digitalWrite(I2CPot1_PIN, LOW);
|
||||
digitalWrite(I2CPot2_PIN, LOW);
|
||||
digitalWrite(I2CPot3_PIN, LOW);
|
||||
|
||||
// Pressure sensor address setup
|
||||
pinMode(AccelSA1, OUTPUT); //Pressure Sensor
|
||||
digitalWrite(AccelSA1, LOW);
|
||||
|
||||
|
||||
|
||||
Serial.begin(9600);//we run the serial at 9600 for debugging only.
|
||||
|
||||
//make sure the LED's are off
|
||||
digitalWrite(Power_LED, 0);
|
||||
digitalWrite(Event_LED, 0);
|
||||
//Temporary positioning; Read the temperature at boot in the Arduino
|
||||
//ADCTempValue = ADCTemp();
|
||||
//Serial.println(ADCTempValue);
|
||||
//Set the Vbias based on the internal temperature at boot
|
||||
VbiasSet(100);
|
||||
PressureSetup();
|
||||
VbiasSet(HVSetpoints[int(PressureTemp()+0.5)]);
|
||||
//VbiasSet(100);
|
||||
ThresholdSet(130,130);
|
||||
|
||||
//ADCSetup();
|
||||
|
|
@ -106,7 +121,10 @@ Serial.println(Ch2);
|
|||
|
||||
void loop() {
|
||||
//Serial.println(String(analogRead(A6))+" "+String(analogRead(A7))+" " +int(digitalRead(Event_Input)));
|
||||
|
||||
Serial.println(PressureTemp());
|
||||
|
||||
delay(1000);
|
||||
/*
|
||||
if (digitalRead(Event_Input)) {
|
||||
Serial.print("Event ");
|
||||
oldtime = timeX;
|
||||
|
|
@ -128,6 +146,7 @@ EventFlashOff();
|
|||
//Serial.println("Accel");
|
||||
//AccelRead();
|
||||
// Serial.println(String(Accel[0])+" "+ String(Accel[1])+" "+ String(Accel[2]));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -303,4 +322,4 @@ float treal = fixtemp + (( trans * ulValue ) - offset ) / factor;
|
|||
|
||||
return treal;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
100
Pressure.ino
Normal file
100
Pressure.ino
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
//all this stuff comes from the LHP25S data sheet
|
||||
|
||||
#define PressureREF_P_XL 0x08
|
||||
#define PressureREF_P_L 0x09
|
||||
#define PressureREF_P_H 0x0A
|
||||
#define PressureWho_Am_I 0x0F
|
||||
#define PressureRES_CONF 0x10
|
||||
#define PressureCTRL_REG1 0x20
|
||||
#define PressureCTRL_REG2 0x21
|
||||
#define PressureCTRL_REG3 0x22
|
||||
#define PressureCTRL_REG4 0x23
|
||||
#define PressureINT_CFG 0x24
|
||||
#define PressureINT_SOURCE 0x25
|
||||
#define PressureSTATUS_REG 0x27
|
||||
#define PressurePRESS_POUT_XL 0x28
|
||||
#define PressurePRESS_OUT_L 0x29
|
||||
#define PressurePRESS_OUT_H 0x2A
|
||||
#define PressureTEMP_OUT_L 0x2B
|
||||
#define PressureTEMP_OUT_H 0x2C
|
||||
#define PressureFIFO_CTRL 0x2E
|
||||
#define PressureFIFO_STATUS 0x2F
|
||||
#define PressureTHS_P_L 0x30
|
||||
#define PressureTHS_P_H 0x21
|
||||
#define PressureRPDS_L 0x39
|
||||
#define PressureRPDS_H 0x3A
|
||||
|
||||
void PressureDebug(){
|
||||
//debug information that might be useful for this sensor
|
||||
|
||||
byte PressureID = 0;
|
||||
|
||||
Wire1.beginTransmission(PressureAddr);
|
||||
Wire1.write(PressureWho_Am_I);
|
||||
Wire1.endTransmission();
|
||||
Wire1.requestFrom(PressureAddr,1);
|
||||
PressureID = Wire1.read();
|
||||
Serial.println("PressureID");
|
||||
Serial.println(PressureID, HEX);
|
||||
|
||||
Wire1.beginTransmission(PressureAddr);
|
||||
Wire1.write(0x27);
|
||||
Wire1.endTransmission();
|
||||
Wire1.requestFrom(PressureAddr,1);
|
||||
PressureID = Wire1.read();
|
||||
Serial.println("Status");
|
||||
Serial.println(PressureID, BIN);
|
||||
|
||||
}
|
||||
|
||||
void PressureSetup(){
|
||||
//set up the pressure sensor for reading. Always do this on boot, otherwise the device will be in power down mode.
|
||||
|
||||
byte PressureResolution = 0;
|
||||
byte PressureConfig = 0;
|
||||
byte PressureTempL = 0;
|
||||
byte PressureTempH = 0;
|
||||
|
||||
//Serial.println("Setting up pressure sensor");
|
||||
|
||||
|
||||
//Setup Resolution
|
||||
Wire1.beginTransmission(PressureAddr);
|
||||
Wire1.write(PressureRES_CONF);
|
||||
Wire1.write(B00001111);
|
||||
Wire1.endTransmission();
|
||||
Wire1.requestFrom(PressureAddr,1);
|
||||
PressureResolution = Wire1.read();
|
||||
Serial.println(PressureResolution, BIN);
|
||||
|
||||
|
||||
//Setup Control Registers
|
||||
Wire1.beginTransmission(PressureAddr);
|
||||
Wire1.write(PressureCTRL_REG1);
|
||||
Wire1.write(B10010011); //activate device, set resolution to 1hz, enable BDU
|
||||
Wire1.endTransmission();
|
||||
Wire1.requestFrom(PressureAddr,1);
|
||||
PressureConfig = Wire1.read();
|
||||
Serial.println(PressureConfig, BIN);
|
||||
}
|
||||
|
||||
float PressureTemp(){
|
||||
//Read the Temperature using the pressure sensor, borrowed from the LPS Library by ryantm
|
||||
// go find the full thing at https://github.com/pololu/lps-arduino
|
||||
Wire1.beginTransmission(PressureAddr);
|
||||
// assert MSB to enable register address auto-increment
|
||||
Wire1.write(PressureTEMP_OUT_L | (1 << 7));
|
||||
Wire1.endTransmission();
|
||||
Wire1.requestFrom(PressureAddr, (byte)2);
|
||||
|
||||
while (Wire1.available() < 2);
|
||||
|
||||
uint8_t tl = Wire1.read();
|
||||
uint8_t th = Wire1.read();
|
||||
|
||||
// combine bytes
|
||||
int16_t PresTempRaw = (th << 8 | tl);
|
||||
return 42.5 + (float)PresTempRaw / 480;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -69,4 +69,92 @@ void VbiasSet(int Vbias) {
|
|||
|
||||
|
||||
|
||||
|
||||
//bus scanning routines for debugging, borrowed from code on Arduino.cc
|
||||
// according to the i2c scanner by Nick Gammon
|
||||
// http://www.gammon.com.au/forum/?id=10896
|
||||
|
||||
void busscan0()
|
||||
{
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning I2C Bus 0...");
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.print(address,HEX);
|
||||
Serial.println(" !");
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4)
|
||||
{
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
|
||||
delay(5000); // wait 5 seconds for next scan
|
||||
}
|
||||
|
||||
|
||||
|
||||
void busscan1()
|
||||
{
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning I2C Bus 1...");
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire1.beginTransmission(address);
|
||||
error = Wire1.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.print(address,HEX);
|
||||
Serial.println(" !");
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4)
|
||||
{
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
|
||||
delay(5000); // wait 5 seconds for next scan
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue