Create windlogger2.ino

Create windlogger2.ino

added sensor array to this sketch

// Date and time functions using RX8025 RTC connected via I2C and Wire lib

#include <Wire.h>

#include "DS3231.h"
#include <SDI12.h>
#include <Fat16.h>
#include <Fat16util.h>

#include <L3G4200D.h>
#include <ADXL345.h>
#include <HMC5883L.h>
#include <Adafruit_BMP085.h>
#include <Sensirion.h>

float heading;

//10DOF
L3G4200D gyro;
ADXL345 accel;
HMC5883L compass;
Adafruit_BMP085 bmp;

//sht75
const uint8_t dataPin =  9;              // SHT serial data
const uint8_t sclkPin =  8;              // SHT serial clock
const uint32_t TRHSTEP   = 5000UL;       // Sensor query period
Sensirion sht = Sensirion(dataPin, sclkPin);
uint16_t rawData;
float temperature;
float humidity;
float dewpoint;
byte measActive = false;
byte measType = TEMP;
unsigned long trhMillis = 0;             // Time interval tracking

//Linear Thermistor
int inPin = A2;
double inputValue;
double tempInCelsius;
double slope = -0.1302;    //Place calibrated thermistor slope here in degC/V
double offset = 89.113;        //Place calibrated thermistor offset here in degC

#define DATAPIN 3         // change to the proper pin
SDI12 mySDI12(DATAPIN);
String myCommand = "0R0!";

SdCard card;
Fat16 file;

bool newline = false;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode) {
    PgmPrint("SD error: ");
    Serial.println(card.errorCode, HEX);
  }
  while(1);
}

DS3231 RTC; //Create the R8025 object

void setup ()
{
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
    mySDI12.begin();

    pinMode(inPin, INPUT);
    gyro.enableDefault();
    accel.set_bw(ADXL345_BW_12);
    compass = HMC5883L();
    compass.SetScale(1.3); // Set the scale of the compass.
    compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
    bmp.begin();
}

void loop ()
{

      // initialize the SD card
    if (!card.init()) error("card.init");

    // initialize a FAT16 volume
    if (!Fat16::init(&card)) error("Fat16::init");

    char name[] = "DATALOG.CSV";
    // clear write error
    file.writeError = false;

    // O_CREAT - create the file if it does not exist
    // O_APPEND - seek to the end of the file prior to each write
    // O_WRITE - open for write
    if (!file.open(name, O_CREAT | O_APPEND | O_WRITE))
        error("error opening file");

  mySDI12.sendCommand(myCommand);
  delay(100);           // wait a while for a response
     printTime();
      Serial.print(',');
      file.print(',');
     printLT();
      Serial.print(',');
      file.print(',');
     printSHT();
      Serial.print(',');
      file.print(',');
//     printGryo();
//      Serial.print(',');
//      file.print(',');
//     printAccel();
//      Serial.print(',');
//      file.print(',');
//     printBMP();
//      Serial.print(',');
//      file.print(',');
//     printHeading();
//      Serial.print(',');
//      file.print(',');
  while(mySDI12.available()){    // write the response to the screen
    char i = mySDI12.read();
    if (i != '\n') {
      Serial.write(i);
      file.write(i);
    }
  }
    Serial.println();

    if (!file.close())
        error("error closing file");

    delay(900);
}

void printTime () {
  DateTime now = RTC.now(); //get the current date-time
    char timestp[15];
    sprintf(timestp, "%04d-%02d-%02d-%02d:%02d:%02d", now.year(), now.month(), now.date(), now.hour(), now.minute(), now.second());
    file.print(timestp);
    Serial.print(timestp);
}

//linear thermistor
void printLT() {
  inputValue = analogRead(inPin);
  tempInCelsius = inputValue * slope + offset;
  Serial.print(tempInCelsius);
  file.print(tempInCelsius);
  Serial.print("C");
  file.print("C");
}

//sht75
void printSHT() {
  sht.meas(TEMP, &rawData, BLOCK);        // Start temp measurement
  temperature = sht.calcTemp(rawData);     // Convert raw sensor data
  sht.meas(HUMI, &rawData, BLOCK);      // Start humidity measurement
  humidity = sht.calcHumi(rawData, temperature); // Convert raw sensor data
  dewpoint = sht.calcDewpoint(humidity, temperature);
  Serial.print(temperature);
  file.print(temperature);
  Serial.print("C,");
  file.print("C,");
  Serial.print(humidity);
  file.print(humidity);
  Serial.print("%,");
  file.print("%,");
  Serial.print(dewpoint);
  file.print(dewpoint);
  Serial.print("C");
  file.print("C");
}

// gryo values
void printGryo() {
  gyro.read();
  Serial.print((int)gyro.g.x);
  Serial.print(",");
  Serial.print((int)gyro.g.y);
  Serial.print(",");
  Serial.println((int)gyro.g.z);
  file.print((int)gyro.g.x);
  file.print(",");
  file.print((int)gyro.g.y);
  file.print(",");
  file.println((int)gyro.g.z);
}

// accel values
void printAccel() {
  double acc_data[3];
  accel.get_Gxyz(acc_data);
  float length = 0.;
  for(int i = 0; i < 3; i++){
    length += (float)acc_data[i] * (float)acc_data[i];
    Serial.print(acc_data[i]);
    Serial.print(",");
    file.print(acc_data[i]);
    file.print(",");
  }
  length = sqrt(length);
  Serial.print(length);
  file.print(length);
}

// bmp values
void printBMP(){
  Serial.print(bmp.readTemperature());
  Serial.print(",");
  Serial.print(bmp.readPressure());
  Serial.print(",");
  Serial.print(bmp.readAltitude());
}

// compass heading
void printHeading(){
  // Retrive the raw values from the compass (not scaled).
  MagnetometerRaw raw = compass.ReadRawAxis();
  // Retrived the scaled values from the compass (scaled to the configured scale).
  MagnetometerScaled scaled = compass.ReadScaledAxis();

  // Values are accessed like so:
  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)

  // Calculate heading when the magnetometer is level, then correct for signs of axis.
  heading = atan2(scaled.YAxis, scaled.XAxis);

  float declinationAngle = 0.0457;
  heading += declinationAngle;

  // Correct for when signs are reversed.
  if(heading < 0)
    heading += 2*PI;

  // Check for wrap due to addition of declination.
  if(heading > 2*PI)
    heading -= 2*PI;

  // Convert radians to degrees for readability.
  heading = heading * 180/M_PI;
  Serial.print(heading);
  file.print(heading);
}

error: pathspec 'sensor-array/windlogger2.ino' did not match any file(s) known to git


Example for Setting variable value

Example for Setting variable value

error: pathspec 'Software/Examples/Cing' did not match any file(s) known to git
error: pathspec 'Examples/Setting_variable/Setting_variable.ino' did not match any file(s) known to git


Add DynamixelBus unit test sketch

Add DynamixelBus unit test sketch

#include <HalfDuplexHardwareSerial.h>

/**
 * Unit tests for DynamixelBus class.
 *
 */

#include <DynamixelBus.h>

#include <ArduinoUnit.h>

DynamixelBus dynamixel(Serial1);

/*
 * CAUTION!
 * These tests will run using the first servo found using the discovery method.
 * The servo limits, position, speed and torque limit values are modified
 * in many of the tests. The tests may be safely run using a freestanding
 * servo, but care must be taken when running the tests if the servo is attached
 * brackets or assemblies that restrict the movement of the servo.
 * The following macros may be used to establish limits for the test suite.
 * However, test failures may leave the servo configured in a state different from that
 * proir to executing the tests. You can try re-running the test suite to restore
 * the defaults given below if the test failures occurred as a result of
 * communication errors or alarm conditions.
 */
#define DEFAULT_MIN_ANGLE (512 - 64)
#define DEFAULT_MAX_ANGLE (512 + 64)
#define DEFAULT_TORQUE_LIMIT 256
#define DEFAULT_GOAL_POSITION 512
#define DEFAULT_GOAL_SPEED 256
#define DEFAULT_PUNCH 32

#define DEFAULT_MIN_VOLTAGE 6000
#define DEFAULT_MAX_VOLTAGE 14000

/*
 * Set these macros to TRUE or FALSE to control whether a test is included.
 * Each test reduces the amount of memory for program execution,
 * so you will generally need to disable most tests to successfully
 * compile the sketch while also leaving enough RAM to run the tests.
*/
#define TRUE 1
#define FALSE 0

#define TEST_PING                   FALSE
#define TEST_MODELNUMBER_AX12       FALSE
#define TEST_FIRMWAREVERSION_AX12   FALSE
#define TEST_DISCOVER               FALSE
#define TEST_BAUD_RATE              FALSE
#define TEST_RETURN_DELAY_TIME      FALSE
#define TEST_ANGLE_LIMITS           FAKSE
#define TEST_TEMPERATURE_LIMIT      FALSE
#define TEST_VOLTAGE_LIMITS         TRUE
#define TEST_INITIAL_TORQUE_LIMIT   FALSE
#define TEST_STATUS_RETURN_LEVEL    FALSE
#define TEST_ALARM_LED              FALSE
#define TEST_ALARM_SHUTDOWN         FALSE
#define TEST_TORQUE_ENABLE          FALSE
#define TEST_LED                    FALSE
#define TEST_COMPLIANCE_MARGINS     FALSE
#define TEST_COMPLIANCE_SLOPES      FALSE
#define TEST_GOAL_POSITION          FALSE
#define TEST_GOAL_SPEED             FALSE
#define TEST_TORQUE_LIMIT           FALSE
#define TEST_PRESENT_STATE          FALSE
#define TEST_REGISTERED_INSTRUCTION FALSE
#define TEST_MOVING                 FALSE
#define TEST_LOCK                   FALSE
#define TEST_PUNCH                  FALSE

// Global state variable required in multiple tests
uint8_t servoId = 0;
uint16_t servoMinAngle = DEFAULT_MIN_ANGLE; // +90
uint16_t servoMaxAngle = DEFAULT_MAX_ANGLE; // -90

void setup() {
  delay(1000);

  Serial.begin(115200);
  while(Serial.read() == -1);

  Serial.println("DynamixelBus Unit Tests\n");

  dynamixel.begin(DynamixelBus::k1000000);

  // Must call this method to update internal state even
  // if the initial baud rate is incorrect as the DynamixelBus
  // initially assumes a state of kRespondToNone.
  dynamixel.setStatusReturnLevel(0xFE,DynamixelBus::kRespondToAll);

  Serial.println("Starting servo discovery...\n");
  dynamixel.setMaxRetriesOnError(4);
  size_t count = dynamixel.discover(&servoId,1,3);
  if (count == 0 || servoId == 0) {
    Serial.println("### No tests can be run because no servos were found!");
    return;
  }
  Serial.println("Servo discovery complete.\n");

  // Bump up the retries to account for occasional bouts
  // communication errors that arise for some, as yet, unkown reason.
  dynamixel.setMaxRetriesOnError(8);

  // The discovery operation will have saved the servo's baud rate
  DynamixelBus::BaudRate baud;
  dynamixel.getBaudRate(servoId,baud);

  Serial.print(F("Servo #"));
  Serial.print(servoId);
  Serial.print(F(" baud="));
  Serial.println(baud);

  // Switch to the servo's baud rate
  dynamixel.begin(baud);

  // Uncomment the following two statements to change the servo baud rate
  // dynamixel.setBaudRate(servoId,DynamixelBus::k115200);
  // dynamixel.begin(DynamixelBus::k115200);

  // Instruct the servo to respond to all instructions for testing purposes
  dynamixel.setStatusReturnLevel(servoId,DynamixelBus::kRespondToAll);
  dynamixel.setLed(servoId,false);

  // Enable torque so the servo can move as required in some tests
  dynamixel.setTorqueLimit(servoId,DEFAULT_TORQUE_LIMIT);
  dynamixel.setAngleLimits(servoId,DEFAULT_MIN_ANGLE,DEFAULT_MAX_ANGLE);
  dynamixel.setGoalPosition(servoId,DEFAULT_GOAL_POSITION);
  dynamixel.setGoalSpeed(servoId,DEFAULT_GOAL_SPEED);
  dynamixel.setTorqueEnable(servoId,true);

  // Uncomment the following to reset triggers to desired values
  // dynamixel.setAlarmLedTriggers(servoId,DynamixelBus::kOverloadError | DynamixelBus::kTemperatureLimitError);
  // dynamixel.setAlarmShutdownTriggers(servoId,DynamixelBus::kOverloadError | DynamixelBus::kTemperatureLimitError);

  // Now capture the current state of the servo..
  // (No guarantee every one of these calls will succeed!)

  uint16_t servoModelNumber = 12;
  uint8_t servoFirmwareVersion = 0;
  uint16_t servoReturnDelayTime = 0;
  uint8_t servoTemperatureLimit = 0;
  uint16_t servoLowVoltageLimit = 0;
  uint16_t servoHighVoltageLimit = 0;
  uint16_t servoInitialTorqueLimit = 0;
  uint8_t servoAlarmLedTriggers = 0;
  uint8_t servoAlarmShutdownTriggers = 0;
  bool servoTorqueEnable = false;
  uint8_t servoCWComplianceMargin = 0;
  uint8_t servoCCWComplianceMargin = 0;
  uint8_t servoCWComplianceSlope = 0;
  uint8_t servoCCWComplianceSlope = 0;
  uint16_t servoGoalPosition = 0;
  uint16_t servoGoalSpeed = 0;
  uint16_t servoTorqueLimit = 0;
  uint16_t servoPresentPosition = 0;
  uint16_t servoPresentSpeed = 0;
  uint16_t servoPresentLoad = 0;
  uint8_t servoPresentLoadDirection = 0;
  uint16_t servoPresentVoltage = 0;
  uint8_t servoPresentTemperature = 0;
  bool servoLock = false;
  uint16_t servoPunch = 0;

  dynamixel.getModelNumber(servoId,servoModelNumber);
  dynamixel.getFirmwareVersion(servoId,servoFirmwareVersion);
  dynamixel.getReturnDelayTime(servoId,servoReturnDelayTime);
  dynamixel.getAngleLimits(servoId,servoMinAngle,servoMaxAngle);
  dynamixel.getTemperatureLimit(servoId,servoTemperatureLimit);
  dynamixel.getVoltageLimits(servoId,servoLowVoltageLimit,servoHighVoltageLimit);
  dynamixel.getInitialTorqueLimit(servoId,servoInitialTorqueLimit);
  dynamixel.getAlarmLedTriggers(servoId,servoAlarmLedTriggers);
  dynamixel.getAlarmShutdownTriggers(servoId,servoAlarmShutdownTriggers);
  dynamixel.getTorqueEnable(servoId,servoTorqueEnable);
  dynamixel.getComplianceMargins(servoId,servoCWComplianceMargin,servoCCWComplianceMargin);
  dynamixel.getComplianceSlopes(servoId,servoCWComplianceSlope,servoCCWComplianceSlope);
  dynamixel.getGoalPosition(servoId,servoGoalPosition);
  dynamixel.getGoalSpeed(servoId,servoGoalSpeed);
  dynamixel.getTorqueLimit(servoId,servoTorqueLimit);
  dynamixel.getLock(servoId,servoLock);
  dynamixel.getPunch(servoId,servoPunch);
  dynamixel.getPresentPosition(servoId,servoPresentPosition);
  dynamixel.getPresentSpeed(servoId,servoPresentSpeed);
  dynamixel.getPresentLoad(servoId,servoPresentLoadDirection,servoPresentLoad);
  dynamixel.getPresentVoltage(servoId,servoPresentVoltage);
  dynamixel.getPresentTemperature(servoId,servoPresentTemperature);

  Serial.println(F("Executing tests using following servo:\n"));
  Serial.print(F("Servo ID = "));
  Serial.println(servoId);
  Serial.print(F(": Baud Rate index = "));
  Serial.println(baud);
  Serial.print(F(": Model Number = "));
  Serial.println(servoModelNumber);
  Serial.print(F(": Firmware Version = "));
  Serial.println(servoFirmwareVersion);
  Serial.print(F(": Return Delay Time (usec) = "));
  Serial.println(servoReturnDelayTime);
  Serial.print(F(": Angle Limits: cw = "));
  Serial.print(servoMinAngle);
  Serial.print(F("/1023 ("));
  Serial.print((servoMinAngle * 300L / 1023));
  Serial.print(F("°)  ccw = "));
  Serial.print(servoMaxAngle);
  Serial.print(F("/1023 ("));
  Serial.print((servoMaxAngle * 300L / 1023));
  Serial.println("°)");
  Serial.print(F(": Temperature Limit (C) = "));
  Serial.println(servoTemperatureLimit);
  Serial.print(F(": Voltage Limits (V): low = "));
  Serial.print(servoLowVoltageLimit/1000.0);
  Serial.print(F(" high = "));
  Serial.println(servoHighVoltageLimit/1000.0);
  Serial.print(F(": Initial Torque Limit (EEPROM) = "));
  Serial.print(servoInitialTorqueLimit);
  Serial.println(F("/1023"));
  Serial.print(F(": Alarm LED Errors: "));
  if (servoAlarmLedTriggers & DynamixelBus::kInstructionError) Serial.print(F("instruction, "));
  if (servoAlarmLedTriggers & DynamixelBus::kOverloadError) Serial.print(F("overload, "));
  if (servoAlarmLedTriggers & DynamixelBus::kChecksumError) Serial.print(F("checksum, "));
  if (servoAlarmLedTriggers & DynamixelBus::kRangeError) Serial.print(F("range, "));
  if (servoAlarmLedTriggers & DynamixelBus::kTemperatureLimitError) Serial.print(F("temperature, "));
  if (servoAlarmLedTriggers & DynamixelBus::kAngleLimitError) Serial.print(F("angle, "));
  if (servoAlarmLedTriggers & DynamixelBus::kVoltageLimitError) Serial.print(F("voltage"));
  Serial.println();
  Serial.print(F(": Alarm Shutdown Errors: "));
  if (servoAlarmShutdownTriggers & DynamixelBus::kInstructionError) Serial.print(F("instruction, "));
  if (servoAlarmShutdownTriggers & DynamixelBus::kOverloadError) Serial.print(F("overload, "));
  if (servoAlarmShutdownTriggers & DynamixelBus::kChecksumError) Serial.print(F("checksum, "));
  if (servoAlarmShutdownTriggers & DynamixelBus::kRangeError) Serial.print(F("range, "));
  if (servoAlarmShutdownTriggers & DynamixelBus::kTemperatureLimitError) Serial.print(F("temperature, "));
  if (servoAlarmShutdownTriggers & DynamixelBus::kAngleLimitError) Serial.print(F("angle, "));
  if (servoAlarmShutdownTriggers & DynamixelBus::kVoltageLimitError) Serial.print(F("voltage"));

  Serial.println();
  Serial.print(F(": Torque Enable = "));
  Serial.println(servoTorqueEnable ? F("true") : F("false"));
  Serial.print(F(": Compliance Margins: cw = "));
  Serial.print(servoCWComplianceMargin);
  Serial.print(F(" ccw = "));
  Serial.println(servoCCWComplianceMargin);
  Serial.print(F(": Compliance Slopes: cw = "));
  Serial.print(servoCWComplianceSlope);
  Serial.print(F(" ccw = "));
  Serial.println(servoCCWComplianceSlope);
  Serial.print(F(": Goal Position = "));
  Serial.print(servoGoalPosition);
  Serial.println(F("/1023"));
  Serial.print(F(": Goal Speed = "));
  Serial.print(servoGoalSpeed);
  Serial.println(F("/1023"));
  Serial.print(F(": Torque Limit (RAM) = "));
  Serial.print(servoTorqueLimit);
  Serial.println(F("/1023"));
  Serial.print(F(": Present Position = "));
  Serial.println(servoPresentPosition);
  Serial.print(F(": Present Speed = "));
  Serial.println(servoPresentSpeed);
  Serial.print(F(": Present Load = "));
  Serial.print(servoPresentLoad);
  Serial.print(F(" direction = "));
  Serial.println(servoPresentLoadDirection);
  Serial.print(F(": Present Voltage (Mv) = "));
  Serial.println(servoPresentVoltage);
  Serial.print(F(": Present Temperature (C) = "));
  Serial.println(servoPresentTemperature);
  Serial.print(F(": Lock = "));
  Serial.println(servoLock ? F("true") : F("false"));
  Serial.print(F(": Punch = "));
  Serial.print(servoPunch);
  Serial.println(F("/1023"));
  Serial.println();

  // Select tests (that are included by the preprocessor)
  Test::exclude("ModelNumber_*");
  switch (servoModelNumber) {
#if TEST_MODELNUMBER_AX12 == TRUE
    case 12: Test::include("ModelNumber_AX12"); break;
#endif
  }

}

#if TEST_PING == TRUE
test(Ping) {
  assertTrue(dynamixel.ping(servoId));
  assertFalse(dynamixel.ping(253));
}
#endif

#if TEST_MODELNUMBER_AX12 == TRUE
test(ModelNumberAX12) {
  uint16_t getModelNumber = 0;
  assertEqual(dynamixel.getModelNumber(servoId,getModelNumber),DynamixelBus::kOk);
  assertEqual(getModelNumber,12);
}
#endif

#if TEST_FIRMWAREVERSION_AX12 == TRUE
test(FirmwareVersion_AX12) {
  uint8_t getVersion = 0;
  assertEqual(dynamixel.getFirmwareVersion(servoId,getVersion),DynamixelBus::kOk);
  assertMore(getVersion,0);
}
#endif

#if TEST_DISCOVER == TRUE
test(Discover) {
  uint8_t id;
  size_t count = dynamixel.discover(&id,1,servoId+1);
  assertTrue(count > 0);
  assertEqual(servoId,id);
}
#endif

#if TEST_BAUD_RATE == TRUE
test(BaudRate) {
  DynamixelBus::BaudRate currentBaud = DynamixelBus::kUnknown;
  dynamixel.getBaudRate(servoId,currentBaud);
  DynamixelBus::BaudRate putBaud = DynamixelBus::k115200;
  if (currentBaud == putBaud) putBaud = DynamixelBus::k57600;
  assertEqual(dynamixel.setBaudRate(servoId,putBaud),DynamixelBus::kOk);
  DynamixelBus::BaudRate getBaud = DynamixelBus::kUnknown;
  uint8_t error = dynamixel.getBaudRate(servoId,getBaud);
  if (error) {
    dynamixel.setBaudRate(servoId,currentBaud);
    fail();
  }
  assertTrue(putBaud == getBaud);
  dynamixel.setBaudRate(servoId,currentBaud);
}
#endif

#if TEST_RETURN_DELAY_TIME == TRUE
test(ReturnDelayTime) {
  uint16_t currentReturnDelayTime = 0;
  assertEqual(dynamixel.getReturnDelayTime(servoId,currentReturnDelayTime),DynamixelBus::kOk);
  //Serial.print("current return delay time: ");
  //Serial.println(currentReturnDelayTime);
  uint16_t putReturnDelayTime = (currentReturnDelayTime + 256) / 2;
  assertEqual(dynamixel.setReturnDelayTime(servoId,putReturnDelayTime),DynamixelBus::kOk);
  //Serial.print("put return delay time: ");
  //Serial.println(putReturnDelayTime);
  uint16_t getReturnDelayTime = -1;
  assertEqual(dynamixel.getReturnDelayTime(servoId,getReturnDelayTime),DynamixelBus::kOk);
  //Serial.print("get return delay time: ");
  //Serial.println(getReturnDelayTime);
  assertTrue(putReturnDelayTime == getReturnDelayTime);
  assertEqual(dynamixel.setReturnDelayTime(servoId,currentReturnDelayTime),DynamixelBus::kOk);
}
#endif

#if TEST_ANGLE_LIMITS == TRUE
test(AngleLimits)
{

  uint16_t currentMinAngleLimit = 0;
  uint16_t currentMaxAngleLimit = 0;

  assertEqual(dynamixel.getAngleLimits(servoId,currentMinAngleLimit,currentMaxAngleLimit),DynamixelBus::kOk);

  uint16_t offset = (currentMaxAngleLimit - currentMinAngleLimit) / 3;
  uint16_t putMinAngleLimit = currentMinAngleLimit + offset;
  uint16_t putMaxAngleLimit = currentMaxAngleLimit - offset;

  assertEqual(dynamixel.setAngleLimits(servoId,putMinAngleLimit,putMaxAngleLimit),DynamixelBus::kOk);

  uint16_t getMinAngleLimit = 0;
  uint16_t getMaxAngleLimit = 0;

  delay(18);

  assertEqual(dynamixel.getAngleLimits(servoId,getMinAngleLimit,getMaxAngleLimit),DynamixelBus::kOk);
  assertTrue(getMinAngleLimit == putMinAngleLimit);
  assertTrue(getMaxAngleLimit == putMaxAngleLimit);

  assertEqual(dynamixel.setAngleLimits(servoId,currentMinAngleLimit,currentMaxAngleLimit),DynamixelBus::kOk);

}
#endif

#if TEST_TEMPERATURE_LIMIT == TRUE
test(TemperatureLimit) {
  uint8_t currentTemperatureLimit = 0;
  assertEqual(dynamixel.getTemperatureLimit(servoId,currentTemperatureLimit),DynamixelBus::kOk);

  // This value will probaby trigger the temperature limit alarms if enabled
  uint8_t putTemperatureLimit = currentTemperatureLimit / 2;
  assertEqual(dynamixel.setTemperatureLimit(servoId,putTemperatureLimit),DynamixelBus::kOk);

  uint8_t getTemperatureLimit = 0;
  assertEqual(dynamixel.getTemperatureLimit(servoId,getTemperatureLimit),DynamixelBus::kOk);
  assertEqual(putTemperatureLimit,getTemperatureLimit);

  assertEqual(dynamixel.setTemperatureLimit(servoId,currentTemperatureLimit),DynamixelBus::kOk);

}
#endif

#if TEST_VOLTAGE_LIMITS == TRUE
test(VoltageLimits) {
  uint16_t currentMinVoltageLimit = 0;
  uint16_t currentMaxVoltageLimit = 0;

  assertEqual(dynamixel.getVoltageLimits(servoId,currentMinVoltageLimit,currentMaxVoltageLimit),DynamixelBus::kOk);

  uint16_t offset = (currentMaxVoltageLimit - currentMinVoltageLimit) / 3;
  uint16_t putMinVoltageLimit = ((currentMinVoltageLimit + offset) / 100) * 100;
  uint16_t putMaxVoltageLimit = ((currentMaxVoltageLimit - offset) / 100) * 100;

  assertEqual(dynamixel.setVoltageLimits(servoId,putMinVoltageLimit,putMaxVoltageLimit),DynamixelBus::kOk);

  uint16_t getMinVoltageLimit = 0;
  uint16_t getMaxVoltageLimit = 0;

  assertEqual(dynamixel.getVoltageLimits(servoId,getMinVoltageLimit,getMaxVoltageLimit),DynamixelBus::kOk);
  assertEqual(putMinVoltageLimit,getMinVoltageLimit);
  assertEqual(putMaxVoltageLimit,getMaxVoltageLimit);

  assertEqual(dynamixel.setVoltageLimits(servoId,DEFAULT_MIN_VOLTAGE,DEFAULT_MAX_VOLTAGE),DynamixelBus::kOk);
}
#endif

#if TEST_INITIAL_TORQUE_LIMIT == TRUE
test(InitialTorqueLimit) {
  uint16_t currentInitialTorqueLimit = 0;
  assertEqual(dynamixel.getInitialTorqueLimit(servoId,currentInitialTorqueLimit),DynamixelBus::kOk);

  uint16_t putInitialTorquLimit = currentInitialTorqueLimit / 2;
  assertEqual(dynamixel.setInitialTorqueLimit(servoId,putInitialTorquLimit),DynamixelBus::kOk);

  uint16_t getInitialTorquLimit = 0;
  assertEqual(dynamixel.getInitialTorqueLimit(servoId,getInitialTorquLimit),DynamixelBus::kOk);
  assertEqual(putInitialTorquLimit,getInitialTorquLimit);

  assertEqual(dynamixel.setInitialTorqueLimit(servoId,currentInitialTorqueLimit),DynamixelBus::kOk);
}
#endif

#if TEST_STATUS_RETURN_LEVEL == TRUE
test(StatusReturnLevel)
{
  uint8_t error = 0;
  uint8_t currentStatusReturnLevel = DynamixelBus::kRespondToNone;
  uint8_t putStatusReturnLevel = DynamixelBus::kRespondToRead;
  uint8_t getStatusReturnLevel = DynamixelBus::kRespondToNone;

  assertEqual(dynamixel.getStatusReturnLevel(servoId,currentStatusReturnLevel),DynamixelBus::kOk);
  assertEqual(dynamixel.setStatusReturnLevel(servoId,putStatusReturnLevel),DynamixelBus::kOk);
  assertEqual(dynamixel.getStatusReturnLevel(servoId,getStatusReturnLevel),DynamixelBus::kOk);
  assertEqual(putStatusReturnLevel,getStatusReturnLevel);

  putStatusReturnLevel = DynamixelBus::kRespondToAll;
  getStatusReturnLevel = DynamixelBus::kRespondToNone;

  assertEqual(dynamixel.setStatusReturnLevel(servoId,currentStatusReturnLevel),DynamixelBus::kOk);
  assertEqual(dynamixel.getStatusReturnLevel(servoId,getStatusReturnLevel),DynamixelBus::kOk);
  assertEqual(getStatusReturnLevel,currentStatusReturnLevel);
}
#endif

#if TEST_ALARM_LED == TRUE
test(AlarmLed) {
  uint8_t currentAlarmLed = 0;
  uint8_t putAlarmLed = 0x7F;
  assertEqual(dynamixel.getAlarmLedTriggers(servoId,currentAlarmLed),DynamixelBus::kOk);
  assertEqual(dynamixel.setAlarmLedTriggers(servoId,putAlarmLed),DynamixelBus::kOk);
  uint8_t getAlarmLed = 0;
  assertEqual(dynamixel.getAlarmLedTriggers(servoId,getAlarmLed),DynamixelBus::kOk);
  assertEqual(putAlarmLed,getAlarmLed);
  assertEqual(dynamixel.setAlarmLedTriggers(servoId,currentAlarmLed),DynamixelBus::kOk);
}
#endif

#if TEST_ALARM_SHUTDOWN == TRUE
test(AlarmShutdown) {
  uint8_t currentAlarmShutdown = 0;
  uint8_t putAlarmShutdown = 0x7F;
  assertEqual(dynamixel.getAlarmShutdownTriggers(servoId,currentAlarmShutdown),DynamixelBus::kOk);
  assertEqual(dynamixel.setAlarmShutdownTriggers(servoId,putAlarmAlarmShutdown),DynamixelBus::kOk);
  uint8_t getAlarmShutdown = 0;
  assertEqual(dynamixel.getAlarmShutdownTriggers(servoId,getAlarmShutdown),DynamixelBus::kOk);
  assertEqual(putAlarmShutdown,getAlarmShutdown);
  assertEqual(dynamixel.setAlarmShutdownTriggers(servoId,currentAlarmShutdown),DynamixelBus::kOk);
}
#endif

#if TEST_TORQUE_ENABLE == TRUE
test(TorqueEnable) {
  assertEqual(dynamixel.setTorqueEnable(servoId,false),DynamixelBus::kOk);
  bool getTorqueEnable = true;
  assertEqual(dynamixel.getTorqueEnable(servoId,getTorqueEnable),DynamixelBus::kOk);
  assertTrue(getTorqueEnable);
  assertEqual(dynamixel.setTorqueEnable(servoId,true),DynamixelBus::kOk);
}
#endif

#if TEST_LED == TRUE
test(Led) {
  bool currentLed = false;
  assertEqual(dynamixel.getLed(servoId,currentLed), DynamixelBus::kOk);
  for (size_t i=0; i < 10; i++) {
    assertEqual(dynamixel.setLed(servoId,i & 0x1), DynamixelBus::kOk);
    delay(100);
  }
  assertEqual(dynamixel.setLed(servoId,!currentLed), DynamixelBus::kOk);
  bool getLed = false;
  assertEqual(dynamixel.getLed(servoId,getLed), DynamixelBus::kOk);
  assertTrue(currentLed != getLed);
  assertEqual(dynamixel.setLed(servoId,currentLed), DynamixelBus::kOk);
}
#endif

#if TEST_COMPLIANCE_MARGINS == TRUE
test(ComplianceMargins) {

  uint8_t currentCWComplianceMargin = 0;
  uint8_t currentCCWComplianceMargin = 0;
  assertEqual(dynamixel.getComplianceMargins(servoId,currentCWComplianceMargin,currentCCWComplianceMargin),DynamixelBus::kOk);

  uint8_t putCWComplianceMargin = 24;
  uint8_t putCCWComplianceMargin = 12;
  assertEqual(dynamixel.setComplianceMargins(servoId,putCWComplianceMargin,putCCWComplianceMargin),DynamixelBus::kOk);

  assertEqual(dynamixel.setTorqueLimit(servoId,0x3FF),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalSpeed(servoId,0x3FF),DynamixelBus::kOk);
  assertEqual(dynamixel.setPunch(servoId,0xFF),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalPosition(servoId,DEFAULT_GOAL_POSITION),DynamixelBus::kOk);
  delay(100);
  bool isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  uint16_t targetPosition = servoMinAngle; // + putCWComplianceMargin;

  assertEqual(dynamixel.setGoalPosition(servoId,targetPosition),DynamixelBus::kOk);
  delay(100);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  uint16_t actualPosition = 0;

  assertEqual(dynamixel.getPresentPosition(servoId,actualPosition),DynamixelBus::kOk);
  int offset = actualPosition - targetPosition;
  offset = abs(offset);
  assertLessOrEqual(offset,putCWComplianceMargin);

  targetPosition = servoMaxAngle;// - putCCWComplianceMargin;

  assertEqual(dynamixel.setGoalPosition(servoId,targetPosition),DynamixelBus::kOk);
  delay(100);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  assertEqual(dynamixel.getPresentPosition(servoId,actualPosition),DynamixelBus::kOk);
  offset = actualPosition - targetPosition;
  offset = abs(offset);
  assertLessOrEqual(offset,putCCWComplianceMargin);

  assertEqual(dynamixel.setTorqueLimit(servoId,DEFAULT_TORQUE_LIMIT),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalSpeed(servoId,DEFAULT_GOAL_SPEED),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalPosition(servoId,DEFAULT_GOAL_POSITION),DynamixelBus::kOk);
  assertEqual(dynamixel.setPunch(servoId,DEFAULT_PUNCH),DynamixelBus::kOk);

  delay(100);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  assertEqual(dynamixel.setComplianceMargins(servoId,currentCWComplianceMargin,currentCCWComplianceMargin),DynamixelBus::kOk);
}
#endif

#if TEST_COMPLIANCE_SLOPES == TRUE
test(ComplianceSlopes) {

  uint8_t currentCWComplianceSlope = 0;
  uint8_t currentCCWComplianceSlope = 0;
  assertEqual(dynamixel.getComplianceSlopes(servoId,currentCWComplianceSlope,currentCCWComplianceSlope),DynamixelBus::kOk);

  uint8_t putCWComplianceSlope = 0xFE;
  uint8_t putCCWComplianceSlope = 0xFE;
  assertEqual(dynamixel.setComplianceSlopes(servoId,putCWComplianceSlope,putCCWComplianceSlope),DynamixelBus::kOk);

  uint8_t getCWComplianceSlope = 0x0;
  uint8_t getCCWComplianceSlope = 0x0;
  assertEqual(dynamixel.getComplianceSlopes(servoId,getCWComplianceSlope,getCCWComplianceSlope),DynamixelBus::kOk);
  assertEqual(putCWComplianceSlope,getCWComplianceSlope);
  assertEqual(putCCWComplianceSlope,getCCWComplianceSlope);

  assertEqual(dynamixel.setTorqueLimit(servoId,0x3FF),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalSpeed(servoId,0x3FF),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalPosition(servoId,DEFAULT_GOAL_POSITION),DynamixelBus::kOk);
  delay(100);
  bool isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  uint16_t targetPosition = servoMinAngle;
  assertEqual(dynamixel.setGoalPosition(servoId,targetPosition),DynamixelBus::kOk);
  delay(100);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  targetPosition = servoMaxAngle;
  assertEqual(dynamixel.setGoalPosition(servoId,servoMaxAngle),DynamixelBus::kOk);
  delay(100);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  assertEqual(dynamixel.setTorqueLimit(servoId,DEFAULT_TORQUE_LIMIT),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalSpeed(servoId,DEFAULT_GOAL_SPEED),DynamixelBus::kOk);
  assertEqual(dynamixel.setGoalPosition(servoId,DEFAULT_GOAL_POSITION),DynamixelBus::kOk);
  delay(100);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  assertEqual(dynamixel.setComplianceSlopes(servoId,currentCWComplianceSlope,currentCCWComplianceSlope),DynamixelBus::kOk);
}
#endif

#if TEST_GOAL_POSITION == TRUE
test(GoalPosition)
{
  uint16_t putPosition = servoMinAngle;
  uint16_t getPosition = 0;

  if (putPosition < servoMinAngle) putPosition = servoMinAngle;
  else if (putPosition > servoMaxAngle) putPosition = servoMaxAngle;

  assertEqual(dynamixel.setGoalPosition(servoId,putPosition),DynamixelBus::kOk);
  delay(100);
  bool isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  assertEqual(dynamixel.getGoalPosition(servoId,getPosition),DynamixelBus::kOk);
  assertEqual(putPosition,getPosition);

  assertEqual(dynamixel.setGoalPosition(servoId,512),DynamixelBus::kOk);
  delay(100);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }
}
#endif

#if TEST_GOAL_SPEED == TRUE
test(GoalSpeed)
{
  uint16_t putSpeed = millis() & 0x3FF;
  uint16_t getSpeed = 0;

  assertEqual(dynamixel.setGoalSpeed(servoId,putSpeed),DynamixelBus::kOk);
  assertEqual(dynamixel.getGoalSpeed(servoId,getSpeed),DynamixelBus::kOk);
  assertEqual(putSpeed,getSpeed);
}
#endif

#if TEST_TORQUE_LIMIT == TRUE
test(TorqueLimit) {
  uint16_t currentTorqueLimit = 0;
  assertEqual(dynamixel.getTorqueLimit(servoId,currentTorqueLimit),DynamixelBus::kOk);

  uint16_t putTorquLimit = currentTorqueLimit / 2;
  assertEqual(dynamixel.setTorqueLimit(servoId,putTorquLimit),DynamixelBus::kOk);

  uint16_t getTorquLimit = 0;
  assertEqual(dynamixel.getTorqueLimit(servoId,getTorquLimit),DynamixelBus::kOk);
  assertEqual(putTorquLimit,getTorquLimit);

  assertEqual(dynamixel.setTorqueLimit(servoId,currentTorqueLimit),DynamixelBus::kOk);
}
#endif

#if TEST_PRESENT_STATE == TRUE
test(PresentState) {
  uint16_t servoPresentPosition = 0;
  uint16_t servoPresentSpeed = 0;
  uint16_t servoPresentLoad = 0;
  uint8_t servoPresentLoadDirection = 0;
  uint16_t servoPresentVoltage = 0;
  uint8_t servoPresentTemperature = 0;
  assertEqual(dynamixel.getPresentPosition(servoId,servoPresentPosition),DynamixelBus::kOk);
  assertEqual(dynamixel.getPresentSpeed(servoId,servoPresentSpeed),DynamixelBus::kOk);
  assertEqual(dynamixel.getPresentLoad(servoId,servoPresentLoadDirection,servoPresentLoad),DynamixelBus::kOk);
  assertEqual(dynamixel.getPresentVoltage(servoId,servoPresentVoltage),DynamixelBus::kOk);
  assertEqual(dynamixel.getPresentTemperature(servoId,servoPresentTemperature),DynamixelBus::kOk);
}
#endif

#if TEST_REGISTERED_INSTRUCTION == TRUE
test(RegisteredInstruction) {
  fail();
}
#endif

#if TEST_MOVING == TRUE
test(Moving) {

  bool isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  assertEqual(dynamixel.setGoalPosition(servoId,DEFAULT_MIN_ANGLE),DynamixelBus::kOk);
  delay(10);
  assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
  assertTrue(isMoving);
  delay(100);
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }

  assertEqual(dynamixel.setGoalPosition(servoId,DEFAULT_GOAL_POSITION),DynamixelBus::kOk);
  isMoving = true;
  while(isMoving) {
    assertEqual(dynamixel.getMoving(servoId,isMoving),DynamixelBus::kOk);
    delay(100);
  }
}
#endif

#if TEST_LOCK == TRUE
test(Lock) {

}
#endif

#if TEST_PUNCH == TRUE
test(Punch) {

  uint16_t currentPunch = 0;
  assertEqual(dynamixel.getPunch(servoId,currentPunch),DynamixelBus::kOk);

  uint16_t putPunch = DEFAULT_PUNCH / 2;
  assertEqual(dynamixel.setPunch(servoId,putPunch),DynamixelBus::kOk);

  uint16_t getPunch = 0;
  assertEqual(dynamixel.getPunch(servoId,getPunch),DynamixelBus::kOk);
  assertEqual(putPunch,getPunch);

  assertEqual(dynamixel.setPunch(servoId,DEFAULT_PUNCH),DynamixelBus::kOk);
}
#endif

void loop() {
  if (servoId != 0) Test::run();
}

error: pathspec 'examples/DynamixelBusTest/DynamixelBusTest.ino' did not match any file(s) known to git


Create dragino_sht11_mqtt.ino

Create dragino_sht11_mqtt.ino

#include <Process.h>
#include "MQTTclient.h"
#include "DHT.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SHT1x.h>
#define dataPin  2
#define clockPin 3
SHT1x sht1x(dataPin, clockPin);

#define ONE_WIRE_BUS_PIN A3
float  tempC2 = 0;
float  tempC3 = 0;
unsigned long time;

OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);

#define MQTT_HOST "190.97.168.236"
#define DHTPIN A0
//#define DHTPIN2 A1

#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);
//DHT dht2(DHTPIN2, DHTTYPE);

char message_buff[100];
char message_buff2[100];
char message[256];
String id_sensor = "prueba12";

float t2;

void setup() {

  Serial.begin(9600);
  Bridge.begin();
  mqtt.begin(MQTT_HOST, 1883);
  dht.begin();
  sensors.begin();
  //sensors.setResolution(probe01, 10);

  mqtt.subscribe("rr/temp", someEvent);

}

void loop() {
 delay(2000);
  float h = sht1x.readHumidity();
  float t = sht1x.readTemperatureC();

 sensors.requestTemperatures();

 tempC2 = sensors.getTempCByIndex(0),4;
 //tempC2 = sensors.getTempC(probe01);

 if (isnan(t) || isnan(h)) {
    Serial.println("Failed to from DHT");
    mqtt.publish("error/temp/SHT","error de lectura NAN SHT" );
  }

  else if (t == 0.00 && h == 0.00)

  {
    Serial.println("Failed to from DHT");
    mqtt.publish("error/temp/SHT","error de lectura SHT" );
  }

    else if (tempC2 == -127.00)

  {
    Serial.println("Failed to from DHT");
    mqtt.publish("error/temp/ds18b20","error de lectura ds18b20 -127.00" );
  }

  else {

   if (millis() > (time + 15000)) {
       time = millis();

 String pubString = "" + String(t) + "," + String(tempC2) + "," + String(h) + "," + id_sensor + "";
   pubString.toCharArray(message_buff, pubString.length()+1);
   mqtt.publish("rr/temp",message_buff );

   }
   else{

  mqtt.monitor();
   }
  }

}

void someEvent(const String& topic, const String& subtopic, const String& message) {

}

error: pathspec 'rr/dragino_sht11_mqtt.ino' did not match any file(s) known to git


init: simple arduino file for testing that serial i/o works

void setup() {
    Serial.begin(9600);
    pinMode(13, OUTPUT);
}

void loop() {
    Serial.print("test");
    Serial.println("LINE");
    delay(500);
}

void serialEvent() {
    while (Serial.available()) {

        char ch = (char)Serial.read();

        Serial.print(ch);
        Serial.println(ch);

        if (ch == '\n') {
            Serial.print("Line detected");
        } else if (ch == '1') {
            digitalWrite(13, HIGH);
        } else if (ch == '0') {
            digitalWrite(13, LOW);
        }
    }
}

error: pathspec 'exampleFile/exampleFile.ino' did not match any file(s) known to git


add example

add example

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/hideakitai/FPSTimer.git/'


Stop doing math on volatile!

Stop doing math on volatile!

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/spoollord/MyOurWeather.git/'


COH-12: fixing library-version-checking code

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Denzo77/OTRadioLink.git/'


Program controlling the Bedrooms functionality

/*
 * Main Control Team
 * Arduino Control: Sultan Ibrahim Ibrahim
 * commented commands are used for debugging
 * NRF24l01+ connections:
    MOSI is connected to the digital pin 11
    MISO is connected to the digital pin 12
    SCK is connected to the digital pin 13
    CE  is connected to the digital pin 9
    CSN is connected to the digital pin 10
    IRQ is not used or connected
*/

#include "DHT.h"
//#include <AccelStepper.h>
#include <Stepper.h>
#include <SPI.h>                    //the nRF24 modules uses SIP protocol so we must include SPI library
#include "RF24.h"                   //for all nRF24 modules
#include <printf.h>                 //to print nRF24 module detailes if needed
#include "StopWatch.h"              //to allow using stopwatch function for time calculation

//defines
#define STEPS_PER_MOTOR_REVOLUTION 32
#define HALFSTEP   8      //interface 8 means a 4 wire half stepper
#define motorPin1  2      // IN1 on the ULN2003 driver 1
#define motorPin2  3      // IN2 on the ULN2003 driver 1
#define motorPin3  4      // IN3 on the ULN2003 driver 1
#define motorPin4  5      // IN4 on the ULN2003 driver 1

#define DHTPIN 7          // what digital pin we're connected to
#define DHTTYPE DHT11     // DHT 11

//constants
const byte pipes[][6] = {"MSTR2", "SLV2"};  //this is SLV2 and Rpi is MSTR
const char ACK[40]    = "ACK";               //ACK to be sent to RPi to inform that messease we recived and/or arduino is online
const char UC[40]     = "No such command";   //to send to Rpi if RPI didn't understand the command that was send (if Rpi didn't understand then the command was corrupted on sending)
const char NACK[40]   = "NACK";              //NACK to be sent to RPi to inform that arduino failed to do the command requested

const byte photoResistorPin = A0;            //the pin the photoresistor reads from
const byte relayPin         = 6;             //the control pin for the relay to turn light on and off
const byte tempPin          = A1;            //the pin for temperature sensor
const byte tempFanPin       = A2;            //the pin connected to the fan to enable or disable it
const byte tempHeaterPin    = A3;            //the pin connected to the heater to enable or disable it
const byte PIRPin           = A4;            //the pin connected to PIR sensors digital output read pin for pir  (active high: 0 => no living being was detected, 1 => there is a living being within range)
//const byte PIRAlarmPin      = 7;             //the pin connected to the alarm(buzzer or led) of PIR sensors
const byte tvPin            = 8;             //the pin connected to the tv (turn on and off the tv)
const byte contactPin       = A5;            //the pin connected to the garage contact to indicate whether it's open or closed

//data
bool serial_state = 0;
char data[40] = "";                 //to store incoming string from RPi
float tempCelsius;                  //temperature in celcius
float tempReference = 25;           //to store the desired temperature the user wants
int lightState;                     //to store whether the light is turned on or off
int PIRState;                       //to store the PIR sensors digital reading
int fanState;                       //to store whether the fan is turned on or off
int heaterState;                    //to store whether the heater is turned on or off
int garageState;                    //to store whether the garage is open or closed
float photoResistorVoltage;         //to store the voltage from the photoresistor
float onReference  = 3.0;           //referenc voltage to turn light off if below it
byte retry;                         //to print the number of retries that the program will attempt to send ACK to Rpi before giving up
//int startPosition;
int tvState;                        //to store TV state, either on or off
float humidityOutside;              //to store the percentage of the humidity measured outside the house
float temperatureOutside;           //to store the temperature in celsius outside the house

bool timeout = false;               //to know when time out and stop the wait for something to happen and move on
bool ret = false;                   //the return of the attempt to write all data to Rpi (0: failed, 1: success)
bool garageRetern;

StopWatch SW;                       //initialize stopwatch
RF24 radio(9, 10);                  //initialize nrf24 module with CE connected to D9 and CSN connected to D10
//AccelStepper stepper(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
Stepper stepper(STEPS_PER_MOTOR_REVOLUTION, motorPin1, motorPin3, motorPin2, motorPin4);
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);                       //initialize with data rate of 115200 bit per second
  //SPI.setClockDivider(SPI_CLOCK_DIV2);
  //Serial.println("entered setup");
  radio.begin();                              //initialize nrf24 connection
  printf_begin();                             //initialize print radion details
  radio.setRetries(15, 15);                   //set to retry writing (if failed) to max of 15 times with a wait of 15*250us between each retry
  radio.openWritingPipe(pipes[1]);            //open channel on address SLV1 to write to master
  radio.openReadingPipe(1, pipes[0]);         //open channel on address 'MSTR' to read from master
  radio.startListening();                     //set the nrf24 mode to listen for incoming messages

  //Serial.println("setting up motor");
  stepper.setSpeed(400);
  /*
  stepper.setMaxSpeed(1000.0);
  stepper.setAcceleration(100.0);
  stepper.setSpeed(200);
  */

  dht.begin();

  //Serial.println("setting pinmode");
  //setting the mode of input and output pins according to the purpose of usage
  pinMode(tempPin,INPUT);
  pinMode(tempFanPin,OUTPUT);                 //analog pin
  pinMode(tempHeaterPin,OUTPUT);              //analog pin
  pinMode(photoResistorPin,INPUT);
  pinMode(relayPin,OUTPUT);
  pinMode(PIRPin,INPUT);
  //pinMode(PIRAlarmPin,OUTPUT);                // no need to set its mode to input since it's input by default (analog pin) but we'll do it anyways
  pinMode(tvPin,OUTPUT);
  pinMode(contactPin,INPUT);

  //Serial.println("just before findstart()");
  //findStart();                               //when uncommented causes problem with tempReference, check stepper control in general
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------

void loop() {

  //check is serial bus is connected
  if(Serial){
    serial_state = 1;                    //set the serial state to 1 (true) if serial is connected
  }
  else{
    serial_state = 0;                   //set the serial state to 0 (false) if serial is NOT connected
  }

  if(Serial.available() && serial_state){ //for printing data to serial
    Serial.println("in serial available");
    char c = toupper(Serial.read());      //just to empty serial buffer
    printData();
  }

  if (radio.available()){                     //if data are found in nrf24 buffer
    //Serial.print("available radio !\n");    //for debugging
    receiver();                               //call a function called receiver to handle incoming data (line: 252)
  }

  readVoltage();                              //go ahead and read(update) the values of all sensors (line: 185)

  lightControl();                             //call the function that controls the light (on or off) (line: 102)
  tempControl();                              //call the function that controls the temperature (fan or heater or none) (line: 113)
  PIRControl();                               //call the function that controls the PIR alarm (on or off) (line: 147)
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------

void readVoltage(){
  photoResistorVoltage = analogRead(photoResistorPin);             //read light sensors analog output
  photoResistorVoltage = photoResistorVoltage * (5.0 / 1023.0);    //convert to range 0-5V

  tempCelsius = analogRead(tempPin);                               //store voltage first then convert it to celcius
  tempCelsius = Thermistor(tempCelsius);                           //temperature in celcius (line: 174)

  PIRState  = digitalRead(PIRPin);                                 //read PIR sensors digital output
  garageState = digitalRead(contactPin);                           //read grage state (open or closed)

  temperatureOutside = dht.readTemperature();                      //read temperature in Celsius (the default)
  humidityOutside = dht.readHumidity();

}

//--------------------------------------------------------------------
/*
int findStart(){ //move untill you close the door
  stepper.moveTo(-20000);                                        // +ve means clockwise
  garageState = digitalRead(contactPin);

  while(!garageState){                                          //while the garage door is still open
    stepper.run();
    garageState = digitalRead(contactPin);

    if(stepper.distanceToGo() == 0){
      Serial.println("we couldn't close the door, something is wrong we either the switch or the motor!");
      return 1;
    }
  }

  startPosition = stepper.currentPosition();
  Serial.print("we reached start position at: "); Serial.println(startPosition);
  return 0;
}
*/
//--------------------------------------------------------------------

void lightControl(){
  //light control
  if (photoResistorVoltage < (onReference-1)) {   // some light detected
    digitalWrite(relayPin, LOW);                 //turn light off
    lightState = 0;                               //light is turend off
  }
  else if (photoResistorVoltage >= onReference) { // it's almost dark(according ro sensors datasheet)
    digitalWrite(relayPin, HIGH);                  //turn light on
    lightState = 1;                               //light is turned on
  }// the threshold at which the light is turned on or off is chosen to satisfy the user's preferences
}

void tempControl(){
    //temperature control
  if(tempCelsius >= (tempReference+3)){           //if the current temperature(tempCelsius) is larger than the desired value+margin << the range is chosen to satisfy the user's preferences
    digitalWrite(tempFanPin,HIGH);                //turn on the fan
    fanState = 1;
    digitalWrite(tempHeaterPin,LOW);              //turn off the heater
    heaterState = 0;
  }
  else if(tempCelsius <=(tempReference-3)){       //if the current temperature(tempCelsius) is smaller than the desired value+margin
    digitalWrite(tempHeaterPin,HIGH);             //turn on heater
    heaterState = 1;
    digitalWrite(tempFanPin,LOW);                 //turn off heater
    fanState = 0;
  }
  else if(tempCelsius < (tempReference+2) && tempCelsius > (tempReference-2)){ //current temperature is within desired value + and - margin
    digitalWrite(tempHeaterPin,LOW);              //turn off heater
    heaterState = 0;
    digitalWrite(tempFanPin,LOW);                 //turn off fan
    fanState = 0;
  }
}

void PIRControl(){ //no pin for PIRAlarmPin
  //PIR Control (active high)
  if(PIRState == HIGH){                           //if a lifeform was detected
    //digitalWrite(PIRAlarmPin,HIGH);               //activate the pir alarm
    //PIRAlarm = true;
  }
  else{                                           //otherwise
    //digitalWrite(PIRAlarmPin,LOW);                //stop the pir alarm
    //PIRAlarm = false;
  }
}

void tvControl(bool state){
  digitalWrite(tvPin ,state);
  tvState = state;
}

int garageDoorControl(bool open_close){ //state == 1 means closed
  garageState = digitalRead(contactPin);

  if(!open_close){// open the door if it's closed otherwise, do nothing
    if(garageState){//if the garage is closed
      stepper.step(3000); //change to the number of steps that will open the door
      garageState = digitalRead(contactPin);

      if(garageState){//if garage is still open
        if(serial_state){
          Serial.println("failed to open garage door!");
        }
        return 1;
      }
      else{
        if(serial_state){
          Serial.println("garage door was opened successfully.");
        }
        return 0;
      }
    }
    else{//if the garage door is open
      if(serial_state){
        Serial.println("garage door is aleady open!");
      }
      return 0;
    }
  }

  else if(open_close){// close the door if it's opened otherwise, do nothing
    int count = 0;
    if(!garageState){//if the garage door is open
        while(!garageState && count < 2000){
          stepper.step(-10);
          count++;
          garageState = digitalRead(contactPin);
        }
      }
      if(!garageState){//if garage is still open
        if(serial_state){
          Serial.println("failed to close garage door!");
        }
        return 1;
      }
      else{
        if(serial_state){
          Serial.println("garage door was closed successfully.");
        }
        return 0;
      }
    }
    else{//if the garage door is closed
      if(serial_state){
        Serial.println("garage door is aleady closed!");
      }
      return 0;
    }
}

//--------------------------------------------------------------------

float Thermistor(int RawADC) {                  //convert the temperature sensors read to celsius
  float Temp;
  Temp = log(10000.0*((1024.0/RawADC-1)));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );//Temp in Kelvin
  Temp = Temp - 271.15;                           // Convert Kelvin to Celsius
  Temp = 50- Temp;
  return Temp;
}

//---------------------------------------------------------------------

bool sendData(){//write all the available sensors reading to nRF24 which in turn will sent it to Rpi
    ret = true; //this ret is a logical and between all write function (if a single one write failed then the ret will be 0, and if all succeeded then ret will be 1)
    //ret *= radio.write(&reset,sizeof(reset));
    //Serial.print("photoResistorVoltage send: "); Serial.println(ret);
    ret *= radio.write(&photoResistorVoltage,sizeof(photoResistorVoltage)); //float
    ret *= radio.write(&onReference,sizeof(onReference));
    ret *= radio.write(&lightState,sizeof(lightState));
    ret *= radio.write(&tempCelsius,sizeof(tempCelsius));
    ret *= radio.write(&tempReference,sizeof(tempReference));
    ret *= radio.write(&fanState,sizeof(fanState));
    ret *= radio.write(&heaterState,sizeof(heaterState));
    ret *= radio.write(&PIRState,sizeof(PIRState));
    ret *= radio.write(&garageState,sizeof(garageState));
    ret *= radio.write(&tvState,sizeof(tvState));
    ret *= radio.write(&humidityOutside,sizeof(humidityOutside));
    ret *= radio.write(&temperatureOutside,sizeof(temperatureOutside));
    radio.flush_tx();                                             //flush the tx buffer in case any write failed and something remained
    return ret;                                                   //return the overall result of write attempt
}

void printData(){                                                 //print data (readings) to serial (for debugging)
    if(!serial_state){                                            //check to see if serial bus is not connected
      return;                                                     //if not connected then exit the function. there is no one to print to.
    }
    Serial.println("-------------------------------------------------");
    Serial.print("Photo Resistor Voltage: ");
    Serial.println(photoResistorVoltage);
    Serial.print("Photo Resistor Reference: ");
    Serial.println(onReference);
    Serial.print("light State: ");
    Serial.println(lightState);
    Serial.print("temperature: ");
    Serial.println(tempCelsius);
    Serial.print("temperature Reference: ");
    Serial.println(tempReference);
    Serial.print("fan State: ");
    Serial.println(fanState);
    Serial.print("heater State: ");
    Serial.println(heaterState);
    Serial.print("PIR sensors Digital Output: ");
    Serial.println(PIRState);
    Serial.print("Garage state is: ");
    Serial.println(garageState);
    Serial.print("TV state is: ");
    Serial.println(tvState);
    Serial.print("humidityOutside is: ");
    Serial.println(humidityOutside);
    Serial.print("temperatureOutside is: ");
    Serial.println(temperatureOutside);
    Serial.println("-------------------------------------------------");
}

//--------------------------------------------------------------------

//whenever there is data received this function will be called to handle the data
void receiver(){
  while (radio.available()) {                              //read all data in buffer
    radio.read(&data, sizeof(char[40]));                   //append all byets to string after converting (casting) them to char
  }
  if(serial_state){                                        //check to see if serial bus is connected
    Serial.print("recevied: "); Serial.println(data);      //for debugging
  }
  reply();                                                 //call reply function to respond correctly to the message sent (line: 261)
}

//---------------------------------------------------------------------

void reply(){
  //Serial.println("------------------------------");
  //-----------------------------------------------------------
  if (strcmp(data , "readDataSLV2") == 0) {

    //Serial.println("entered readDataSLV2");
    radio.stopListening();                               //stop listening because we're about to talk
    readVoltage();                                       //read latest sensors values
    ret = sendData();                                    //call senddata function to write all the readings to radio (line: 203)
    radio.startListening();                              //now that we sent the data start listening for respond (or if tha data sending failed then Rpi will probably ask us to send data again)
    printData();                                         //print all readings to serial (line: 222)

    if(!ret){                                           //if sending failed
      if(serial_state){                                 //check to see if serial bus is connected
        Serial.println("Data was NOT sent successfully!");
        Serial.println("-------------------------------------------------");
      }
      return 1;                                         //exit function completlry with error (1 indicate error and 0 indicate success[standard error and success return])
    }
    else{                                               //if the write was successful
      if(serial_state){                                 //check to see if serial bus is connected
        Serial.println("Data was sent successfully");
        Serial.println("-------------------------------------------------");
      }
      return 0;                                         //exit
    }
  }

  //-------------------------------------------------------------
  else if (strcmp(data , "lightReference") == 0){
    if(serial_state){
      Serial.println("entering light ref");               //for debugging
      Serial.println("---------------------------------------");
    }
    //send_light_data:                                  //used in previous version of this communication protocol
    radio.stopListening();                              //stop listening because we're about to talk

    ret = false;
    retry = 0;
    while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
      ret = radio.write(&ACK, sizeof(char[40]));               //of course, this write command already retries sending 15 times with a delay of 15*250us between every retry (like we setup before in setRetries [line: 68])
      radio.flush_tx();                                        //empty the tx buffer in case transmission failed
      retry ++;
      delay(1);
    }

    radio.flush_tx();                                          //empty the tx buffer just to be sure

    if (!ret) {                                               //if  transmission fialed                                               //if transmission fialed
      radio.startListening();                                 //start listening for incoming messages, Rpi might send some other message later on
      //radio.printDetails();
      if(serial_state){                                       //check to see if serial bus is connected
        Serial.println("failed to send ACK");                   //print error message if module failed to send data
        Serial.println("---------------------------------------");
      }
      return 1;                                               //exit with error
      //loop();
    }

    radio.startListening();                                   //start listening for incoming messages, Rpi might send some other message later on
    if(serial_state){                                         //check to see if serial bus is connected
      Serial.print("number of retries: "); Serial.println(retry);
      Serial.println("sent ACK successfully");
    }
    timeout = false;
    SW.start();                                                 //start counting time
    while(!radio.available()){                                  //while no messages in rx buffer
      if(SW.elapsed() > 400){                                   //wait for 400ms for incoming message, used to be 2000ms
        if(serial_state){
          Serial.print("time: "); Serial.println(SW.elapsed());
        }
        timeout = true;                                         //if 400ms passed and still no no icoming message
        break;                                                  //break from the while loop
      }
    }

    SW.stop();                                                 //stop the counter
    SW.reset();                                                //reset the counter

    if(timeout){                                                 //400ms passed without receiving data
      if(serial_state){                                          //check to see if serial bus is connected
        Serial.println("Timeout, no incoming data");             //print error message and then retry sending data
        Serial.println("---------------------------------------");
      }
      //goto send_data;
      return 1;                                               //exit from function with error
    }
    else{                                                     //if no error happened in reading
      radio.read(&onReference, sizeof(float));                //read the on light refrence
      if(serial_state){                                       //check to see if serial bus is connected
        Serial.print("onRef received: "); Serial.println(onReference);
        Serial.println("---------------------------------------");
      }
      return 0;                                               //exit function
    }
  }

  //-------------------------------------------------------------
  else if (strcmp(data , "tempReference") == 0){
    if(serial_state){                                         //check to see if serial bus is connected
      Serial.println("entering temp ref");
      Serial.println("---------------------------------------");
    }
    //send_temp_data:
    radio.stopListening();
    //Serial.println("stopped listening");
    ret = false;
    retry = 0;
    while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
      ret = radio.write(&ACK, sizeof(char[40]));
      radio.flush_tx();
      retry ++;
      delay(1);
    }
    //Serial.println("done writing");
    radio.flush_tx();

    if (!ret) {                                                 //if  transmission fialed
      radio.startListening();
      //radio.printDetails();
      if(serial_state){                                          //check to see if serial bus is connected
        Serial.println("failed to send ACK");                    //print error message if module failed to send data
        Serial.println("---------------------------------------");
      }
      return 1;
      //loop();
    }

    radio.startListening();
    if(serial_state){                                           //check to see if serial bus is connected
      Serial.print("number of retries: "); Serial.println(retry);
      Serial.println("sent ACK successfully");
    }
    timeout = false;
    SW.start();
    while(!radio.available()){                                  //wait for 400ms for incoming message
      if(SW.elapsed() > 2000){
        if(serial_state)
          Serial.print("time: "); Serial.println(SW.elapsed());
        timeout = true;
        break;
      }
    }

    SW.stop();
    SW.reset();

    if(timeout){                                                  //400ms passed without receiving data
      if(serial_state){                                           //check to see if serial bus is connected
       Serial.println("Timeout, no incoming data");               //print error message and then retry sending data
       Serial.println("---------------------------------------");
      }
      //goto send_data;
      return 1;
    }
    else{                                                         //if no error happened in reading
      radio.read(&tempReference, sizeof(float));
      if(serial_state){                                           //check if serial bus is connected
        Serial.print("tempReference received: "); Serial.println(tempReference);
        Serial.println("---------------------------------------");
      }
      return 0;
    }
  }

  //-------------------------------------------------------------
  else if(strcmp(data , "tvOn") == 0){
    if(serial_state){                                           //check to see if serial bus is connected
      Serial.println("entering tvOn");
      Serial.println("---------------------------------------");
    }

    Serial.println("enter tv control");
    tvControl(1);
    Serial.println("exit tv control");
    radio.stopListening();

    ret = false;
    retry = 0;
    while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
      ret = radio.write(&ACK, sizeof(char[40]));
      radio.flush_tx();
      retry ++;
      delay(1);
    }

    radio.flush_tx();

    if (!ret) {                                               //if  transmission fialed
      radio.startListening();
      //radio.printDetails();
      if(serial_state){                                       //check to see if serial bus is connected
        Serial.println("failed to send ACK");                 //print error message if module failed to send data
        Serial.println("---------------------------------------");
      }
      return 1;
      //loop();
    }

    radio.startListening();
    if(serial_state){                                        //check to see if serial bus is connected
      Serial.print("number of retries: "); Serial.println(retry);
      Serial.println("sent ACK successfully");
    }
    //Serial.println("exit tv on");
  }

  //-------------------------------------------------------------
  else if(strcmp(data , "tvOff") == 0){
    if(serial_state){                                        //check to see if serial bus is connected
      Serial.println("entering tvOff");
      Serial.println("---------------------------------------");
    }

    tvControl(0);                                             //turn off tv
    radio.stopListening();

    ret = false;
    retry = 0;
    while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
      ret = radio.write(&ACK, sizeof(char[40]));
      radio.flush_tx();
      retry ++;
      delay(1);
    }

    radio.flush_tx();

    if (!ret) {                                               //if  transmission fialed
      radio.startListening();
      //radio.printDetails();
      if(serial_state){                                       //check to see if serial bus is connected
        Serial.println("failed to send ACK");  //print error message if module failed to send data
        Serial.println("---------------------------------------");
      }
      return 1;
      //loop();
    }

    radio.startListening();
    if(serial_state){                                         //check to see if serial bus is connected
      Serial.print("number of retries: "); Serial.println(retry);
      Serial.println("sent ACK successfully");
    }
  }

  //-------------------------------------------------------------
  else if(strcmp(data , "openGarageDoor") == 0){
    if(serial_state){                                         //check to see if serial bus is connected
      Serial.println("---------------------------------------");
      Serial.println("entering openGarageDoor");
    }

    garageRetern = garageDoorControl(0);                                             //open garage door
    radio.stopListening();

    ret = false;
    retry = 0;

    if(garageRetern == 0){//success
      while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
        ret = radio.write(&ACK, sizeof(char[40]));
        radio.flush_tx();
        retry ++;
        delay(1);
      }
      if (!ret) {                                               //if  transmission fialed
        radio.startListening();
        //radio.printDetails();
        if(serial_state){                                       //check to see if serial bus is connected
          Serial.println("failed to send ACK");                 //print error message if module failed to send data
          Serial.println("---------------------------------------");
        }
        return 1;
        //loop();
      }
    }
    else{//failed
      while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
        ret = radio.write(&NACK, sizeof(char[40]));
        radio.flush_tx();
        retry ++;
        delay(1);
      }

      if (!ret) {                                               //if  transmission fialed
        radio.startListening();
        //radio.printDetails();
        if(serial_state){                                       //check to see if serial bus is connected
          Serial.println("failed to send NACK");                //print error message if module failed to send data
          Serial.println("---------------------------------------");
        }
        return 1;
        //loop();
      }
    }

    radio.flush_tx();

    radio.startListening();
    if(serial_state){                                          //check to see if serial bus is connected
      Serial.print("number of retries: "); Serial.println(retry);
      Serial.println("sent ACK/NACK successfully");
      Serial.println("---------------------------------------");
    }
    return 0;
  }

  //-------------------------------------------------------------
  else if(strcmp(data , "closeGarageDoor") == 0){
    if(serial_state){                                         //check to see if serial bus is connected
    Serial.println("---------------------------------------");
    Serial.println("entering closeGarageDoor");
    }

    garageRetern = garageDoorControl(1);                         //close garage door
    radio.stopListening();

    ret = false;
    retry = 0;

    if(garageRetern == 0){//success
      while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
        ret = radio.write(&ACK, sizeof(char[40]));
        radio.flush_tx();
        retry ++;
        delay(1);
      }
      if (!ret) {                                               //if  transmission fialed
        radio.startListening();
        //radio.printDetails();
        if(serial_state){                                       //check to see if serial bus is connected
          Serial.println("failed to send ACK");                 //print error message if module failed to send data
          Serial.println("---------------------------------------");
        }
        return 1;
        //loop();
      }
    }
    else{//failed
      while (!ret && retry <= 5) {                               //if sending failed retry sending again in 1ms for 5 times
        ret = radio.write(&NACK, sizeof(char[40]));
        radio.flush_tx();
        retry ++;
        delay(1);
      }
      if (!ret) {                                               //if  transmission fialed
        radio.startListening();
        //radio.printDetails();                                  //check to see if serial bus is connected
        if(serial_state){
          Serial.println("failed to send NACK");                 //print error message if module failed to send data
          Serial.println("---------------------------------------");
        }
        return 1;
        //loop();
      }
    }

    radio.flush_tx();

    radio.startListening();
    if(serial_state){                                            //check to see if serial bus is connected
      Serial.print("number of retries: "); Serial.println(retry);
      Serial.println("sent ACK/NACK successfully");
      Serial.println("---------------------------------------");
    }
    return 0;
  }

  else{
    radio.stopListening();                                      //stop listening because we're about to send UC
    if(serial_state){                                           //check to see if serial bus is connected
      Serial.println("---------------------------------------");
      Serial.println("unknown command!");
      Serial.print("command is: "); Serial.print(data); Serial.print(", or: "); Serial.println((atof(data)));
      Serial.println("---------------------------------------");
    }
    radio.write(&UC, sizeof(char[40]));                        //send unknowen command
    radio.startListening();                                    //start listening for incoming messages, Rpi probably will send the command again since we didn't understand it
    //radio.printDetails();
  }
}

error: pathspec 'Microcontroller/Code/Living_Room_Program/Living_Room_Program.ino' did not match any file(s) known to git


DHT22 reading code

DHT22 reading code

#include "DHT.h"

DHT dht(2, DHT22);

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  Serial.print("Temp: ");Serial.print(temperature);Serial.print("\tHum:");Serial.println(humidity);
  delay(3000);
}

error: pathspec 'DHT22.ino' did not match any file(s) known to git


Fixes merge issue on last commit.

Fixes merge issue on last commit.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/dkadish/nuit_blanche_ocean.git/'


Added arduino and serial test code. Deleted a whole bunch of old arduino code. byebye

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jondolan/igvc-software.git/'


added logging sketch for the new us wind sensor testing

// Date and time functions using RX8025 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "DS3231.h"
#include <SDI12.h>
#include <Fat16.h>
#include <Fat16util.h>

#define DATAPIN 3         // change to the proper pin
SDI12 mySDI12(DATAPIN);
String myCommand = "0R0!";

SdCard card;
Fat16 file;

bool newline = false;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode) {
    PgmPrint("SD error: ");
    Serial.println(card.errorCode, HEX);
  }
  while(1);
}

DS3231 RTC; //Create the R8025 object

void setup ()
{

    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
    mySDI12.begin();
}

void loop ()
{

      // initialize the SD card
    if (!card.init()) error("card.init");

    // initialize a FAT16 volume
    if (!Fat16::init(&card)) error("Fat16::init");

    char name[] = "DATALOG.CSV";
    // clear write error
    file.writeError = false;

    // O_CREAT - create the file if it does not exist
    // O_APPEND - seek to the end of the file prior to each write
    // O_WRITE - open for write
    if (!file.open(name, O_CREAT | O_APPEND | O_WRITE))
        error("error opening file");

  mySDI12.sendCommand(myCommand);
  delay(100);           // wait a while for a response
     printTime();
      Serial.print(',');
      file.print(',');
  while(mySDI12.available()){    // write the response to the screen
    char i = mySDI12.read();
    if (i != '\n') {
      Serial.write(i);
      file.write(i);
    }
  }
    Serial.println();
//    file.println();

    if (!file.close())
        error("error closing file");

    delay(900);
}

void printTime () {
  DateTime now = RTC.now(); //get the current date-time
    char timestp[15];
    sprintf(timestp, "%04d-%02d-%02d-%02d:%02d:%02d", now.year(), now.month(), now.date(), now.hour(), now.minute(), now.second());
    file.print(timestp);
    Serial.print(timestp);
}

error: pathspec 'sensor-array/windlogger.ino' did not match any file(s) known to git


Fichier de test pour le circuit soudé

Fichier de test pour le circuit soudé

Il faut ajouter la fonction interrupt au code originel et ce, sur la pin 3, pour permettre de mettre on / off les moteurs

#define DC_MOTOR_PIN1 9
#define DC_MOTOR_PIN2 10
#define ONOFF 3
int mode=1;
int i=150;

void setup() {
  /* Initialize DC motor control pin as digital output */
  pinMode( DC_MOTOR_PIN1, OUTPUT );
  pinMode( DC_MOTOR_PIN2, OUTPUT );
  pinMode( ONOFF, INPUT );
  attachInterrupt(digitalPinToInterrupt(ONOFF),TRIGGER,RISING);
}

void TRIGGER()
{
  if(mode==0)
  {
    mode=1;
  }
  else
  {
    mode=0;
  }
}
void loop()
{
  while(1)
  {
    if(mode==1)
    {
    analogWrite( DC_MOTOR_PIN1, i );
    analogWrite( DC_MOTOR_PIN2, i );
    }
    if(mode==0)
    {
    analogWrite( DC_MOTOR_PIN1, 0 );
    analogWrite( DC_MOTOR_PIN2, 0 );
   }
  }
}

error: pathspec 'apps/EurekaInterface/arduino/code_pwmMotor.ino' did not match any file(s) known to git


Added additional font chars

Added additional font chars

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/rniemand/ArduinoProjects.git/'


Fixed a bug where the X wasn't a full X

Fixed a bug where the X wasn't a full X

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/buelowp/sleepintimer.git/'


Documenting

Documenting

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Blade2021/roots.git/'


rename dht sensor test folder

rename dht sensor test folder

#include <DHT.h>

#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
    Serial.begin(9600);
    dht.begin();
}

void loop() {
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    if (isnan(t) || isnan(h)) {
        Serial.println("Failed to read from DHT");
    }
    else {
        Serial.print("Humi: ");
        Serial.println(h);
        Serial.print("Temp: ");
        Serial.println(t);
        delay(1000);
    }
}

error: pathspec 'tests/dht11/src/sketch.ino' did not match any file(s) known to git


aiming over pos_comp

aiming over pos_comp

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/trinamic/T-Bone.git/'


finishing touches end stop config?

finishing touches end stop config?


gammon's wdt

gammon's wdt

// 5pin
/* 24l01    85
   1  gnd   4
   2  vcc   8
   3  ce    1
   4  csn   3
   5  sck   7
   6  mosi  6
   7  miso  5
*/

// 3pin
/* 24l01    85
   1  gnd   4
   2  vcc   8
   3  ce    x
   4  csn   x
   5  sck   7
   6  mosi  6
   7  miso  5
*/

#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <avr/power.h>
#include <nRF24L01.h>
#include <RF24.h>

#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC
#define adc_enable()  (ADCSRA |=  (1<<ADEN)) // re-enable ADC

// http://www.gammon.com.au/forum/?id=12769
#if defined(__AVR_ATtiny85__)
#define watchdogRegister WDTCR
#else
#define watchdogRegister WDTCSR
#endif

#define _TEST
#define _DIGITAL
//#define _3PIN

#define _5PIN

#ifdef _3PIN
// 3pin
#define CE_PIN 3
#define CSN_PIN 3
#else
// 5pin
#define CE_PIN 5
#define CSN_PIN 4
#endif

#define DEVICE_ID 5
#define CHANNEL 100

const uint64_t pipes[2] = { 0xFFFFFFFFFFLL, 0xCCCCCCCCCCLL };

typedef struct {
  uint32_t _salt;
  uint16_t volt;
  int16_t data1;
  int16_t data2;
  uint8_t devid;
} data;

data payload;

RF24 radio(CE_PIN, CSN_PIN);

const int statusPin = 3;
volatile int statusPinStatus ;

void setup() {
  delay(20);
  unsigned long startmilis = millis();
  adc_disable();

  pinMode(statusPin, INPUT);
  statusPinStatus = digitalRead(statusPin);

  radio.begin();
  radio.setChannel(CHANNEL);
  //radio.setPALevel(RF24_PA_LOW);
  radio.setPALevel(RF24_PA_HIGH);
  radio.setDataRate(RF24_250KBPS);
  //radio.setAutoAck(1);
  radio.setRetries(15, 15);
  radio.setPayloadSize(11);
  radio.openWritingPipe(pipes[0]);
  radio.stopListening();
  radio.powerDown();

  unsigned long stopmilis = millis();
  payload.data2 = ( stopmilis - startmilis ) * 10 ;

  payload._salt = 0;
  payload.devid = DEVICE_ID;
}

void loop() {
  pinint_sleep();
  unsigned long startmilis = millis();
  payload._salt++;
  payload.data1 = statusPinStatus * 10 ;
  payload.volt = readVcc();

  radio.powerUp();
  delay(2);
  radio.write(&payload , sizeof(payload));
  delay(2);
  radio.powerDown();

  unsigned long stopmilis = millis();
  payload.data2 = millis();

  goToSleep();
}

// http://www.gammon.com.au/forum/?id=12769
// watchdog interrupt
ISR (WDT_vect)
{
  wdt_disable();  // disable watchdog
}

void goToSleep ()
{
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  noInterrupts ();       // timed sequence coming up

  // pat the dog
  wdt_reset();

  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset, clear existing interrupt
  watchdogRegister = bit (WDCE) | bit (WDE) | bit (WDIF);
  // set interrupt mode and an interval (WDE must be changed from 1 to 0 here)
  watchdogRegister = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);    // set WDIE, and 2 seconds delay

  sleep_enable ();       // ready to sleep
  interrupts ();         // interrupts are required now
  sleep_cpu ();          // sleep
  sleep_disable ();      // precaution
}  // end of goToSleep

ISR(PCINT0_vect) {
  statusPinStatus = digitalRead(statusPin);
  cli();
  PCMSK &= ~_BV(PCINT3);
  sleep_disable();
  sei();
}

void pinint_sleep() {
  PCMSK |= _BV(PCINT3);
  GIMSK |= _BV(PCIE);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sei();
  sleep_cpu();
}

int readVcc() {
  adc_enable();
  ADMUX = _BV(MUX3) | _BV(MUX2);

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA, ADSC)); // measuring

  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
  uint8_t high = ADCH; // unlocks both

  long result = (high << 8) | low;

  //result = 1126400L / result; // Calculate Vcc (in mV);
  result = 1074835L / result;

  //Disable ADC
  adc_disable();

  return (int)result; // Vcc in millivolts
}

error: pathspec '_30-attiny85-nrf24-5pin-pin-change-int/_30-attiny85-nrf24-5pin-pin-change-int.ino' did not match any file(s) known to git


add changes

add changes

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/markwatneyy/ttt_arduino.git/'


Update Templete.ino

Update Templete.ino

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/SirenCreatorTeam/Siren_Zwei.git/'