Saving two values into arduino uno EEPROM - arduino

I am looking to save pulse and SPO2 readings from the cooking hacks e-health sensor platform (link below) onto my Arduino Uno's EEPROM then remove the health shield and use an Ethernet shield to move the data. A piece of my code is as below:
#include <PinChangeInt.h>
#include <eHealth.h>
#include <EEPROM.h>
int cont =0;
int addr =0;
int BPM;
int SPO2;
void loop() {
Serial.print("PRbpm:");
Serial.print(e.health.getBPM);
BPM =eHealth.getBPM();
Serial.print("%SPo2 :);
Serial.print(eHealth.getOxygenSaturation());
SPO2 =eHealth.getOxygenSaturation();
Serial.print("\n");
Serial.println("===========");
EEPROM.write(0,eHealth.getBPM());
delay(500);
}
The two readings I am trying to save and then load onto another sketch are BPM and SPO2, does the line:
EEPROM.write(0,eHealth.getBPM());
make sense and how would I also save and send the second reading SPO2?
Any help appreciated or any knowledge of why my idea will not work also appreciated, thanks.
Cooking-hacks sensor platform

EEPROM.write(0,BPM);
EEPROM.write(1,SPO2);

Related

How can i use SPI on Arduino Due to communicate with AD7124-8 correctly

I want to read data from AD7124-8 with arduino Due via SPI. I found several libraries, but i dont get anything back from my ADC modul. By using an Oscilloscope i made sure my Arduino sends data via MOSI, SCK and CS work aswell. Just the MISO dataline doesnt get me anything back.
I first used this library (https://github.com/NHBSystems/NHB_AD7124), but decided to use a much easier Code to just make sure everything is working fine. I tried to to talk to the communication register to get the ID of my device from the ID register. You can find the registers on page 39 of the datasheet :https://www.analog.com/en/products/ad7124-8.html .
Im sending 0x00 and 0x05 to get back the 0x14 which should be the correct ID. Just zeros arriving (shown by Osci).
I found a solution in a Forum, but im not sure about why it differs with the data sheet:
https://ez.analog.com/data_converters/precision_adcs/f/q-a/24046/ad7124-8-for-arduino-due
when i use it the code stops running at the Line: value[0] = SPI.transfer(0x00);
They send 0x40 at the beginning, too.
Here my simple Code:
#include <SPI.h>
// Physical Pins
const int csPin = 10;
int value[7] {0};
void setup() {
Serial.begin (9600);
pinMode(10,OUTPUT);
SPI.begin(10);
SPI.setClockDivider(10, 128);
SPI.setDataMode(SPI_MODE3);
}
void loop() {
digitalWrite(csPin, LOW);
//SPI.transfer(csPin, 0x00);
SPI.transfer(csPin,0x00,SPI_CONTINUE); //Tell Communication Register you are going to read ID register
SPI.transfer(csPin,0x05);
//SPI.transfer(csPin,0x00); //Get data from Communication Register
delay(1);
digitalWrite(csPin, HIGH);
delay(1);
Serial.print(value[0],HEX);
}
I hope someone can help me out.
Greetings
First of all, this may not related to your question, but you are using old SPI methods setClockDivider(), setDataMode(), and setBitOrder() that has been deprecated since 2014. It is recommend to use use transactional SPI APIs which I have some explanation here.
Secondly, according to datasheet page 85, to access the ID register, you send one-byte to specific which register that you need to communicate with. Your code send two bytes, 0x00 and 0x05, which is incorrect.
Furthermore, based on page 78 of the datasheet, in order to read a register, bit 6 need to be set to 1 for a read operation, and 0 for a write operation.
Try the following code:
#include <SPI.h>
#define READ_REGISTER 0B01000000 // bit 6 set to 1 for read operation
#define ID_REGISTER 0x05
const int csPin = 10;
void setup() {
Serial.begin (9600);
digitalWrite(csPin, HIGH); // set csPin to HIGH to prevent false trigger
pinMode(csPin,OUTPUT);
SPI.begin();
}
void loop() {
SPI.beginTransaction(SPISettings(84000000/128, MSBFIRST, SPI_MODE3));
digitalWrite(csPin, LOW);
SPI.transfer(READ_REGISTER | ID_REGISTER); // read register 5
uint8_t id = SPI.transfer(0x00); // get the id
digitalWrite(csPin, HIGH);
SPI.endTransaction();
Serial.print(id,HEX);
}

my serial port did not show my sensor data properly

Hey i got a bit problem with my Arduino and sensor
Here is what i tried ;
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
#include <SoftwareSerial.h>
SoftwareSerial blue(0,1);
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550;
PulseSensorPlayground pulseSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
blue.begin(9600);
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat.
pulseSensor.setThreshold(Threshold);
pulseSensor.begin();
}
void loop() {
// put your main code here, to run repeatedly:
int myBPM = pulseSensor.getBeatsPerMinute();
if(myBPM>200){
myBPM-100;
}
if (pulseSensor.sawStartOfBeat()) {
Serial.println(myBPM);
blue.println(myBPM);
}
delay(10);
}
this code I got from the example library and modified it.
so i want to send data to my android using Bluetooth but this sensor kinda ticked me off because whenever i use it with my HC-06 Bluetooth module it suddenly got a hearth beat without i even touching it and it just sends so much data ignoring the delay I set.
I just need to slowly sending data just like a second but the data didn't show up
so anyone can help?
I read your code and I noticed this piece of code
if(myBPM > 200){ myBPM - 100; }
that is poorly written if (I understand correctly) you want to check the size of myBPM and if it is larger than 200 then it should be subtracted 100.
it should be:
myBPM = myBPM - 100; not myBPM - 100;
I hope my answer will help you. Have a nice day!

Arduino practice with a DHT 11 temp/humid sensor but having an issue

I am currently sending temperature data from the sensor to an lcd 16x2 display I am able to display the temperature but it keeps alternating from the temperature to -999 it displays the data like this too in the Serial monitor when I print it their too. Can anyone tell me what I'm doing wrong?
Here is my sloppy code sorry it's not properly noted but I'm still grasping the basics.
#include <LiquidCrystal.h>
#include <dht.h>
dht DHT;
#define DHT11_PIN 12
LiquidCrystal lcd(13 ,11,10,9,8,7,6 ,5 , 4, 3 );
void setup(){
Serial.begin(9600);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
lcd.begin(16,2);
lcd.print("Temperature =");
lcd.setCursor(0,2);
lcd.print(DHT.temperature);
delay(1000);
}
first of all, just as an advice, place the lcd.begin() function in the setup function, and not in the loop, because the lcd must be initialized just one time.
Then, reading the datasheet of the DHT11 sensor I found that the minimum time between two sensor readings should be at least 2 seconds, so probably changing delay(1000) to delay(2000) should do the job.

Using the SD card with the Seeed Studio TFT Touch Shield 2.0

I just purchased Seeed's TFT Touch Shield 2.0 for Arduino, but I cannot seem to figure out how to access the SD card while maintaining the ability to draw to the screen. The tutorials and documentation are quite insubstantial (for me), and most questions on the product site seem to be directed to the same wiki page, which doesn't explain anything about the SD interface, other than what example file draws bitmaps from the card.
I've used the SD interface with the Ethernet Shield before, but it's been a long time since then, so I can't quite remember the ins and outs. From my old code, it seems that, for normal usage of the SD library, you simply do:
#include <SD.h>
void setup()
{
pinMode(4, OUTPUT);
if (!SD.begin(4))
{
//Fail
}
... //Open file, read, etc.
}
To use the TFT screen normally (with the exception of drawing bitmaps), you do as such:
#include <SD.h>
#include <TFTv2.h>
#include <SPI.h>
void setup()
{
TFT_BL_ON; //Enable Backlight
Tft.TFTinit(); //Initialize TFT Screen
Tft.drawCircle(100, 100, 30,YELLOW); //Draw
}
In the provided example program on the wiki page for drawing bitmaps from the SD card, the setup code looks like this:
#include <SD.h>
#include <TFTv2.h>
#include <SPI.h>
#define chipSelect 4
Sd2Card card;
void setup()
{
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);
TFT_CS_HIGH;
pinMode(chipSelect,OUTPUT);
digitalWrite(chipSelect,HIGH);
Serial.begin(38400);
SPI.begin();
Tft.TFTinit();
//SPI.setClockDivider(SPI_CLOCK_DIV4);
//SDcard_info();
/**/
DDRB |= 0x04;
card.init(SPI_FULL_SPEED,chipSelect);
if(!SD.begin(chipSelect))//SPI_QUARTER_SPEED,
{ //53 is used as chip select pin
Serial.println("failed!");
while(1);
}
Serial.println("SD OK!");
Tft.setCol(0,239);
Tft.setPage(0,319);
Tft.sendCMD(0x2c);//start to write to display ram
TFT_BL_ON;
}
In loop() bitmaps are sequentially opened with SD.open(), drawn, and then closed with SD.close().
What I assume is happening is that pins 11 through 13 are set to input for some SPI-related reason, the TFT chip select 'enabled' mode is set to HIGH, and then the screen is subsequently enabled. Serial moniter is started, followed by SPI, and then the TFT. After those things happen, it does something unknown to me, starts the card, and then uses the standard card initialization method. It finishes up by preparing to draw the bitmaps and sends this 'command 0x2c', which is used frequently in the underlying libraries to "start to write to display ram".
The problem is that I have tried initializing the TFT and SD card using this code, and then attempted to draw graphics as shown in my second example, but this did not work. I need to be able to read bytes from the SD card, and then be able to draw simple graphics on-screen, and repeat.
So my question is: Is anyone who has used this shield before or has experience with this able to explain how one should go about writing the code to allow usage of both the SD card and screen or how the initialization and SPI processes work to make this possible?
Thanks for your answers in advance!
(Also, if this is not the correct SE site for this question, please feel free to migrate it accordingly.)
The solution to this problem is quite simple actually, and I must have been doing something wrong when I had combined the source files before.
The initialization code looks like this:
#include <SD.h>
#include <TFTv2.h>
#include <SPI.h>
Sd2Card card;
void setup()
{
pinMode(11, INPUT); //Pin mode changes; not sure what for
pinMode(12, INPUT);
pinMode(13, INPUT);
TFT_CS_HIGH; //Something with chipselect and the TFT
pinMode(4, OUTPUT); //Set chipselect pin to OUTPUT
digitalWrite(4, HIGH); //Set chipselect mode
SPI.begin(); //Start SPI
Tft.TFTinit(); //Initialize the TFT
TFT_BL_ON; //Turn on the TFT Backlight
Serial.begin(9600); //Start serial output
DDRB |= 0x04; //Some sort of processor IO port?
if(!SD.begin(4)) //Start the SD card
{
while(true) { } //Fail
}
}
It is basically the bitmap initialization code, with the extra TFT commands at the end left out. After this, both the screen and the SD card are usable, as was desired.

Freescale Pressure Sensor MPL3115A2 I2C communication with Arduino

Does anyone have experience with the MPL3115A2 Freescale I2C pressure sensor?
I need to use it in a project concerning Arduino UNO r3, but I can't get communication between them correctly. Here is my code:
#include <Wire.h>
void setup(){
Serial.begin(9600);
/*Start communication */
Wire.begin();
// Put sensor as in Standby mode
Wire.beginTransmission((byte)0x60); //0x60 is sensor address
Wire.write((byte)0x26); //ctrl_reg
Wire.write((byte)0x00); //reset_reg
Wire.endTransmission();
delay(10);
// start sensor as Barometer Active
Wire.beginTransmission((byte)0x60);
Wire.write((byte)0x26); //ctrl_reg
Wire.write((byte)0x01); //start sensor as barometer
Wire.endTransmission();
delay(10);
}
void getdata(byte *a, byte *b, byte *c){
Wire.beginTransmission(0x60);
Wire.write((byte)0x01); // Data_PMSB_reg address
Wire.endTransmission(); //Stop transmission
Wire.requestFrom(0x60, 3); // "please send me the contents of your first three registers"
while(Wire.available()==0);
*a = Wire.read(); // first received byte stored here
*b = Wire.read(); // second received byte stored here
*c = Wire.read(); // third received byte stored here
}
void loop(){
byte aa,bb,cc;
getdata(&aa,&bb,&cc);
Serial.println(aa,HEX); //print aa for example
Serial.println(bb,HEX); //print bb for example
Serial.println(cc,HEX); //print cc for example
delay(5000);
}
The data I receive is : 05FB9 (for example). When I change the register address (see Wire.write((byte)0x01); // Data_PMSB_reg address), I expect the data to change, but it doesn't! Can you explain this to me?
You can find the documentation and datasheets on the NXP website.
I can't properly understand how they communicate with each other. I got communication between Arduino and some other I2C sensors with same communication protocol without any problem.
Your problem is likely due to the fact that the Freescale part requires Repeated-Start I2C communication to do reads. The original Arduino two-wire library (TWI library used by Wire), did not support Repeated-Start.
I know this because I had to rewrite TWI for one of my projects to support Repeated-Start (interrupt driven, both Master and Slave). Unfortunately I've never gotten around to uploading my code, but someone else did essentially the same thing here (at least for Master which is what you need):
http://dsscircuits.com/articles/arduino-i2c-master-library.html
Lose the Wire library and use their I2C library instead.

Resources