/* fifoV3
22/12/23
This should run on any board as it does not require any pins
Just the Serial monitor.
FIFO First in First Out
This sketch controls 2 different arrays.
Although I could have used a 2 dimensional integer array it would have used
more memeory than the seperate ineteger and byte arrays.
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Adafruit_SHT31.h"
// Name des Sensors (sht31)
Adafruit_SHT31 sht31 = Adafruit_SHT31();
// Data wire is plugged into pin 23 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a OneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass OneWire reference to Dallas Temperature
DallasTemperature sensors(&oneWire);
byte readPosition;
byte writePosition;
byte byteSwap;
// (48%) OK
int fifoBuffer[256];
byte fifoByteBuffer[256];
unsigned long currentMillis;
unsigned long writeMillis;
unsigned long readMillis;
int randomWriteTiming;
void setup() {
Serial.begin(9600);
Serial.println("fifoV3");
pinMode(ONE_WIRE_BUS, OUTPUT);
sensors.begin(); //Start up the library
//this loop fills the first 30 items in the fifo buffer to prefill with some info.
for (int q = 0; q < 30; q++) {
fifoBuffer[writePosition] = q;
if(byteSwap > 0){
byteSwap = 0;
}else{
byteSwap = 1;
}
fifoByteBuffer[writePosition] = byteSwap;
writePosition++;
}
// SHT35 starten, im Fehlerfall Meldung anzeigen
Serial.println("SHT35 Test");
if (!sht31.begin()) Serial.println("Sensor SHT35 nicht gefunden");
else Serial.println("Sensor SHT35 gefunden!");
}
void loop() {
currentMillis = millis();
if (currentMillis - readMillis >= 1000) { //1 second spacing for read
readMillis = currentMillis;
if (readPosition != writePosition) {
Serial.print("R ");
Serial.print(fifoBuffer[readPosition]);
Serial.print(":");
Serial.println(fifoByteBuffer[readPosition]);
readPosition++;
/* Not required any more, using a byte and a 256 element array
* The line readPosition++; leads to
* 253
* 254
* 255
* 0....goes back to Zero as the byte value has been exceeded
* 1
* 2
*
if (readPosition > 99) {
readPosition = 0;
}
*/
}
}
if (currentMillis - writeMillis >= randomWriteTiming) {
writeMillis = currentMillis;
randomWriteTiming = random(500, 2000); //generate random times to write between 0.5 and 2 seconds
fifoBuffer[writePosition] = writePosition;
if(byteSwap > 0){
byteSwap = 0;
}else{
byteSwap = 1;
}
fifoByteBuffer[writePosition] = byteSwap;
Serial.print("W ");
Serial.print(fifoBuffer[writePosition]);
Serial.print(":");
Serial.println(fifoByteBuffer[writePosition]);
writePosition++;
}
// Sensorwerte erfassen (Luftfeuchtigkeit, Temperatur)
String Temperatur = String(sht31.readTemperature());
String Luftfeuchtigkeit = String(sht31.readHumidity());
// . durch , ersetzen
Temperatur.replace(".", ",");
Luftfeuchtigkeit.replace(".", ",");
// Temperatur anzeigen
Serial.println("Temperatur: " + Temperatur + "°C");
// Luftfeuchtigkeit anzeigen
Serial.println("Luftfeuchtigkeit: " + Luftfeuchtigkeit + "%");
Serial.println("------------------------");
}Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1
Loading
ds18b20
ds18b20