texts:
I have to read out the teperature and humidity of four independent SHT31 sensors with the help of an ESP32. Is there any prefered way to do this, since the only examples I can find online are only with one sensor. I have no access to the address pins of the sensors.
Thank you in advance for any help!


texts:
I created a small library, which takes a callback function:
MyClass::add_callback(bool (*callback_function)(), byte behaviour) {
  // ...
  bool result = callback_function();
  // ...
}

So far, I'm using it for periodic polling (for which I don't want to use ISR interrupts). However, I like to use it for other periodic calls that require a state. A simple example is a blinking light, which has an on-off state, as well as knowledge when the next state change needs to occur.
I like to change this method or add another method that takes a method, instead of a function. How should I do this? I'm struggling with the C basics, but answers on StackOverflow seem foccused to more modern C variants. For example, this great answer on Stackoverflow recommends to use boost::bind, but I rather not include such a large dependency.
What I'm looking for is something akin to:
MyClass::add_callback(void *obj, bool (*callback_method)(), byte behaviour) {
  // ...
  bool result = Object::callback_method(&obj);
  // ...
}

where Object::callback_method(&obj); should be equivalent to Object obj; bool result = obj.callback_method();.
For bonus points, is it possible to make this independent on the Object class?
I'm happy for pointers to other sites (like StackOverflow), provided it is applicable to a bare Arduino program.


texts: Output specific value using port manipulation

texts:
How can I output a specific value on a pin using port manipulation?

Example: I want to use this code but without any arduino functions, just with port manipulation:

for (int i = 0; i < 255; i++){
analogWrite(11, i); //write the i value to pin 11
}

I want to replace the analogWrite function with register manipulation. Is that possible?


texts: I have just done this same code but not getting exact time as per Indian timezone...What thing should I add to get exact time?

texts:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/

static const int RXPin = 10, TXPin = 11;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup() {
  Serial.begin(115200);
  ss.begin(GPSBaud);
  Serial.println(F("DeviceExample.ino"));
  Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
}

void loop() {
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();
  if (millis() > 5000 && gps.charsProcessed() < 10) {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
}

void displayInfo() {
  Serial.print(F("Location: "));
  if (gps.location.isValid()) {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  } else {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid()) {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  } else {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid()) {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  } else {
    Serial.print(F("INVALID"));
  }
  Serial.println();
}


texts: Using a 3V latching relay to power up ESP8266

texts:
I'm trying to use a 2-Coil Latching Relay like TXS2SA-L2-3V for  powering up a ESP8266. My idea is to activate the relay by setting the first coil to high and deactivate the coil by setting the second coil to high. In my circuit i will set the second coil to high at the end of the code by the esp8266. I need the latching (holding the power) function of it. Because when somebody activtes the Deep Sleep function to early, I have no electricity to power the esp8266.

My question is:

What kind of circuit I must use? I have no idea where I can start.

I have a regulator that can be enabled via de EN signal.

Thanks in advance!


texts: Arduino uno PWM CTC mode - strange behaviour on interrupt

texts:
i have this simple code that i use for generating a square wave signal of 125 KHz on pin 9 using Timer1 in the "Clear Timer on Compare Match (CTC) Mode".
I also use Timer1 Compare Match A interrupt for toggling pin 7 of PORTD.

void setup() {
pinMode(9, OUTPUT);
pinMode(7, OUTPUT);

TCNT1 = 0;
TCCR1A = 0;
TCCR1B = 0;

OCR1A = 7;
TIMSK1 = _BV(OCIE1A);
TCCR1A = _BV(COM1A0);
TCCR1B = _BV(CS11) | _BV(WGM12);
}

void loop() {
}

ISR(TIMER1_COMPA_vect)
{
  PORTD = PORTD ^ 128;
}

It happens that

The 125KHz waveform on pin 7 is delayed by 1us with respect to the waveform of pin 9. I think that is related to the time that the microcontroller takes to "entering" the interrupt function and toggling the PORTD pin (1us are 16 clock cycle of the 16MHz master clock).
Sometimes the waveform on pin 7 (the one generated inside the interrupt service routine) has some "gaps". For example, this is the waveform acquired with my scope:Why this strange behaviour happens?

Thank you


texts:
Is there any good quality GSM shield compatible with Arduino Due?
I have searched for gsm shield but it seems all shields have operation voltage 5v.
Any suggestion would be helpful.


texts:
I’ve got a large wall with 1” holes scattered about. I’ve got some wooden pegs that fit perfectly into these holes. Now I’m thinking of creating a light installation based on the pegs, but i’m Struggling to find a way of detecting when a peg has been inserted into any hole.

What’s the best method of detecting them? I was thinking a stop switch that’s just placed on the edge of the hole to the peg activates it, but i’m Not sure how well that can be detected or if it would bend with use


texts: Use pointer in calculation results in error

texts:
I'm building a project to measure/track flyball dog races.
The dogs timings are measured by photoelectric sensors at the start/finish line of the racing lane.
I have most of my code working (available on github) but I'm having some difficulties in handling very short crossings of dogs. Since I cannot realistically run a real race at home next to my development machine :-), I'm trying to build a simulator class which gives the triggers that would normally come from my photoelectric sensors.

I have a RaceHandler class which has the following in its header file:

class RaceHandlerClass
{
 public:
   long* lRaceStartTime = &_lRaceStartTime;

 private:
   long _lRaceStartTime;
}
extern RaceHandlerClass RaceHandler;

As you can see I made a public pointer lRaceStartTime which points to the private _lRaceStartTime member variable.
This might seem stupid/strange, but it really should a private member variable, I just want to 'temporarily' make it publicly available, so that I can use it in a temporary 'simulator' class to simulate a race towards my code.

Then I want to use this public pointer in the Simulator class like so:

long* lRaceStartTime = RaceHandler.lRaceStartTime;
long lRaceElapsedTime = micros() - lRaceStartTime;

However I get the following error when trying to compile this:

  error: invalid operands of types 'long unsigned int' and 'long int*'
  to binary 'operator-'

I'm afraid my c++ knowledge ends here and I have no clue what I should do different to fix this...
Any help would be greatly appreciated!


texts: Logging multiple gigabytes of data with Arduino

texts:
I have Arduino Uno with SD card shield. I'm planning to log a huge amount of data from various sensors - including accelerometers and 3D compass - to the SD card.

However, I have understood that Arduino, 64GB SD, FAT and large amount of data are not working too well.

Does Arduino work well with this amount of data on FAT? There's no need to read any data from SD on Arduino. If not, is there a better approach? Writing directly to SD without FAT?

This data logger will be on the environment where no computer or network connection is available. Performance is not an issue - around 8kB/s (over three months) is already enough.


texts: how to do Arduino to esp8266 communication

texts:
I am trying to do Arduino to ESP8266 communication, but I am not able to send data to esp8266. However I can receive data from esp8266.

Here if my Arduino code:

#include <SoftwareSerial.h>
SoftwareSerial ESPserial(0, 1); // RX | TX

void setup()
{
  Serial.begin(115200);     // communication with the host computer
  // Start the software serial for communication with the ESP8266
  ESPserial.begin(9600);

  Serial.println("Enter 1 to turn led high & 2 to turn led low.");
}
// the loop function runs over and over again forever
void loop() {
  // listen for communication from the ESP8266 and then write it to the serial monitor
  if ( ESPserial.available() )   {
    Serial.write( ESPserial.read() );
  }

  // listen for user input and send it to the ESP8266
  if ( Serial.available() )       {
    ESPserial.write( Serial.read() );
  }

}

Here is esp8266 code:

void setup()
{
  Serial.begin(9600);     // communication with the host computer
  // Start the software serial for communication with the ESP8266
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
  Serial.println("ESP -- Hello");
  delay(1000);
  // listen for user input and send it to the ESP8266
  if ( Serial.available() )  {

    int ledState = Serial.parseInt();
    if (ledState == 1) {
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      Serial.println("ESP Led On\n");
    }
    if (ledState == 2) {
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      Serial.println("ESP Led Off\n");
    }
  }
}

Once I upload both sketches, then I can see it terminal " ESP -- Hello " keep printing comming from esp8266 but when I enter 1 or 2, its not sent to esp8266 due to which I never see "ESP led on/off" messages , so correct me guys what mistake I am making.


texts: How to append float value of into a string ?

texts:
I have a float variable lng = 33.785469 and lat = 78.126548. Now can I convert them to String and append in a String variable "my_location" as "your location is \nlng = 33.785469 \nlat = 78.126548". I was trying to do this with

    char charVal[5];               //temporarily holds data from vals
    String stringVal = "";     //data on buff is copied to this string

    dtostrf(lng , 4, 2, charVal);  //4 is mininum width, 2 is precision; float value is copied onto buff
    //convert chararray to string
    for(int i=0;i<sizeof(charVal);i++)
    {
    stringVal+=charVal[i];
    }
    GPS_string = GPS_string + "Car location: \nlat:" + stringVal;
    stringVal = "";

and it given me an error :

error: cannot convert 'String' to 'double' for argument '1' to 'char* dtostrf(double, signed char, unsigned char,


texts: What can I do if I run out of Flash memory or SRAM?

texts:
According to the Arduino documentation, the ATmega328 has 32KB of Flash memory for the bootloader + uploaded sketch, and only 2KB SRAM for runtime data. The ATmega2560 has quite a bit more, totalling 256KB and 8KB respectively.

In either case, those limits seem rather small, especially when compared to similarly sized consumer devices, such as smartphones.

What can you do if you run out? E.g. if your sketch is too big, or you need to process a lot of data (such as strings) at runtime? Is there any way to expand the Flash or SRAM?


texts:
Scenario

When I upload my project via the Arduino ide I see this at the bottom:

Writing | ################################################## | 100% 4.14s

avrdude: 25698 bytes of flash written
avrdude: verifying flash memory against /var/folders/r4/s_j4c02s3wvcx6wy41__rnwh0000gp/T/build5447a2e9a95ee46ba2ad71abe5de02d6.tmp/SwatBotSpine.ino.hex:
avrdude: load data flash data from input file /var/folders/r4/s_j4c02s3wvcx6wy41__rnwh0000gp/T/build5447a2e9a95ee46ba2ad71abe5de02d6.tmp/SwatBotSpine.ino.hex:
avrdude: input file /var/folders/r4/s_j4c02s3wvcx6wy41__rnwh0000gp/T/build5447a2e9a95ee46ba2ad71abe5de02d6.tmp/SwatBotSpine.ino.hex contains 25698 bytes

Question

I'm uploading to an Arduino Uno, does this mean I have 32256 - 25698 bytes left?


texts: wire up usb to pins rather than on board usb socket

texts:
I have an uno r3 clone in an enclosure and one of these usb ports on the enclosure.

It's pretty tight in there so I was wondering if there was a way to bypass the usb port on the board and plug it in directly to the pins.

So do something like plug the usb into the outer port on the enclosure and then cut off the usb end and plug the wires directly into the board rather than using the onboard arduino usb port.

The group of 4 just above the i2c seems promising but couldn't find much on it.

Thanks for your help.


texts: Serial doesn't initialise on Arduino Mega 2560 when not powered via the USB port

texts:
I am working on a project with a Mega 2560 and a Sim800L module.

Everything works fine, however if i don't connect the USB port (at least once) and power only externally (either by Vin unregulated 7-12V or 5V regulated pin)
the program will seem not to initialize serial in setup().

I found this which is related to the issue but not a proper workaround:
https://forum.arduino.cc/index.php?topic=24642.0

edit: I can confirm using a resistor to short pins 0+1 together (serial) works but it is not a proper solution. This means you have to disassemble your project to access the resistor or add a switch if you want to use USB to debug later or upload new code. Another workaround which i need to test is to remove all Serial code (because i can in my specific project), but again this is not a proper solution.
Any ideas please?

edit2:
for comments

if(SIM900.available()>0){
// AT command to set SIM900 to SMS mode
SIM900.print("AT+CMGF=1\r");
delay(100);
// Set module to send SMS data to serial out upon receipt
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
textMessage = SIM900.readString();
textMessage.toUpperCase();
Serial.print(textMessage);
delay(10);
}

if(textMessage.indexOf("SET PHONE")>=0){
// Set phone number to receive notifications
phoneNumber = textMessage.substring(9,21);
Serial.println("Phone number set to: " + phoneNumber);
String message = "Notification number set to: " + phoneNumber + "\nSend 'Help' for additional commands.\nNote in case of reset number returns to hardcoded default";
sendSMS(message);
Serial.println("Confirmication of phone number change sent");
textMessage = "";
}


texts:
I am not sure why the ON LED and the L LED keeps blinking on my Arduino.

I was just trying to implement a simple circuit using breadboard, and everything worked fine until I unplugged one wire with the power turned on. I accidentally made the wire touch something in the Arduino, and the LED in the breadboard became extremely bright. Then the ON LED and the L LED in the Arduino started to keep blinking, and I cannot download code to Arduino anymore. I am using IAR and IAR says AT91SAM3 reset: Communication breakdown after resetting target. Abort debug session?.

I think maybe there is a short cut when the wire touched the Arduino... But how can I determine what the problem is? Thank you very much, I am totally new to Arduino and has very limited knowledge about hardware...


texts: Arduino exercise that i have no idea how to do

texts:
The messages received by the Arduino take the form: $ Ba, Pb, Rc #
Where $ represents the beginning of the message, # represents m, and B, P, and R are characters representing B button, P period and R repetition.

`a 'designates the button to be read, which can be 1, 2 or 3.
`b 'designates the time (in seconds) that the button should be expected to be pressed.
`c 'designates the number of times the button is expected to be pressed during the indicated period.

For example, with the message: $ B2, P4, R2 #
you want to know if button 2 has been pressed twice for four seconds. If condition is verified, then the Arduino must send the message $ MSG, TRUE # where MSG represents the message received without the start and m message characters. Otherwise, you must send the message $ MSG, FALSE #.
Incoming messages must respect the format presented. If not, the condition is not checked and the message $ NOK, MSG, KON # must be sent as a response.
I have no idea how to do this since im new to arduino


texts:
I have this code which produces a square wave:

int output_state = 0;
unsigned long start;

void setup() {
  Serial.begin(1200);
  start = millis();
}

void loop() {

  if((millis() - start) >=1000){
    output_state = ! output_state;
    //output_state *= 1023;
    start = millis();
  }

    Serial.println(output_state);
}

but should I multiply the signal by 1023:

output_state *= 1023;

this signal is produced by the Serial Plotter:

Mind that the timing is right, just the x axis speeds up in zero values. Why is that happening, and how can be solved?

Any thoughts would be appreciated.


texts:
I have a working code that uses MCP2515 CAN module. Wanted to minimize the size of required modules, so I went with VP230 CAN transceiver and I'm having trouble relaying the same data through different libraries. All it has to do is log in with the first ''payload1'' and send voltage instruction with ''setdefaultvolt''. Any help is greatly appreciated.

MCP2515 code:

#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
#include <Wire.h>

//pins:
#define CAN_INT 17                                                                         // Set INT to pin 2
MCP_CAN CAN(5);                                                                         // Set CS to pin 4 (D2)

void setup()
{
  Serial.begin(115200);
  delay(100);
  pinMode(17, INPUT);                                                                       //Setting pin 2 for /INT input

START_INIT:
  if(CAN_OK == CAN.begin(MCP_ANY, CAN_125KBPS, MCP_8MHZ))
  {
  }
  else
  {
    delay(100);
    goto START_INIT;
  }
  CAN.setMode(MCP_NORMAL);                                                        //set operation mode to normal so the MCP2515 sends acks to received data.
  unsigned char payload1[8] = {0x16, 0x50, 0x71, 0x07, 0x97, 0x089, 0x00, 0x00};  //login data with serial number
  CAN.sendMsgBuf(0x05004804, 1, 8, payload1);                                     //send login data

  unsigned char setdefaultvolt[5] = {0x29, 0x15, 0x00, 0xFE, 0x10};              //this is the command for setting the default output voltage (Last two bytes, LSB first). 16 80 is the maximum voltage of 57.6 V
  CAN.sendMsgBuf(0x05019C00, 1, 5, setdefaultvolt);                              //send setup data
}

void loop()
{
}

VP230 code:

#include <CAN_config.h>
#include <ESP32CAN.h>

CAN_device_t CAN_cfg;

#include <SPI.h>
#include <Wire.h>

void setup()
{
  Serial.begin(115200);

  CAN_cfg.speed=CAN_SPEED_1000KBPS;
  CAN_cfg.tx_pin_id = GPIO_NUM_19;
  CAN_cfg.rx_pin_id = GPIO_NUM_23;

  CAN_frame_t my_frame;
  CAN_frame_t my_frame2;

  ESP32Can.CANInit();

  my_frame.FIR.B.FF = CAN_frame_ext;
  my_frame.MsgID = 0x05004804;
  my_frame.FIR.B.DLC = 8;

  my_frame.data = {0x16, 0x50, 0x71, 0x07, 0x97, 0x089, 0x00, 0x00};

  ESP32Can.CANWriteFrame(&my_frame);

  my_frame.FIR.B.FF = CAN_frame_ext;
  my_frame.MsgID = 0x05019C00;
  my_frame.FIR.B.DLC = 5;

  my_frame2.data = {0x29, 0x15, 0x00, 0xFE, 0x10};

  ESP32Can.CANWriteFrame(&my_frame2);

}

void loop()
{
}


texts: Help me for interfacing Arduino with AMTP32M VOICE IC

texts:
i'm trying to get control an Aplus chip aMTP32M (stores audio samples) with Arduino . this amtp32m ic provide CPU SERIAL MODE its come with DATA and CLOCK pin.i try Spi mode with Amtp32m ic but its not working.
Please help me for this.
Link for  for DATASHEET of AMTP32M IC -http://www.aplusinc.com.tw/proimages/Mtp%20Vioce%20Ic/aMTP32M/aMTP32M/Datasheet/aMTPxxM-Datasheet_V1.1_20141216.pdf


texts: Arduino as ISP - program is being uploaded on Arduino, not breadboard

texts:
I am following this tutorial, and have wired Arduino using this diagram:

This is what it looks like:

These options are selected in Arduino IDE:

This is the program I'm uploading:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

When I upload it, it's uploaded on the Atmega on arduino board, not the one on breadboard. Both chips are ATMEGA328P.

I also tried to put 10μF capacitor between GND and RESET pins of the arduino board, which led to following errors:

Sketch uses 936 bytes (3%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avrdude -CC:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM4 -b115200 -D -Uflash:w:C:\Users\Jakub\AppData\Local\Temp\arduino_build_319338/BlinkTestAtmega.ino.hex:i

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x12
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Note that I have a homemade ATTINY programmer shield for this arduino board and it works without problems.


texts: Communicate with custom usb slave device with DUE?

texts:
I have a arduino due which i know has usb host mode. The usb library that comes with the due supports mouse and keyboard.

I have another usb device (diacnostic tool) id like to talk to, it use a:
USB Com Board Driver ( Multi-instance )
TI USBN9604
"Universal Serial Bus Full Speed Node Controller with
Enhanced DMA Support"
datasheet: www.ti.com/lit/ds/symlink/usbn9603.pdf

Ive also logged the raw byte usb traffic between windows and it when operating and would like to try sending some of those same calls to the device with the due.

Where do i start ?

Example Capture:

    000000: PnP Event: Device Connected (UP), 12.04.2015 09:14:51.390 (1. Device: USB Com Board Driver ( Multi-instance ))
The USB device has just been connected to the system.
000001: Bulk or Interrupt Transfer (DOWN), 12.04.2015 09:15:14.953 +23.562 (1. Device: USB Com Board Driver ( Multi-instance ))
Pipe Handle: 0x8639885c (Endpoint Address: 0x6)
Send 0x1b bytes to the device
 40 05 17 C0 00 09 02 00 AA 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 16 06 12


texts:
I built a button box, everything is wired up and all of the push buttons work using the code below, but for some reason my rotary encoders are not working, well 3 out of the 4 are not working. Is there something in my code that I messed up? Should rotary encoders not be linked to analog pins? Any guidance would be appreciated.
EDIT - Correct code replacing incorrect code.
#include <Keyboard.h>
#include <SimpleRotary.h>

#define NUMROWS 6
#define NUMCOLS 4

const int ModPin = A0;
int ModState = 0;

//define the symbols on the buttons of the keypads
char buttons[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {'r','e','w','q'},
  {'i','u','y','t'},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

char buttonsMod[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {0xC9,0xC7,0xC5,0xC3},
  {0xC8,0xC6,0xC4,0xC2},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

byte rowPins[NUMROWS] = {13,12,11,10,9,8}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {7,6,5,4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Keypad buttbxMod = Keypad( makeKeymap(buttonsMod), rowPins, colPins, NUMROWS, NUMCOLS);

SimpleRotary RotaryA(1,2,3);
SimpleRotary RotaryB(0,A5,3);
SimpleRotary RotaryC(A4,A3,3);
SimpleRotary RotaryD(A2,A1,3);

void setup() {
  Keyboard.begin();
  pinMode(ModPin, INPUT_PULLUP);
}

void loop() {
ModState = digitalRead(ModPin);
  if (ModState == HIGH) {
    CheckAllButtons();
  } else {
  CheckAllButtonsMod();
  }

byte i;

  // 0 = not turning, 1 = CW, 2 = CCW

  i = RotaryA.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryB.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryC.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryD.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
}

void CheckAllButtons(void) {
  char key = buttbx.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

void CheckAllButtonsMod(void) {
  char key = buttbxMod.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}


texts:
I am struggling with the code that I should write for my project. I finished my breadboard but I have never learnt programming before so I cannot write the program for the dice.
My project is to make the dice output random numbers when the button is pressed.
This is what I have completed already. I just want to know how to complete the program to make it work for my arduino.

This is the code so far:

int leda = 2;
int ledb = 3;
int ledc = 4;
int ledd = 5;
int lede = 6;
int ledf = 7;
int ledg = 8;
int ledh = 9;
int leda1 = A0;
int ledb1 = A1;
int ledc1 = A2;
int ledd1 = A3;
int lede1 = A4;
int ledf1 = A5;
int ledg1 = A6;
int ledh1 = A7;

void setup()
{
    Serial.begin(9600);
    pinMode(leda, OUTPUT);
    pinMode(ledb, OUTPUT);
    pinMode(ledc, OUTPUT);
    pinMode(ledd, OUTPUT);
    pinMode(lede, OUTPUT);
    pinMode(ledf, OUTPUT);
    pinMode(ledg, OUTPUT);
    pinMode(ledh, OUTPUT);
    pinMode(leda1, OUTPUT);
    pinMode(ledb1, OUTPUT);
    pinMode(ledc1, OUTPUT);
    pinMode(ledd1, OUTPUT);
    pinMode(lede1, OUTPUT);
    pinMode(ledf1, OUTPUT);
    pinMode(ledg1, OUTPUT);
    pinMode(ledh1, OUTPUT);

    pinMode(12, INPUT);

    digitalWrite(12, HIGH);
}

if (number == 1)
{
    digitalWrite(2, HIGH);
    digitalWrite(7, HIGH);
}

else if (number == 2)
{
    digitalWrite(3, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    delay(200);
}
else if (number == 3)
{
    digitalWrite(3,HIGH);
    digitalWrite(2,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    delay(200);
}

else if (number == 4)
{
    // do number 4
}

else if (number == 5)
{
    // do number 5
}

// ... etc
// Additional 'numbers' have been removed for brevity


texts: Is it possible to run Python embedded in Arduino?

texts: I know how to program in C but I'm more productive in python, so, I would like to know if there is a way to run a python code into arduino.


texts:
I'm trying to rename pins so that they post as some kind of alpha-numeric combination in a database.  For example, if I define the following....

#define APLHA 0
#define BRAVO 2
#define CHARLIE 5
#define DELTA 6

...I would like to rename the output of the pins, as recorded in the db, as something other than 0, 2, 5, and 6 (or whatever pin is used). Let's say A, B,C, and D for the purposes of this exercise.

Is this just as simple as creating if() function that is called upon prior to posting to the db (ex. if 0 then A, if 2, then B, etc)?  I feel like there must be a better, dare I say more elegant(?), way of doing this?

Current output:
PIN | VALUE
0  |   1
 2  |   1
 5  |   0
 6  |   0

Desired:
PIN | VALUE
 A  |   1
 B  |   1
 C  |   0
 D  |   0


texts:
I am stumped.  I have a few Wemos D1 Mini boards that were working on the local WiFi yesterday, yet today none of them will connect.  More puzzling is that I can flash Tasmota on them and they all connect to the WiFi, but none with this code that was working yesterday.  Any tips would be appreciated.

void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(wifi_ssid);

  //Connect to WiFi network so we can reach the MQTT broker and publish messages to topics.
  WiFi.mode(WIFI_STA);
  WiFi.begin(wifi_ssid, wifi_password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.print(F("WiFi connected, "));
  Serial.print(F("IP address: "));
  Serial.println(WiFi.localIP());
}


texts: Is there a way to play .mp3 files from an SD card on Arduino?

texts:
Is there a way to have mp3 files on an SD card in the SD card shield for the Arduino and play an mp3 file on that SD card with a buzzer?

If possible also with something like:

playmp3(thismp3.mp3);

So that if I execute that command, the Arduino will play thismp3.mp3 through a buzzer.

Thank you.


texts: DHT11 Humidity/Temp Sensor showing incorrect values

texts:
So I am trying to use a humidity sensor with an LCD, but have run into this problem I have yet to fix. My problem is that when it is turned on, it returns the values Humidity: 255% and Temp: 255C. I know for sure that I am getting a signal from the sensor and that is working 100% (I have tested it without an LCD display). I have asked about this in the Adafruit Discord server and someone brought up the possibility of the data being clipped somewhere in the data collection/signal processing/printing chain. Still very confused about how I can fix this, I ask for help.

Here is some code:

#include <dht11.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht11 DHT;

#define DHT11_PIN 7

void setup(){
  lcd.begin(16, 2);
}

void loop()
{
  int chk = DHT.read(DHT11_PIN);
  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
}


texts:
How can I create a workspace & projects so that either the Arduino IDE or the EclipseArduino IDE may be used to develop the project, interchangeably?

I have both IDEs installed and working but in separate workspaces.

I need:

One workspace that either IDE can understand and work in;
Either to IDE build with the physically same set of library sources;
Whichever IDE I open to see my sources as I last left them, regardless of which IDE I last used.

I want:

The source files to have conventional names - .C or .C++, not .pde or .ino;
Either IDE to build with the physically same set of library object modules;

My use-case is that I work in/with Eclipse, and I teach Arduino skills to people starting out with the Arduino IDE. I'd like to be able to prepare class work at home with Eclipse but open and project it in class with the Arduino IDE. It would be nice if I could demonstrate the two IDEs using the same code. Clearly, I could hack up a demonstration, but I'd rather do it honestly and without sync issues like having to apply twice any changes we made in class.

Update 20 Apr '16:
At @Jantje's suggestion (in the comments below his answer), I created a github issue, "Importing an ArduinoIDE project with the New Sketch Wizard and using same sketch-name, failed." The new sketch would over-write the .ino file with a new, empty sketch.

That issue got fixed in the April 14, 2016 nightly and now works as his answer to this question says it does.


texts:
i am working on a control Interface for serveral Components including turbo Pumps from the company Pfeiffer.
The communication will be done according to the The Pfieffer Vacuum Protocol for RS485.
Does any one have experience with this Protokoll or is there a library that can be used for this art of communication.
I will use a MAXCHIPRS485 for the communication between Arduino (SerialPorts) and the Pumps RS485 Port.
the Wiring is clear .
I want to ask if someone already has done a similar Code that sends and reads from the Pump continuously.
Thanks in advance


texts: Using two ultrasonic sensors for counting cars when they enter to a garage

texts:
I want to use two ultrasonic sensors for counting incoming cars to a garage. What I want is: When both sensors detect the object then the counter should increase.

Can anyone help me and give me an example?


texts: I saw a YouTube Video of someone who used an aux cord input into pin A0 on their Arduino to control a strip of LEDs. I have a strip of Adafruit's RGB NeoPixel LEDs, but I'm not sure how to input my audio into pin A0. If there is a way to do this without a separate shield or board, that'd be great because I'm on a tight budget, but if not possible it'll have to do. Also, would it be possible to send this audio to another Arduino via wifi or bluetooth using a different shield? Thanks.


texts: How can I interface HMC5883L compass board to a smartphone with OTG?

texts: Friends... I have an idea to attach the compass sensor (HIMC5883L) with my  android smartphone using arduino, but I don't clearly know how to do this. I mean I want to make an OTG compass for smartphone for map navigation etc.(Many Smartphones have compass but mine have not).  If anyone had do this or know how to do this, please guide me. Thanks!


texts: AnalogRead value constant for a varying voltage (for LED brightness variation)

texts:
Having the 11~ pin on OUTPUT mode that delivers a varying voltage (from 0 to 5 : 0 to 255).

and the A0 pin on INPUT mode to read the voltage, I find that the value read by A0 being either 0 or 1016 instead of it gradually taking multiple values between the two. what is the catch?

The circuit and the code i am using:

int volt = 0;
int sign = 1; //values: (1, -1), increments or decrements "volt" by 5.
float potential;

void setup() {

  pinMode(11, OUTPUT);
  pinMode(A0, INPUT);
  Serial.begin(9600);

}

void loop() {

if (volt == 0){sign = 1;}
if (volt == 255){sign = -1}

volt = volt + sign * 5; //raises brightness to 255 from 0, then to 0 from 255.
analogWrite(11, volt);

potential = analogRead(A0);

Serial.println(potential);

delay(30);
/*
*/

}


texts:
I would like to move my servo motor (SM-S2309S) between random angles. In order to do so, I used this simple code:

#include <Servo.h>
Servo servoMain; // Define our Servo

// SM-S2309S angular speed
float speed = 0.12/60;

void move(int from, int to)
{
  // initiate the move to the new angle
  servoMain.write(to);
  // wait for the movement to actually happen over the actual angle to move through
  delay(1000 * speed * int(from-to));
}

void setup()
{
   servoMain.attach(10); // servo on digital pin 10
   Serial.begin(115200);
   // move to center as a start
   servoMain.write(90);
   delay(1000);
}

void loop()
{
  // the previous angle, initially set as center (per the setup() call)
  static int oldangle = 90;
  // apparently 15 to 165 deg is a safe range
  int newangle = random(15,165);
  Serial.println(newangle);
  move(oldangle,newangle);
  oldangle = newangle;
}

It starts by placing the arm in the center (in the setup() function) and then should generate a random number (the new angle to go to), in a loop.

What I get is the initial position, then two moves (counterclockwise, then clockwise). The output on the serial console shows 22 and 64, which is consistent with the two moves.

Then everything stops. There is no error message on the console (I do not expect one to be, but I am not sure if there could be any feedback from the Arduino, being a complete beginner). What can be the reason for this stop, after two successful loops?


texts: What does the following code in Morse Code Arduino mean?

texts:
struct node *root, *currentNode;
  root = (struct node*)malloc(sizeof(struct node));
  root->value = '\0';
  root->next = 0;
  currentNode = root;


texts: Atmel Studio and Arduino IDE compiles the same code different

texts:
Before going in details I need to say I am trying to program Arduino Nano board with atmega328p.
Here is my code in Atmel Studio;

#include <avr/io.h>
#include <string.h>
#include <avr/interrupt.h>

int received;
int pinState = 0;

ISR(USART_RX_vect)
{
    //cli();
    while(!(UCSR0A&(1<<RXC0))){};
     //clear the USART interrupt
    received = UDR0;
    UDR0 = received;
    //sei();
}

int main(void)
{
    //DDRB |= (1 << PORTB3);
    //DDRD |= (1 << PORTD3);

    DDRD = 0xFF;
    DDRB= 0xFF;

    #define F_CPU 16000000

    TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B = _BV(CS22);

    TCCR0A |= _BV(WGM00) | _BV(WGM01) | _BV(COM0A1);
    TCCR0B |= _BV(CS02);

    #define USART_BAUDRATE 9600
    #define UBRR_VALUE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
    UBRR0H = (uint8_t)(UBRR_VALUE>>8);
    UBRR0L = (uint8_t)UBRR_VALUE;
    UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);   // Turn on the transmission, reception, and Receive interrupt
    UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
    //DDRB |= (1 << DDB1)|(1 << DDB2);

    sei();
        while(1)
    {

    }
    return 0;
}

And here is the code in Arduino IDE;

#include <avr/io.h>
#include <string.h>
#include <avr/interrupt.h>

int received;
int pinState = 0;
ISR(USART_RX_vect)
{
    //cli();
    while(!(UCSR0A&(1<<RXC0))){};
     //clear the USART interrupt
    received = UDR0;
    UDR0 = received;
    //sei();
}
void setup() {
 DDRD = 0xFF;
    DDRB= 0xFF;

    #define F_CPU 16000000

    TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B = _BV(CS22);

    TCCR0A |= _BV(WGM00) | _BV(WGM01) | _BV(COM0A1);
    TCCR0B |= _BV(CS02);

    #define USART_BAUDRATE 9600
    #define UBRR_VALUE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
    UBRR0H = (uint8_t)(UBRR_VALUE>>8);
    UBRR0L = (uint8_t)UBRR_VALUE;
    UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);   // Turn on the transmission, reception, and Receive interrupt
    UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
    //DDRB |= (1 << DDB1)|(1 << DDB2);

    sei();
}

void loop() {
           // wait for a second
}

As you can see these codes are exactly the same (except the setup-loop format)
Now I am using exact same parameters for AVRdude;

-CF:\arduino-1.0.6\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P\.\COM9 -b57600 -D -Uflash:w: and following the hex file that is created after compile. But when I examine the verbose output of avrdude.exe they are different.

Arduino program works but the program uploaded using Atmel Studio does not. For more information everything about avrdude and parameters are working and it uploads and doesnt give any errors.

I chose atmega328p in Atmel Studio which is correct because I am using arduino nano board.


texts: Modbus master arduino code is throwing weird errors on upload

texts:
I am using the following https://code.google.com/p/simple-modbus/ arduino master library code. In order to communicate with my industrial drive.

All seems right but I am getting some weird errors. I am using the arduino master code as it is. With just the difference in modbus_construct.

Here is the error I am getting

 This report would have more information with
 "Show verbose output during compilation"

enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
In file included from SimpleModbusMasterArduino.ino:29:

C:\Program Files\Arduino\hardware\arduino\cores\arduino/Arduino.h:131: error: expected ',' or '...' before numeric constant
In file included from C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:28,
                 from C:\Program Files\Arduino\hardware\arduino\cores\arduino/Arduino.h:215,
                 from SimpleModbusMasterArduino.ino:29:
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Stream.h:57: error: expected ',' or '...' before numeric constant
In file included from SimpleModbusMasterArduino.ino:29:
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Arduino.h:222: error: expected ',' or '...' before numeric constant
SimpleModbusMasterArduino:37: error: 'Packet' does not name a type
SimpleModbusMasterArduino.ino: In function 'void setup()':
SimpleModbusMasterArduino:45: error: 'packets' was not declared in this scope
SimpleModbusMasterArduino:45: error: 'READ_HOLDING_REGISTERS' was not declared in this scope
SimpleModbusMasterArduino:45: error: 'modbus_construct' was not declared in this scope

SimpleModbusMasterArduino:49: error: 'modbus_configure' was not declared in this scope SimpleModbusMasterArduino.ino: In function 'void loop()': SimpleModbusMasterArduino:56: error: 'modbus_update' was not declared in this scope

Here is my code:

#include <SimpleModbusMaster.h>

/*
   The example will use packet1 to read a register from address 0 (the adc ch0 value)
   from the arduino slave (id=1). It will then use this value to adjust the brightness
   of an led on pin 9 using PWM.
   It will then use packet2 to write a register (its own adc ch0 value) to address 1
   on the arduino slave (id=1) adjusting the brightness of an led on pin 9 using PWM.
*/

//////////////////// Port information ///////////////////
#define baud 115200
#define timeout 1000
#define polling 200 // the scan rate
#define retry_count 10

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2
#define LED 13

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 8
#define TOTAL_NO_OF_CONSTANTS 1

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
  //PACKET2,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  // Initialize each packet
  modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 0x3000, 8, 0);
  //modbus_construct(&packets[PACKET2], 2, READ_HOLDING_REGISTERS, 0x3000, 8, 16);

  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);

  pinMode(LED, OUTPUT);
}

void loop()
{
  modbus_update();
  Serial.println(regs[0]);
  //regs[0] = analogRead(0); // update data to be written to arduino slave

  //analogWrite(LED, regs[0]>>2); // constrain adc value from the arduino slave to 255
}


texts: I updated and uploaded some code on another computer that got wiped and didn't send the new code to my current computer, the updated code is still on the board but I don't have access to it. How do I get it back?


texts:
I'm making a hydroponics system that collects data and sends it to the user through a SIM module. The problem is that while I want it to happen only once every 15 minutes and for the pump to operate for 30 seconds only, yet the device seems to do everything 10 times as quickly, if not even faster. Is there any way to fix this without multiplying everything by 10?
#include <SoftwareSerial.h>
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
#include <GravityTDS.h>
#include <Servo.h>

#define ONE_WIRE_BUS 5
#define DHTPIN 7
#define DHTTYPE DHT11
#define TdsSensorPin A1
#define PUMPPIN 11

SoftwareSerial mySerial(9, 10);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DHT dht(DHTPIN, DHTTYPE);
GravityTDS gravityTds;
Servo myservo;

char msg;
char call;

void setup()
{

  dht.begin();

  sensors.begin();

  gravityTds.setPin(A1);
  gravityTds.setAref(5.0);
  gravityTds.setAdcRange(1024);
  gravityTds.begin();

  myservo.attach(PUMPPIN);
}

void loop()
{
  const unsigned long SECOND = 1000;
  const unsigned long MINUTE = 60*SECOND;
  const unsigned long HOUR = 60*MINUTE;

  delay(30*SECOND);
  int h = dht.readHumidity();
  float t = dht.readTemperature();
  float tdsValue = 0;
  float temperature = t;
  gravityTds.setTemperature(temperature);
  gravityTds.update();
  tdsValue = gravityTds.getTdsValue();

  sensors.requestTemperatures();

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+************\"\r"); // Replace x with mobile number
  mySerial.print(h);// The SMS text you want to send
  mySerial.print("% humidity, ");
  mySerial.print(t);
  mySerial.print(" degrees Celsius air temperature, ");
  mySerial.print(sensors.getTempCByIndex(0));
  mySerial.print(" degrees Celsius water temperature, ");
  mySerial.print(tdsValue,0);
  mySerial.print(" ppm");

  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

  myservo.write(0);   //Clockwise maximum speed rotation
    delay(30*SECOND);
  myservo.write(90);
  delay(15*MINUTE);

}```


texts: How do I use digital pin on sensor to analog on arduino uno

texts:
I am working on a autonomous fire extinguisher.i have run out of pins.I have the following question in my mind while working on my project

Is it necessary that the DO pin in a flame sensor must be in a PWM digital pin in Arduino.i have this doubt since when I connected it to non PWM pin it didn't worked.

Secondly it is possible for me to use the analog pin in Arduino for the DO pin of the flame sensor or trigger/echo pins of the ultrasonic sensor.

Thanks.


texts: Can't use MEGA as Transmitter and UNO as Receiver nRF24L01

texts:
I have a project with 7 May Deadline, i really need help on this. Here is the problem, I need to use my Arduino MEGA 2560 as transmitter and Ardino UNO(CH340G) as receiver. I can use uno as transmitter and mega as receiver , but vice versa doesn't works.
I've used the tutorial on this site :
https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/

All codes, connections are same, but when i set MEGA as transmitter and uno as receiver, there is no data coming to Serial port of Uno. I really need help on this, i will be very very very grateful. Thank you so much.

Code on MEGA(transmitter)

/*
* Arduino Wireless Communication Tutorial
*     Example 1 - Transmitter Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay(1000);
}

Code for receiver(UNO)

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

    PINS ON MEGA :
    3.3 -- VCC
    GND -- GND
    8   -- CSN
    7   -- CE
    51  -- MOSI
    52  -- SCK
    50  -- MISO
    PINS ON UNO :
    3.3 -- VCC
    GND -- GND
    8   -- CSN
    7   -- CE
    11  -- MOSI
    12  -- MISO
    13  -- SCK


texts:
I saw some projects with DHT11, some connect it with analog pin, others connect with digital pin.

Is there any difference / advantage connecting to the analog?


texts: Is there any way to run binary code from RAM?

texts:
I am looking for an inexpensive single board computer that I could program in assembly language, using limited facilities to load the object code from a PC and simple I/O peripherals.

Ideally I would like to be able to write in a reasonable time all the code on the machine myself. I don't want an OS in the way, as I want to have a program that writes in RAM some code and then branches to execute it.
Arduino would probably be my best choice, as far as system simplicity suitable for assembly programming goes, but it has a Harvard architecture and it won't allow me to execute from RAM.

Years ago I was using a Von Neumann architecture 8-bit CPU that could branch execution to any address, no matter whether it was mapped to ROM, RAM or whatever. This is what I would like to do now.

I probably could write and load in Flash memory an interpreter of op codes written in RAM, but it is a very complex and time-consuming solution, unless virtual machines of this kind exist already.

Any suggestions on other workarounds with Arduino or of other micro-controllers I might use?

Thanks!

Pierre


texts:
EDIT
I am using an Genuino Uno & Yun Shield

I am a complete arduino noob

I am creating something where I need a process to execute a command on my yun shield but when I use Bridge.begin(); It scrambles all text to something like this

  .ÿš2%š%šr%š%š%šr%š2%š2%º%š%š%š2%º2%º2%ºr%š2%º2%šr%šr%š%š2%šþøøþøøþúøøýýøþþþýþþøøøøúýøþÿøøþþøúýþúøøøþøýøþýúøþþøüþþøýþþøýøúø

and it just keeps adding characters. if I don't use Bridge.begin(); then it correctly prints.

I wrote this short program to replicate the bug:

#include <Process.h>

void setup() {
// put your setup code here, to run once:
// Start the bridge and serial port.
Bridge.begin();
Serial.begin(9600);

 while(!Serial){

 }
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println("test");
}

So this will give the scrambled text and when you remove the Bridge.begin(); it will show the text but I really need to use a Process in my other program so as I understand I need Bridge.


texts: Sketch stops working after ~40 minutes. Overflow?

texts:
I have this simple sketch I use on Arduino Micro:

int fan = 3;
int led = 13;
int ledState = HIGH;         //all'inizio gira
//unsigned long time;
unsigned long prevMicros = 0;        // will store last time LED was updated  +
unsigned long interval =  7000000;           // lunghezza della pausa in secondi
unsigned long intervalON =  1000000;           // lunghezza del ON in secondi

void setup() {
 pinMode(fan, OUTPUT);
 pinMode(led, OUTPUT);
 prevMicros = micros();
}

void loop() {
  unsigned long currMicros = micros();

  // manage overflow? BOH
   if (ledState == HIGH && (((unsigned long)(currMicros  - prevMicros)) >= intervalON)){
     prevMicros = currMicros;
      ledState = LOW;
    }
    else if (ledState == LOW && (((unsigned long)(currMicros - prevMicros)) >= interval)){
      ledState = HIGH;//riparte
      prevMicros = currMicros;
    }

    digitalWrite(led, ledState);
    digitalWrite(fan, ledState);
}

I could use millis() instead of micro(), but I decided to keep this to shorten the overflow rate (should be 72 minutes). I shall go back to millis() once my issue is fixed.

The sketch works as expected, turning on the LED for a second every 7, but the sketch hangs after 40 minutes. Can you tell me why, and how to manage overflow properly? Why is it hanging after 40 and not 72 minutes? Thanks


texts:
I am using an Arduino Mega to control the speed of an internal combustion engine.

The speed is sensed via a Variable Reluctance Sensor (VRS) on the crankshaft. This signal is then converted into a 5V square wave which is feed into Interupt 2 (Pin 21) on the Arduino.

The flywheel of the engine, onto which the VRS is sensing has one tooth. Therefore one square wave blip (from 5v to 0V) as it is passing it and then back up to 5v. The interupt that this is attached to increases a counter by 1. The time taken for the counter to reach 20 is recorded. I want to use this speed reading value in a PID algorithm which then in turn actuates a servo.

This methodology was sucessfully used in a very similar engine with a 22 toothed flywheel but is not working on this engine with 1 tooth.

The problem is the speed reading - the values that I am recording for the time taken for 20 revs ( in micro seconds), and displayed on the serial terminal is wrong and I do not know why. The numbers printed are all mulitples of one another e.g. 440960,551200,661440,771680 which all divide into one another with an even fraction. The correct reading here is 661440, this has been verified with observation of the square wave input through and oscilloscope.

I cannot find why!

I have attached the code here


texts:
I'm using a modified version of Arduino Zero Bootloader. I am trying to write software to automatically detect which USB device the bootloader is currently running on in order to execute bossac.

I have noticed a few unique characteristics when using "lsusb -v". Things like "bDeviceClass" is always 2. and "bDeviceSubClass" is always 0; However, I do not feel confident in using these traits to identify the bootloader. Is there any clear indication of bootloader so I can find the correct ttyACM#?


texts: EEPROM: managing address mapping between firmware versions

texts:
Is there a common way to handle changes in the mapping between eeprom addresses and variables between firmware versions? It's not about the eeprom memory to survive the update, but to be(come) compatible with future sketches with a possibly different set of variables.

To make it clearer consider the following fictional scenario:

A coffee machine has been programmed to measure water_temperature and the firmware is supposed to stop heating within a temperature_hysteresis
 below set_temperature. set_temperature is a persistent parameter that has been individually optimized be the user and must therefore survive any firmware update. As a configuration parameter also temperature_hysteresis is stored in the eeprom.
Now the manufacturer decides to update his machine with a PID-controller, making the parameter temperature_hysteresis obsolete while he introduces some new parameters for the controller's gains (pid_gains). How can he manage that the firmware keeps values that haven't been touched by the update (like set_temperature) while the additional parameter pid_gains is added.

I assume that obsolete parameters should be removed as there could be more updates with new parameters in the future. That's why simply incrementing the eeprom address and ignoring deprecated addresses probably won't work.

On the other hand, when re-using old addresses I wonder how a fragmentation of the eeprom can be avoided.
I came up with the idea of putting all configuration data into a json in the eeprom and to handle the problem a layer above by parsing the json for configuration data. But anyhow, that feels so wrong and might be too complicate.

Does anyone have experience with this kind of problem and knows how this routine is commonly implemented?


texts: Trying to instantiate a DS3231 real time clock within a library

texts:
I'm trying to write a library encapsulating things that I do with a DS3231 real time clock. I have managed to compile a sketch using the library, but it apparently blows up when attempting to call clock methods such as getTime().

Header:

// JBP_DS3231.h
#ifndef __JBP_DS3231_h__
#define __JBP_DS3231_h__

#include <SD.h>
#include "DS3231.h"
#include "Arduino.h"

class JBP_DS3231
{
  public:
    JBP_DS3231();
    String TimeStamp();
  private:
    DS3231* _realTimeClock;
};

#endif

cpp:

#include <JBP_DS3231.h>
#include <SD.h>
#include "DS3231.h"
#include "Arduino.h"

JBP_DS3231::JBP_DS3231() {
  String thisTime = "";

  _realTimeClock = &DS3231(SDA, SCL);

  Serial.println("About to try to get time from RTC."); // Last line we hear from.

  thisTime = _realTimeClock->getTimeStr();
  Serial.print("Time in constructor is: ");
  Serial.println(thisTime);
}

String JBP_DS3231::TimeStamp() {
  String timeStamp = "";

  Serial.println("In TimeStamp().");
  timeStamp = _realTimeClock->getDateStr(FORMAT_LONG, FORMAT_MIDDLEENDIAN, '/');
  Serial.print("Value of timestamp is: ");
  Serial.println(timeStamp);
  timeStamp.concat(" ");
  timeStamp.concat(_realTimeClock->getTimeStr());
  Serial.println(timeStamp);

  return timeStamp;
}

Script:

const String WHO_AM_I = "JBP_DS3231_library_test.ino";
const    int VERSION = 0;

#include <JBP_DS3231.h>

void setup() {
  Serial.begin(9600);
  AnnounceAwakening();

  JBP_DS3231 johnsRTC;
  Serial.println(johnsRTC.TimeStamp());
}

void loop() {
  return;
}

void AnnounceAwakening() {
  Serial.print("Sketch ");
  Serial.print(WHO_AM_I);
  Serial.print(" version ");
  Serial.print(VERSION);
  Serial.println(".");
  Serial.println("");
}


texts: print data after being plugged back into USB

texts:
I have an arduino uno powered by a battery on a buggy with a sonar distance sensor.  I have a program that calculates the speed it's going, and I want to correlate speed with stopping distance.  I can measure the stopping distance manually, but I want the arduino to report to me the speed it was going when the motor was turned off.  I don't have an LCD display - I wanted to print the number to the serial monitor, but plugging it back into the USB port resets everything I think, or at least the serial monitor.

Without buying more components, can I get the data (calculated speed) somehow?


texts: Max current of Vin and 5V pin on Arduino Nano

texts: What is the max current of the Arduino Nano's Vin (30) and 5V (27) pins?


texts: Connecting Arduino to internet through HC-06 and then smartphone

texts: Can I use HC-06 to connect the Arduino to a smartphone (which I am already doing) and thereafter take the data to the internet?


texts: Camera switch with ov7670 to output standard A/V signal - composite

texts:
I've got 3 OV7670 cameras and would like to create a switch that outputs one of the cameras video as standard A/V out (I'm not sure the correct naming).

I found docs explaining how to use the cameras on the Arduino platform but I'm not sure how to output video signal - composite.


texts: If I try to pause my loop function my output screen starts printing trash

texts:
I am working of on a Wemos R1 D2 board with VL53L0X Laser Sensor. I need to stop my program after calculating an average of 50 readings but as soon as I try while(1) { } or any other method my output produces garbage.

void loop()
{
  float initial=0,inside=0,outside=0,sum=0,x;
  for (int i = 0; i < 10; i++) {
    x = sensor.readRangeSingleMillimeters();
    if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
    sum = sum + x;
    Serial.print("Initial Reading: ");
    Serial.println(sum);
  }
  while(1) {};
  Serial.flush();
}


texts: Use Arduino to detect low battery state and shut it down

texts: I wanted to know if it is possible to monitor a battery that is driving the Arduino and check its voltage. When the voltage drops below a certain level (i.E below 3.0V) it should shutdown and disconnect itself from the battery by using a relay or something. When the battery is full enough again it should power up again. Is that possible without any external sensors just by using the Arduino's inputs?


texts: Send IR success but doesn't turn on the TV

texts:
My circuit is simple:

IR sensor (from left to right): PIN 11, GND, 5V
IR transmitter: GND, PIN 1 (via resistor). (BTW: all of the tutorials I read says that the PIN should be 3 but from some reason it sends only when it connected to PIN 1. How do I know? because I can "see" the light via the mobile's camera like the image below)

I'm trying to "record" an IR signal and sent it. The code come from gits I found:

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);
IRsend irsend;

boolean recording = true;
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (recording) {
    if (irrecv.decode(&results)) {
      Serial.println("IR code recorded!");
      //irrecv.resume(); // Receive the next value
      Serial.print("Recorded ");
      Serial.print(results.rawlen);
      Serial.println(" intervals.");
      recording = false;
    }
  } else {
    // replay mode
    for (int i = 0; i < 3; i++) {
      Serial.println("Sending recorded IR signal!");
      irsend.sendRaw((unsigned int*) results.rawbuf, results.rawlen, 38);
      delay(40);
    }
    delay(2000);
  }
}

https://gist.github.com/jeje/3027236

Like you can see in the image, the signal is sent but it does nothing to the TV (I record the TV's remote of course)


texts: Store TinyGPS++ latitude value into a variable of type string or float

texts:
I want to get the GPS ordinates in degrees with 6 decimal accuracy. I can obtain this by creating a gps object with TinyGPS library. but In the TinyGPS example codes, its written

Serial.println(gps.location.lat(), 6);

But I actually want to store this latitude degrees in a variable of type string or float. when i write this;

double Tiny_latitude = (gps.location.lat());
Serial.print("Tiny lat:");
Serial.println(Tiny_latitude);

it returns me Tiny lat:33.55 on serial monitor. But i want 33.546600.
How do I do that ?


texts:
I am building a security system, and found the following code

#define NOOT_B0  31
#define NOOT_C1  33
#define NOOT_D1  37
#define NOOT_E1  41
#define NOOT_F1  44
#define NOOT_G1  49
#define NOOT_A1  55
#define NOOT_B1  62
#define NOOT_C2  65
#define NOOT_D2  73
#define NOOT_E2  82
#define NOOT_F2  87
#define NOOT_G2  98
#define NOOT_A2  110
#define NOOT_B2  123
#define NOOT_C3  131
#define NOOT_D3  147
#define NOOT_E3  165
#define NOOT_F3  175
#define NOOT_G3  196
#define NOOT_A3  220
#define NOOT_B3  247
#define NOOT_C4  262
#define NOOT_D4  294
#define NOOT_E4  330
#define NOOT_F4  349
#define NOOT_G4  392
#define NOOT_A4  440
#define NOOT_B4  494
#define NOOT_C5  523
#define NOOT_D5  587
#define NOOT_E5  659
#define NOOT_F5  698
#define NOOT_G5  784
#define NOOT_A5  880
#define NOOT_B5  988
#define NOOT_C6  1047
#define NOOT_D6  1175
#define NOOT_E6  1319
#define NOOT_F6  1397
#define NOOT_G6  1568
#define NOOT_A6  1760
#define NOOT_B6  1976
#define NOOT_C7  2093
#define NOOT_D7  2349
#define NOOT_E7  2637
#define NOOT_F7  2794
#define NOOT_G7  3136
#define NOOT_A7  3520
#define NOOT_B7  3951
#define NOOT_C8  4186
#define NOOT_D8  4699

 int melody[] = {
// NOOT_C4, NOOT_G3, NOOT_G3, NOOT_A3, NOOT_G3, 0, NOOT_B3, NOOT_C4
NOOT_D8, NOOT_D8, NOOT_D8, NOOT_D8, NOOT_D8, NOOT_D8
};
int NOOTDurations[] = {
 4, 4, 4, 4, 4, 4, 4, 4
 };
 void setup() {
    // iterate over the NOOTs of the melody:
  for (int thisNOOT = 0; thisNOOT < 8; thisNOOT++) {

// to calculate the NOOT duration, take one second divided by the NOOT type.
//e.g. quarter NOOT = 1000 / 4, eighth NOOT = 1000/8, etc.
int NOOTDuration = 1000 / NOOTDurations[thisNOOT];
tone(8, melody[thisNOOT], NOOTDuration);

// to distinguish the NOOTs, set a minimum time between them.
// the NOOT's duration + 30% seems to work well:
int pauseBetweenNOOTs = NOOTDuration * 1.50;
delay(pauseBetweenNOOTs);
// stop the tone playing:
noTone(8);
  }
 }

void loop() {
int melody[] = {
 // NOOT_C4, NOOT_G3, NOOT_G3, NOOT_A3, NOOT_G3, 0, NOOT_B3, NOOT_C4
 NOOT_D8, NOOT_D8, NOOT_D8, NOOT_D8, NOOT_D8, NOOT_D8
  };
 int NOOTDurations[] = {
  4, 4, 4, 4, 4, 4, 4, 4
  };

  }

How can i let the specific tone loop? Right now it's not within the loop and i am struggling to make it work in the loop. Thanks in advance!


texts: Is there a bridge needed to connect Pro Mini 3.3v to HC-05 (level 3.3v)?

texts:
I can't understand how to connect my arduino pro mini https://www.amazon.in/gp/product/B071ZCHW5P/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

To my HC-05 Bluetooth module https://www.ebay.in/itm/HC05-Wireless-Bluetooth-RF-Transceiver-Module-Serial-TTL/182970488321?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

There is a guide to connect them given here : http://www.instructables.com/id/Bluetooth-Serial-Adapter-for-Pro-Mini/

I am trying to follow this guide but it is for 5V version and involves shorting the diode on the pro mini plus a divider circuit.

Here is the circuit:

Apparently, there is an obvious difference in the circuit according to my components.

Please help me connect them correctly.

Thanks :)


texts: How do I know if a board fits my requirements?

texts:
I'm new to Arduino and I saw on their website that there are many different kinds of boards.
What are the differences, or to be more specific, how would I know which board meets my requirements? I understand that the shields can be connected to the board, but are some boards that do not support certain shields?

Another thing, is it possible to connect external sensors to an Arduino board or there are special sensors that can communicate with the board? I want to use weight sensors.


texts: avr/io.h No such file or directory error when compiling using avr-gcc

texts:
I am trying to use the atmega328p as standalone microchip and program it. I ama using an Arduino Uno as ISP. I have written a simple program to test it however when I try to compile it using

avr-gcc -mmcu=atmega328p -o main.out main.c

I get the error:

main.c:1:20: fatal error: avr/io.h: No such file or directory
compilation terminated.

I am running OpenSUSE Leap 42.3 and i have installed avr-gcc, avr-libc.

My code:

#include <avr/io.h>

int main() {
    DDRB = 1;
    PORTB = 1;
}

Thank you in advance!


texts:
I've the VCNL 4000 Proximity Sensor I use some sample code and at the very beginning
the following code hangs (never finishes)
 readVCNLByte(0x81); is called

Can this problem be caused because the contact of the pin isn't very good.
I only but the part with pins in the sensor without to solder it.
Is it likely that this may be the problem ? I have not many experince with solder and the sensor is really small so i'd like to avoid it for first tests ;)
Here the code. The last output in the Serial window is "pre product"
  Serial.println("VCNL");
  Wire.begin();
  Serial.println("pre product");
  uint8_t rev = read8(VCNL4000_PRODUCTID);
   Serial.println("post product");
  if ((rev & 0xF0) != 0x10) {
    Serial.println("Sensor not found :(");
    while (1);
  }


texts: Where can I find magnetic declination lookup table?

texts:
Is there a way to get approximate value of magnetic declination from GPS coordinates?

My Arduino-based device has a Magnetometer and a GPS, and uses magnetic declination in calculations. I would like to avoid having to configure it by hand.

I have found references to https://www.ngdc.noaa.gov/geomag/WMM/soft.shtml online, but the site seems to be down (Google has a cache of the site but not of the code).

Is there another way of getting magnetic declination from GPS coordinates? Doesn't have to be precise, +/- 10% would work just fine.


texts: Liquid Crystal LCD and serial monitor not playing well together

texts:
On my Arduino Uno, when I'm not using the serial everything seems in order:
#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup()
{
    // put your setup code here, to run once:
    lcd.begin(16, 2);
    lcd.clear();
    lcd.print("Prints");
    lcd.setCursor(0, 1);
    lcd.print("Well");
}

void loop()
{
    delay(1000);
}

However the moment I open the serial port with:
Serial.begin(9600);

The problem starts.
Clearing the LCD does not clear it but prints a character with 4 horizontal lines. Trying to move the cursor will print a different  unrecognisable character. Sending things to the Arduino via the Serial port prints gibberish on the LCD.

Any idea why? Is there a way to work with the LCD and the serial port simultaneously? I require the serial port in order to control the Arduino from NodeJS.
#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup()
{
    // put your setup code here, to run once:
    lcd.begin(16, 2);
    lcd.clear();
    lcd.print("Prints");
    lcd.setCursor(0, 1);
    lcd.print("Well");

    Serial.begin(9600);

    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for Native USB only
    }
}

void loop()
{
    lcd.clear(); // This will print 4 horizontal lines character instead of clearing
    delay(500);
}


texts: Cheapest way to change digital output source

texts:
Powering at 5 volts, atmega328 output ~4.7 volts. I need to output between 12 and 24 volts @ 2 amp. I'm currently using relay but they are costly. Is there a way to do it with transistors or any thing cheaper?

Thanks


texts: Eclipse C++ Ide for Arduino 2.0 and eeprom.h (no such file or directory)

texts: I am using a Pro Mini and the Arduino Eclipse plugin. I have a project that is close to 1,000 lines of code and I am using things such as analogRead() and the u8g display library. Now I am at the point where I want to save data to EEPROM but I can't, because it says "eeprom.h (no such file or directory)". I have tried including this library in both my main file (where the setup and loop functions are) and also in my own .h files, which are in the same folder as the main file. Any thoughts on this?


texts: Simultanous read and read/write on two serial connections

texts:
At the moment I'm using two softserials to connect to a GPS and an GSM module.

It seems not possible to have two open software-serials. So I was looking for an solution

After the initial-setup, the GPS module is only needed to be read from; while the GSM module needs to be bidirectional. So:

GPS > listen only
GSM > listen and write

Now I came across the GPS library from Adafruit, which uses an interrupt to receive data. Is this instead of a software serial. Or do I again run into the limitation?

An other solution might be to use the D0 and D1 to attach eg the GPS module. But than I won't be able to see the debug messages in my serial monitor. Is that correct?

Sorry in advance for these n00b questions. But I'm frustrated the things dont work as I want :)

edit

This is the adafruit GPS board.
And the board with whom it is connected: Gboard
The Sim900 is connected to D2/D3 and the GPS is connected to A2/A3.
D0/D1 are connected to a FTDI breakout board, which is plugged into my USB.


texts:
I have an amplifier circuit for a microphone.The output of the circuit(the microphone signal amplified) is connected to the arduino A0 .Now the circuit works(I think ,the output voltage is 4.30 V) and the arduino serial monitor output 875 874... fluctuates with one or 1,2 or more points.The problem is that this value just goes down from 875....800.... .

Is it a correct value?(circuit taken from here http://wiring.org.co/learning/basics/microphone.html)

EDIT: If I put my finger on it the values go up a bit like 792 ,794,800


texts: What does an arduino sketch translate to before compilation?

texts:
I've been experimenting with Arduino on both esp8266 and AVR chips. The structure of the .ino file usually looks like this:

#include "Arduino.h"
#include "ESP8266WiFi.h"
##Some includes

void setup()
{
...
##Will be only run once at the begining.
}

void loop()
{
##Runs this code in a constant loop
}

My assumption is that somewhere behind simplification, before the compilation takes place, there is a full blown source file. It includes the platform specific initialization and contains the calls to setup() and loop(). When I say full blown source file I mean something that can be passed to the compiler and will compile given that the dependencies are met.

My questions are:

Is this assumption correct?
If so, can someone share an example on how does the full blown source file look like, and where did you get it from?


texts: Unexpected behavior of sprintf with i32/u32

texts:
I'm trying to build a string of characters from several elements given by the TinyGPS++ library with the use of sprintf().

This is my code making the string and printing it in the serial monitor.

char posmsg[100], lat[14+1], lon[14+1];

void sendString(){
  //- convert lat/lon
  dtostrf(gps.location.lat(), 10,6, lat);
  dtostrf(gps.location.lng(), 10,6, lon);

  //- sprintf the string
  sprintf(posmsg, "$%4d-%02d-%02d %02d:%02d:%02d,%s,%s,%i,%i,%i,%i,%i$",
          gps.date.year(),gps.date.month(),gps.date.day(),
          gps.time.hour(), gps.time.minute(), gps.time.second(),
          lat, lon,
          gps.speed.value(), gps.course.value(), gps.altitude.value(),
          gps.satellites.value(), gps.hdop.value()
        );

  Serial.println("--------------------");
  Serial.println(posmsg);
  Serial.println("--------------------");

  Serial.print("Speed:");
  Serial.println(gps.speed.value());
  Serial.print("Course:");Serial.println(gps.course.value());
  Serial.print("Height:");Serial.println(gps.altitude.value());
  Serial.print("Sats:");Serial.println(gps.satellites.value());
  Serial.print("HDOP:");Serial.println(gps.hdop.value());
  Serial.println("--------------------");
}

This is the result and what I expect... (spaces added for readability)

 Result:
 --------------------
 $2014-06-24 15:17:11,  51.xxxxxx,   5.xxxxxx, 2, 0, 4964, 0, 3660$
 --------------------
 Speed:2
 Course:4964
 Height:3660
 Sats:8
 HDOP:110
 --------------------

 Expected:
 --------------------
 $2014-06-24 15:17:11,  51.xxxxxx,   5.xxxxxx, 2, 4964, 3660, 8, 110$
 --------------------

So in the end of the string the numbers get displaced...

According to the documentation the type of the variables are all integers or unsigned integers, but the sprintf messes things up.

 gps.speed.value(); // Raw speed in 100ths of a knot (i32)
 gps.course.value(); // Raw course in 100ths of a degree (i32)
 gps.altitude.value(); // Raw altitude in centimeters (i32)
 gps.satellites.value(); // Number of satellites in use (u32)
 gps.hdop.value(); // Horizontal Dim. of Precision (100ths-i32)

What am I doing wrong?


texts: Venus GPS + Arduino. Kill 3.3V TX during sketch upload

texts:
I am playing around with the Sparkfun Venus GPS.  I followed this tutorial to get started.  In here the author states that you should

  Upload the following sketch to your Arduino BEFORE making any
  connections. 5V from an IO pin left high on the Arduino may well kill
  the 3.3V output from the Tx pin on the GPS module.

However, I am using the Sparkfun bi-directional logic level converter in between the Arduino and the Venus GPS (because I'm using the 5V Arduino GSM shield stacked on top of the Arduino).  In that case, would the above statement still apply?


texts: Using multiple HC-SR04: sharing trigger pin and interference between HC-SR04

texts:
If I have four HC-SR04 detectors, can they share the same trigger pin on the Arduino?  This would reduce the number of pins needed from eight to five.

Even if they can share the same trigger, maybe this doesn't make sense because the emitted signal from one HC-SR04 will give a false reading to the others.  If this will occur, how much time should the sketch pause before triggering/reading the next HC-SR04?

Thanks.


texts: LUFA with pro micro 3.3v 8mhz not working

texts:
I am trying to flash my pro micro 3.3v from sparkfun with a Lufa project to make it act as a pokken controller, i am using this project Github Project I have modified the makefile for 8mhz and set the bootstart pid, this has worked succesfuly on an arduino uno r3, with the same project. When i make the project it works fine then I run make avrdude, and it flashes succesfully. the problem though is the pro micro does not show up as a pokken controller as it should. I then tryed it on my switch to no avail. Here is the make file I am using

#
#             LUFA Library
#     Copyright (C) Dean Camera, 2014.
#
#  dean [at] fourwalledcubicle [dot] com
#           www.lufa-lib.org
#
# --------------------------------------
#         LUFA Project Makefile.
# --------------------------------------

# Run "make help" for target help.
PID          = 0x9203
BOOT_START   = 0x9203
ARDUINO_MODEL_PID = 0x9203
MCU          = atmega32u4
ARCH         = AVR8
F_CPU        = 8000000
F_USB        = $(F_CPU)
OPTIMIZATION = s
TARGET       = Joystick
SRC          = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_SERIAL)
LUFA_PATH    = ./lufa/LUFA
CC_FLAGS     = -DUSE_LUFA_CONFIG_HEADER -IConfig/
LD_FLAGS     =
AVRDUDE_PROGRAMMER = avr109 # Add this
AVRDUDE_PORT = COM5 # And this too (use your correct COM port)
MCU_AVRDUDE = atmega32u4
MCU_DFU = atmega32u4

# Default target
all:

# Include LUFA build script makefiles
include $(LUFA_PATH)/Build/lufa_core.mk
include $(LUFA_PATH)/Build/lufa_sources.mk
include $(LUFA_PATH)/Build/lufa_build.mk
include $(LUFA_PATH)/Build/lufa_cppcheck.mk
include $(LUFA_PATH)/Build/lufa_doxygen.mk
include $(LUFA_PATH)/Build/lufa_dfu.mk
include $(LUFA_PATH)/Build/lufa_hid.mk
include $(LUFA_PATH)/Build/lufa_avrdude.mk
include $(LUFA_PATH)/Build/lufa_atprogram.mk

Any Help would be appreciated


texts: 7-Segment, 3-digit display not displaying correctly

texts:
I have written the code that should work, but for some reason the numbers do not display correctly. When I choose to display 3 times the same number it works correctly (so pin connections are correct) but when trying to display different numbers on each digit things get messy. Can anyone see what is wrong with the code? I don't seem to find it. thanks!

Working when 3 digits are the same:

Not working with different numbers (should be 3, 2, 1:

And the code:

int a = 2;               //Defining segments corresponding to the pins
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;

void setup(void) {      //Setting Pins as output
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
}

void WriteNum(int PositionN, int Number) {
  int Position;
  int NumberSegments[10][7] = {{a,b,c,d,e,g},     //Defining segments for forming numbers
                          {b,c},
                          {a,b,d,e,g},
                          {a,b,c,d,g},
                          {b,c,f,d},
                          {a,c,d,f,g},
                          {a,c,d,e,f,g},
                          {a,b,c},
                          {a,b,c,d,e,f,g},
                          {a,b,c,d,f,g}};
  digitalWrite(A0, HIGH);                       //Setting begin conditions (All segments low and no digits turned on)
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

  switch (PositionN) {                        //Deciding which digit to turn on
    case 1:
      Position = A0;
      break;
    case 2:
      Position = A1;
      break;
    case 3:
      Position = A2;
      break;
  }
  digitalWrite(Position, LOW);
  for (int i = 0; i < sizeof(NumberSegments[Number]); i++){       //For each segment in number to display
        digitalWrite(NumberSegments[Number][i], HIGH);            //Light that segment
        }
  delay(5);
}

void loop(void) {
  WriteNum(1,2);
  WriteNum(2,2);
  WriteNum(3,2);
}


texts: Detect DS18B20 sensors and correctly assign them to relays

texts:
I'm relatively new to microcontroller programming, so please excuse me if my question is dumb. I've created a simple device that allows me to control 4 relays based on temperature. I bought four DS18B20 sensors, 4 relay board and Wemos D1. Everything works fine - I'm able to read the temperature of each sensor based on their address.

But I started wondering how I can replace a single DS18B20 without recompiling the code; currently this isn't possible. After searching a bit I found a couple of questions about the order of 1Wire sensors. For example, this one. I have no control over the order in which sensors are detected.

Is there a best practice when it comes to configuring DS18B20 sensors?
I would like to set up my device. By set up, I mean that I would like to assign a specific DS18B20 to a specific relay.

I imagine it like so:

Take a new DS18B20, connect it to a device and power the device.
The device should scan for DS18B20 sensors. If it finds one then it should assign it to relay 1 and store its address in EEPROM.
Then unplug the device from power, plug the second DS18B20 and power the device again.
The device again scans for DS18B20 sensors. It finds 2 devices. The first one is known (the address was stored in EEPROM) so it is skipped. The second is assigned to relay 2 and the address is stored in EEPROM.
The same procedure is applied to the third and fourth sensors.
If four sensors are connected (the addresses are from EEPROM), then the device can run.
When the user wants to replace a non-functioning sensor, the same procedure can be used.

As I wrote, I'm new to microcontroller programming, so if there is a better way please let me know. I'm mostly learning by following examples and tutorials, so if anyone knows of an example showing such a configuration procedure I'll be grateful for any materials.


texts:
I'm trying to create a dead zone so the joystick will turn the motor off completely when in the center position. It's much too sensitive and will start the motor if barely touched. How could I fix the code so the off position of the joystick is bigger? This is the original code.
#include <Servo.h> //Using servo library to control ESC

Servo esc; //Creating a servo class with name as esc

void setup()
{
  esc.attach(9); //Specify the esc signal pin,Here as D9
  esc.writeMicroseconds(1000); //initialize the signal to 1000
  Serial.begin(9600);
}

void loop()
{
  int val; //Creating a variable val
  val = analogRead(A0); //Read input from analog pin a0 and store in val
  val = map(val, 0, 1023, 1000, 2000); //mapping val to minimum and maximum(Change if needed)
  esc.writeMicroseconds(val); //using val as the signal to esc
}


texts: How to reduce current from a AC TO DC power supply for arduino use

texts:
I have a AC to DC converter that was originally used for recharging the PSP, I stripped the 2 wires of the output and was wanting to use it for my arduino instead of using a 9V battery, it's output is 5V 2000MA, is there a way to reduce the current in order to use it for the arduino and im guessing the 5V is enough to power it...right? Im kinda new to electronics and the arduino so any help is much appreciated :D.
Thanks,
Liam.


texts: Is there a method of figuring out whether or not my stepper drivers are dead?

texts: I'm working on a project that involves stepper motors, and I'm mainly using DRV8825 stepper drivers. At the moment, it seems like only one of my drivers actually gives the motors any current. The others usually return 0s when I measure their VREFs. One returns a value but still can't pull the motors. After checking all of my DRV8825s and finding only two returned VREFs, I checked my A4988s and none of them gave anything (aside from power supply voltage when measuring different pins). Is there a way I can figure out whether my stepper drivers are actually fried? I have a suspicion that maybe the potentiometers on the drivers are thrown off or there's some other issue I can't place. I'm happy to give more information if that can help to figure out what's going on here. Thank you!


texts: Is there any way to create some AI with Arduino?. The question is just that. I would like to give some intelligent (explore the house, trigger alarms, etc) to a rover but I dont have so much expierience. Thank you


texts: what ftdi windows driver for arduino nano

texts:
at http://www.ftdichip.com/FTDrivers.htm they seem to divide chips into two categories,  FT4222H vs. D2XX driver.

What's the correct for a arduino nano?


texts: How to specify a timer's name depending on the chip it will be compiled to?

texts:
I need to enable a timer interrupt for a chip, and in the mean time, I am testing the code on Arduino Nano rather than (feed the chip, test the chip)++.
So as part of the code I have to TIMSK0 |= (1 << OCIE0A); which works great on the Arduino Nano, but has to be changed to TIMSK (without the 0) for the ATtiny45.
I was planning to go for something along the line of
#define NANO//Put // in front for the AtTiny45
#ifdef NANO
  const char in  = A0;
  const char out = 3;
  const char pwr = 10;
  char *timer = &TIMSK0;
#else
  const char in  = 3;
  const char out = 0;
  const char pwr = 1;
  char *timer = &TIMSK;
#endif
//...
*timer  |= (1 << OCIE0A);

So here are my three questions:

Do #these commands take space on a chip?
Is a pointer the way to go for this kind of things?
Am, am I doing it right?


texts:
I installed the ESP EXCEPTION DECODER along with my Arduino IDE.  When my sketch crashes with Exception 29, I take the stack trace and input it, but I can't understand its line references (they dont seem to point to my code).

  Exception (29):
  epc1=0x4020ec84 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

  ctx: sys
  sp: 3ffffcd0 end: 3fffffb0 offset: 01a0

  3ffffe70:  3fffb558 00000000 3fff197c fffffffb
  3ffffe80:  3fff0ea0 3fff0ea0 00000000 4020fb20
  3ffffe90:  00000000 00000000 0000001f fffffffb
  3ffffea0:  3fff0ea0 00000000 3fff0e9c 4020ed35
  3ffffeb0:  40000f68 3ffe93b4 3fff0e9c 402120ec
  3ffffec0:  00000000 00000007 3fff197c 402137fa
  3ffffed0:  3ffe93b4 3ffe93b4 3fff0e9c 4021211a
  3ffffee0:  ffffffff 3fff0e9c 3fff197c 4021463c
  3ffffef0:  0100a8c0 3fffdcb0 3ffee960 00000030
  3fffff00:  00000000 3fff0e9c 3fff197c 4021468f
  3fffff10:  4020ffa8 3fff0afc 3fff0fc4 40100690
  3fffff20:  40229e46 00000000 00000012 3fff0af8
  3fffff30:  4020ffa8 3fff0afc 3ffe9348 4020ffb6
  3fffff40:  40104d7e 948e6801 00000018 40210074
  3fffff50:  3ffe9348 3ffed9fc 948e6801 00000000
  3fffff60:  4022e654 3ffee928 3ffee950 60000600
  3fffff70:  0fc612e0 3ffee950 3ffee928 4022e661
  3fffff80:  4022e6a6 3fffdab0 00000000 3fffdcb0
  3fffff90:  3ffee968 40000f65 3fffdab0 00000000
  3fffffa0:  40000f49 3ffe96e8 3fffdab0 40000f49
  <<

  0x4020fb20: tcp_abort at core/tcp.c line 544

  0x4020ed35: netif_sta_status_callback at glue-lwip/lwip-git.c line 303

  0x402120ec: netif_set_ipaddr at core/netif.c line 545

  0x402137fa: dhcp_create_msg at core/ipv4/dhcp.c line 1825

  0x4021211a: netif_set_addr_LWIP2 at core/netif.c line 584

  0x4021463c: dhcp_release_LWIP2 at core/ipv4/dhcp.c line 1314

  0x4021468f: dhcp_coarse_tmr at core/ipv4/dhcp.c line 423

  0x4020ffa8: cyclic_timer at core/timeouts.c line 165

  0x40100690: free at /home/tony/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/umm_malloc/umm_malloc.c line 1739

  0x4020ffa8: cyclic_timer at core/timeouts.c line 165

  0x4020ffb6: cyclic_timer at core/timeouts.c line 171

  0x40210074: sys_check_timeouts at core/timeouts.c line 351

How can I find ou what happens at address 0x4020ec84 and what line it points to?


texts: Having trouble reading directly from VEML6075 UV sensor from its registers(I2C)

texts:
I'm kinda new to Arduino and decided to dive deeper into learning abit more about Arduino; So i decided to grab a Sparkfun VEML6075 UV sensor and try to:

1) Initialise it
2) Take readings from it

Without using the Sparkfun libraries at all. Based on what I read in the datasheets, this seems possible by using the I2C communication protocol provided by communicating directly with the registers of the device itself.

However, I can't seem to be able to even initialise the device properly as the readings I have gotten are weird and do not change (I presume this means the device only took one reading and stops at that)

My code is as below:

#include <Wire.h>

byte address = 0x10; // Slave address of the VEML6075
byte UVA_LSB, UVA_MSB;
word UVA_data;
uint16_t UVA_combined;
void setup() {
    Serial.begin(9600);
    Wire.begin();
    VEML6075_init(address);
//    uv.begin();
    Serial.println("Module is detected");
}

void loop() {
    VEML6075_Fetch_UV(address);   // Fetch UVA data *TEST*
    Serial.print("UVA: ");
    Serial.println(UVA_combined);
    delay(1000);
}

// shutdown module and init it; restarting the module
void VEML6075_init(byte address){
    Wire.beginTransmission(address);  // Shutdown command
    Wire.write(highByte(0x00));
    Wire.write(lowByte(0x01));
    Wire.endTransmission();

    Wire.beginTransmission(address);
    Wire.write(highByte(0x00));
    Wire.write(lowByte(0x12));   // Reset command using conf register
    Wire.endTransmission();
    delay(200); // Wait for module to reset
    // Done //
  }

 void VEML6075_Fetch_UV(byte address){
    Wire.beginTransmission(address);   // Begin transmission into I2C line with Slave address
    Wire.write(highByte(0x07));     // Issue command to read UVA data
    Wire.write(lowByte(0x07));
    Wire.requestFrom(address, 2);
    while(!Wire.available()); // Needs refining; read twice for 16 bits
    UVA_LSB = Wire.read();
    UVA_MSB = Wire.read();
    Wire.endTransmission();

    UVA_combined = ((UVA_MSB << 8) | UVA_LSB); // Combine to 16bits
  }

As stated in the datasheet:

  The VEML6075 contains a CONF register (00h) used for operation control and parameter setup. Measurement results are stored
  in four separate registers, one each for UVA, UVB, UVcomp1, and UVcomp2 (07h to 0Bh respectively). All registers are accessible
  via I2C communication. Fig. 7 shows the basic I2C communication with the VEML6075. Each of the registers in the
  VEML6075 are 16 bit wide, so 16 bit should be written when a write command is sent, and 16 bit should be read when a read
  command is sent.

I have allocated 16 bits for receiving the data, and have also used the conf address 0x12 to set the timing to 100ms and activate active-force-mode which i presume is the device taking readings automatically. The readings given are way off the accurate readings given when i upload a example code that uses the Sparkfun library, so I'm quite lost at this point. How am I using the I2C protocol wrongly? Thanks!


texts: Why did my program stop working when I eject the serial cable like it did an auto reset?

texts:
Arduino Uno based on 328p micro-controller board only works while I am inserting the serial cable between the board and the computer and I can control the speed of my two motors and every thing is work properly, but when I eject the serial cable it works badly and there is no control, is that some thing occurs like auto Reset?

There is always 5 volt feeding the Arduino, I get 5 volt regulated from the battery using "5v regulator", this regulated voltage is always connected to the Arduino board.


texts: Unable to send UDP packets while performing OTA update on the esp8266

texts:
I am sending specific UDP packets with my esp8266 every 5s, I have added an OTA update command, and added the update_progress callback aiming to send it back to my laptop, using a serial terminal I noticed that regular packets, as well as the progress packet, are not sent during the update, everything gets back after. Is the esp able to send and receive packets simultaneously?, is there any interference or the OTA update process causes an interruption?
Hardware: ESP8266MOD Nodemcu
Software: VS code with portable Arduino 1.8.9, espcore 2.6.3


texts: Fastest way to test if two integers differ by 4 or equal to each other

texts:
I'm searching for the fastest way to test if two integers are equal or differ by 4. The integers can be positive, negative and equal to zero. They are between -1000 and 1000 and are exclusively multiples of 4.

The simplest approach to test this should be this:

if(x == y || x - y == 4 || x - y == -4)
{
     //do something...
}

But since I want to do this 4 times inside of a interrupt sub routine I wanted to know if there is a faster way to do this.


texts: How Bootload an Lilypad Arduino USB using Arduino UNO

texts:
I recently bought two lilypads USB, one works perfectly (it's recognized in my computer, but the other one it's never recognized, I even try in different computers and the same scenario with both devices)

So I think that maybe the second one doesn't have a bootloader installed. So I'm triying to "burn" a new bootloader. I have been triying following the guide on https://www.arduino.cc/en/Tutorial/ArduinoISP using as programmer an Arduino UNO but without luck. I ever get avrdude: Device signature = 0x000000 (retrying). Thanks for the help!


texts:
I am looking at creating a fleet of low power, Arduino driven devices.

I would need some kind of GPS on them all (or could triangulate through phone network?) plus a connection to the internet - just for HTTP POST requests. GPRS or GSM would do but 3G would be better.

What are the best (price is a major factor because I'm trying to do a fleet) GSM, GPRS or 3G modules that I can use with Arduinos? As I said, I need their location so one with GPS built in would be great.

EDIT:
The amount of devices in the fleet will change, so the entire network needs to be dynamic which is why having a GPRS/GSM module on each one would work so well.


texts: How to program arduino for ethernet with only usb cable

texts: I have arduino UNO r3 ATMEGA 328P board and this kind of a cable. But I want to make and test a program that need to get the data through ethernet port. Can I do only with them. I want to know whether they are enough to that (there are any converter or virtual devices) or should I buy anything.


texts: Problem with Arduino Uno and SIM900 shield logical communication (rx & tx)

texts: The logical communication(rx & tx) between the shield and Arduino Uno doesn't  work. Arduino (rx & tx) supply  is 0 & 5 V but this is 0 & 2.8 V. What am I to do?


texts:
I'm trying to start with the SainSmart 4x20 serial LCD, and copied the library to the Arduino library:

So LiquidCrystal_I2C.h is included. But when I try to compile an example sketch it says

  Arduino: 1.7.0 (Windows 7), Board: "Arduino Uno"

  HelloWorld_i2c.pde:2:31: fatal error: LiquidCrystal_I2C.h: No such file or directory

  compilation terminated.

  Error compiling.

Any ideas how to fix this?


texts: Arduino Uno - Stepper motor not working with button

texts:
I am completely new to Arduino, and all sorts of hardware and software. I have a stepper motor, which I want to rotate by a number of rotations when I press a button, and then go backwards by a number of rotations when pressed again. I'm not getting any errors with the code, but it does not seem to do what I want. Before adding the button, the stepper motor worked fine, so I don't think it's malfunctioning. When the button is pressed, the LEDs on the H-bridge flicker, but there's no response at all from the motor. I don't know if it's a problem with the code or the set up.

#include <Stepper.h>
const float STEPS_PER_REVOLUTION = 4096;
const float GEAR_REDUCTION = 4;
const float TOTAL_STEPS = STEPS_PER_REVOLUTION * GEAR_REDUCTION
int StepsRequired = 16384;
int switchPin = 7;
boolean current = LOW;
boolean last = LOW;
boolean isOpen = LOW;
Stepper steppermotor (STEPS_PER_REVOLUTION, 8, 10, 9, 11);

void setup() {
  pinMode(switchPin, INPUT);
}

boolean debounce(boolean inLast) {
  boolean inCurrent = digitalRead(switchPin);
  if(inLast != current) {
    delay(5);
    inCurrent = digitalRead(switchPin);
    }
  return inCurrent;
}

void garageAction(float factor){
  StepsRequired = TOTAL_STEPS*factor;
  steppermotor.setSpeed(1000);
  steppermotor.step(StepsRequired);
  if (isOpen == LOW) {
    delay(3000);
  } else if (isOpen == HIGH) {
    delay(5);
  }
}

void loop() {
  current = debounce(last);

  if (current == HIGH && last == LOW && isOpen == LOW) {
    garageAction(2);
    isOpen = !isOpen;
  }

  if(current == HIGH && last == LOW && isOpen == HIGH) {
    garageAction(-2);
    isOpen = !isOpen;
  }
}

I would really appreciate any help with this - as mentioned, I'm completely new to any sort of hardware and software, and I'm also under time pressure to get this done, so I'd really appreciate any help in getting this solved. I could just be missing something really silly, but I'm completely lost.

Thanks in advance