texts:
Ive been trying to get POST working on my ESP8266. I followed this tutorial https://techtutorialsx.com/2016/07/21/esp8266-post-requests/ which works, but once i change the request URL to anything else i get -1 response from http.POST() which the library returns when "no info".
I have no clue what the "no info" means and what im doing wrong. Does anyone have any suggestions? Below is the code im using.
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

    HTTPClient http;    //Declare object of class HTTPClient

    //http.begin("http://192.168.1.88:8085/hello"); //Works fine
    //http.begin("https://httpbin.org:8080/post"); //Causes -1 as httpCode
    //http.begin("https://httpbin.org/post"); //Causes -1 as httpCode
    http.begin("https://XXXXX.execute-api.eu-west-2.amazonaws.com/XXXXX/XXXXX");
    http.addHeader("Content-Type", "application/json");  //Specify content-type header

    int httpCode = http.POST("{\"key\":\"1\",\"id\": \"ESPXXX2\",\"action\": \"rbg\",\"value\": \"255255000\"}");   //Send the request
    String payload = http.getString(); //Get the response payload

    Serial.println(httpCode);   //Print HTTP return code
    Serial.println(payload);    //Print request response payload

    http.end();  //Close connection

  } else {

    Serial.println("Error in WiFi connection");

  }

  delay(10000);  //Send a request every 10 seconds

Only serial output im getting is "-1" for httpCode and empty line for payload.


texts: AtTiny85 and MMA8452Q accelerometer cannot connect using i2c

texts:
I am trying to connect the MMA8452Q with AtTiny85 using the TinyWireM library.
I made the proper hardware setup with  pull-ups on  SCL and SDA pins - tested it on Arduino
Uno and it works, however when i connect the Tiny I cannot even get the handshake.
The following code produces output 13 instead of 42 (0x2A)

HARDWARE SETUP

MMA8452 Breakout ------------AtTiny85

3.3V -------voltage regulator------ 5V

SDA -----------^^(330)^^----------- PB0 (on attiny programmer marked as 5)

SCL -----------^^(330)^^----------- PB3 (on attiny programmer marked as 2)

GND --------------------------------- GND

(I also tried different pins with no luck)

CODE

//---bluetooth console communication stuff---//
#include <SoftwareSerial.h>
#define rxPin 1 //not important - needed for initialization
#define txPin A2
SoftwareSerial blueTooth(rxPin, txPin);
//      ---     //

#include "TinyWireM.h" // Used for I2C

// The SparkFun breakout board defaults to 1, set to 0 if SA0 jumper on the bottom of the board is set
#define MMA8452_ADDRESS 0x1D  // 0x1D if SA0 is high, 0x1C if low

#define WHO_AM_I   0x0D

void setup() {

  blueTooth.begin(9600);
  delay(1000);
  TinyWireM.begin(); //Join the bus as a master
  delay(1000);
 }

void loop() {
   byte c =0;
   c = readRegister(WHO_AM_I);
   blueTooth.println(c);
   delay(1000);
  }

 // Read a single byte from addressToRead and return it as a byte
byte readRegister(byte addressToRead) {
  TinyWireM.beginTransmission(MMA8452_ADDRESS);
  TinyWireM.send(addressToRead);
  TinyWireM.endTransmission(); //endTransmission but keep the connection active

  TinyWireM.requestFrom(MMA8452_ADDRESS, 1); //Ask for 1 byte, once done, bus is released by default

  while(!TinyWireM.available()) ; //Wait for the data to come back
  return TinyWireM.receive(); //Return this one byte
}

Would anyone know how to get it right?


texts: How can I power a NeoPixel ring and strip through Arduino MKR1000?

texts:
I currently have a MKR1000 which is connected to 1 ring with 8 neopixels, 1 strip with 20 neopixels, 1 microwave sensor, 1 speaker, 1 rotary encoder. I am running the NeoPixel positive and negatives through a 220 µF capacitor, and the data pins through 220 Ω resistor.

I am soldering these components onto a board, but currently, when I plug the MKR1000 into my USB it says it's drawing too much power, the Arduino also smokes and I can smell burning, so disconnected straight away.

What am I doing wrong?


texts: How do I fix this error? It says "warning: invalid conversion from 'long int*' to 'long int' [-fpermissive]

texts:
I am working on an assignment that converts a reading of force into pounds and then finds the maximum and average of all the values received

This is my code:

void setup()
{

 // put your setup code here, to run once:

 Serial.begin(9600);

  // declare the outputs and inputs
  pinMode( 0 , INPUT);

  //figure out what pin the reading is going to be input to

  fsrReading = analogRead( 0 ) ;
  //the # is the same pin used to get input

  //or use analogRead ( # ), it depends if the pin input is on the analog side of the arduino

  // should this be under the while loop or here?

  //list functions here
  long ForceInPounds(long);
  long FindMax(long);
  long FindAvg(long);

  //declaring variables of functions
  FM = FindMax(new long);
  FA = FindAvg(new long);

        Serial.println("The max value is:");
        Serial.println(FM); //calls FindMax function

        Serial.println("The average value is:");
        Serial.println(FA); //calls FindAvg function

  }

void loop()
{
  // put your main code here, to run repeatedly

 int counter1= 0;

  while (counter1< 100)
  //runs test 100 times

  //should I just make this a function? instead of embedding it in the void loop

 {
      Serial.print("Analog reading = ");

      Serial.println(fsrReading);

      //declaring variable of function used in this segment
      FiP = ForceInPounds(new long);

      Serial.print("Force in Newtons:");
      Serial.println(FiP); //calls ForceinPounds function

      counter1 ++;
  }

}

//FUNCTIONS

long ForceInPounds(const long)
// converts recorded voltage to resistance to conductance to force to pounds
{
 fsrReading = fsrVoltage;

 if (fsrVoltage== 0)
 {
   Serial.print("No pressure");
 }
 else
 {
   fsrResistance = 5000.0 - fsrVoltage;
   //convert voltage to resistance
   fsrResistance *= 10000.0;
   fsrResistance /= fsrVoltage;
   fsrConductance = 1000000.0 ;

   //convert resistance to conductance
   fsrConductance /= fsrResistance;
   if (fsrConductance <=1000.0)
   //convert resistance to conductance
   {
     fsrForce = fsrConductance/80.0;
   }
   else
   {
     fsrForce = fsrConductance - 1000.0;
     fsrForce /= 30.0;
   }
   fsrPounds = fsrForce/4.45;

   //convert force to pounds
 }

 return fsrPounds;
}

long FindMax(long)
{
  int counter2 = 0;

  while (counter2 < 100);
  {
    if ( fsrPounds > maximum)
    {
          maximum = fsrPounds;
          counter2++;
    }
    else
    {
          maximum = maximum;
          counter2++;
    }

  }
  return maximum;

}

long FindAvg (long)
{
  long start = 0;
  //variable to begin avg function
  long avg;
  int counter3 = 0;

  while (counter3 < 100);
  {
    start = start + fsrPounds ;
    counter3 ++;
  }

  avg = start/100;
  return avg;
}

What am I doing wrong? This is my first time working with Arduino.
Thanks


texts:
i want to press "unu" button of the remote, and the motor to rotate continuously, and when i press "sound" i want the motor to rotate untill the hall sensor detects a magnetic field. any ideas please?
in this configuration, even if i press "unu" or "sound", the motor rotates untill the hall sensor detects a magnetic field.

#include <TLE94112.h>
#include <Tle94112Motor.h>
#include <IRremote.h>

#define unu 0x1
#define sound 0x55

int RECV_PIN = 2;
int hallSensorPin1 = 3;
int state1;
int oldState1 = 1;

Tle94112 controller = Tle94112();
Tle94112Motor motor1(controller);

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{ irrecv.enableIRIn();
  controller.begin();

  motor1.connect(motor1.HIGHSIDE, controller.TLE_HB1);
  motor1.connect(motor1.LOWSIDE, controller.TLE_HB2);
  motor1.setPwm(motor1.HIGHSIDE, controller.TLE_PWM2);
  motor1.setPwmFreq(motor1.HIGHSIDE, controller.TLE_FREQ200HZ);

  motor1.begin();
}

void loop()
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }//add bracket here

  if (results.value == unu || results.value == 0x801 || results.value == 0x2049) {
    motor1.start(63);
  }

  if (results.value == sound || results.value == 0x55 || results.value == 0x2103 || results.value == 0x837 || results.value == 0x37) {
    motor1.start(63);

    oldState1 = 1;
    state1 = digitalRead(hallSensorPin1);

    if (state1 == LOW && oldState1 == 1) {
      motor1.coast();

    }
  }
}


texts: How to correctly use functions that return pointers to multiple typedef'ed types in Arduino IDE?

texts:
I have a program that typedef's two structs. Each one has a corresponding function that returns a pointer to it....

typedef struct {
  int x1;
} x;

x *a;

x *f(void) {
  return a;
}

typedef struct {
    int  y1;
} y;

y *b;

y *g(void) {
  return b;
}

void loop(void) {

}

void setup(void) {

}

This program produces the following error when compiled under the Arduino IDE...

sketch_nov10a:18: error: 'y' does not name a type

 y *g(void)

If we copy/paste to switch the order of the two blocks like so...

typedef struct {
    int  y1;
} y;

y *b;

y *g(void) {
  return b;
}

typedef struct {
  int x1;
} x;

x *a;

x *f(void) {
  return a;
}

void loop(void) {

}

void setup(void) {

}

...then we instead get the following error...

sketch_nov10a:18: error: 'x' does not name a type

x *f(void)

...so apparently the Arduino IDE only supports functions that return pointers to the first typedef'ed type defined in the file?

Is there a rational to this? How would you implement the above code to get it to compile under the Arduino IDE (it works fine in gcc).


texts: Can an IC be programmed by an Arduino and then be removed, to be used in an external breadboard?

texts: I wanted to find out if is possible to write programs into a micro controller using the Arduino and use the micro controller independent of the Arduino board?


texts: Making '*' key on keypad a backspace key

texts:
Using a 4x3 membrane keypad and I want to make the '*' key a backspace if the wrong number is entered.

I am a newbie and having a hard time trying to figure out how to code that, any help would be great.

int getNumber()
{
  int num = 0;
  char key = myKeypad.getKey();
  while (digitCount <=  1)
  {
    switch (key)

    {
    case NO_KEY:
      break;
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      num = num * 10 + (key -  48);
      digitCount++;
      break;
    case '*':
      break;
    case '#':
      break;
    }
  key = myKeypad.getKey();
  }

  digitCount = 0;
  return num;
}


texts: What is the function of the XBee / USB switch on an XBee shield?

texts: I recently bought an XBee shield (this). The shield has a switch that seems to switch between USB/XBee. However, there is no USB port. What exactly is the switch supposed to do?


texts: Is it possible to put priorities between external interrupts?

texts:
My question is quite simple. I am using one external interrupt on the Mega2560 to wake it up with an alarm from the rtc DS3231 and record data from sensors for about 30 seconds and I would like also to use the other external interrupt to wake it up in case of shock detection to measure the signal.

The thing is that I know external interrupts have priority on internal interrupt but is it possible to put, in my case, the shock detection prior to the alarm ? In case the shock occurs during the alarm recording I would prefer to record the shock signal.

Thank you for your help !


texts: Upload code on Arduino Leonardo using command line

texts:
I'm trying to upload a compiled .hex file on an Arduino Leonardo, using the terminal. Uploading a sample code using the Arduino IDE works well, and from the Arduino IDE I got the upload command

avrdude -C/etc/avrdude.conf -patmega32u4 -cavr109 -v -v -v -v -P/dev/ttyACM0 -b57600 -D -Uflash:w:[file.hex]:i

But executing it I got the following error

Connecting to programmer: .avrdude: Send: . [1b]
avrdude: Send: S [53]
avrdude: Recv: . [15]

avrdude: ser_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding

What's wrong?


texts: I just want to control a 48 volt and 30 amp current with pwm singnal...i don't nkow what components is needed for this

texts: I just want to adjust voltage of a dc dc converter output with pwm signal...i used MOSFET but i get some heating effect..please tell me what model of MOSFET or ijbt or anything else which components is more reliable...


texts:
I want to control a stepper while displaying user menus on a freetronics style  16x2 LCD. I'm using liquidcrystal for my menus and in order to get non-blocking control of the stepper I've imported the StepperLab3 library.

The problem is that the two seem to be incompatible. Either will work if I disable the other, but if I try to run them both, the output on the LCD screen is garbled, and I don't think the stepper driver is working (though I haven't tested it fully - the current sketch uses menu functions to control the stepper and since the menus don't work I can't use it).

I believe the problem is that they're both wanting to use the same timer(…?). This belief is based on this warning on the stepperLab page

  Keep in mind that the library is using ATMEGAs timer1 and the corresponding interrupt. Some other libraries or arduino functions might work not correct.

Would a workaround be to try another timer? How many does the Uno have available? Would the LCD be using the timer or interrupts to do PWM for the LED that illuminates the screen?

In the SpepperLab source the timer is set-up here:

void StepperLab3::_setupTimer() {
#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)

// set Timer 1 prescaler to 1
TCCR1B &=  ~((1<<CS11) | (1<<CS12));  // Reset Bits
TCCR1B |=  (1<<CS10);    // set Bits

// Fast PWM 10 bit , WGM13=0,WGM12=1 WGM11=1, WGM10=1
// 64uS / 15.625 KHz

TCCR1A |= (1<<WGM11) ;  //  WGM10=1
TCCR1B |= (1<<WGM12) ;  //  WGM10=1
TCCR1A |= (1<<WGM10);  //  WGM11=1
TCCR1B &= ~(1<<WGM13);  //  WGM13=0
//TCCR1B |= (1<<WGM13);  //  WGM13=1

//OCR1A=500;

// set pins as pwm output
TCCR1A |= ((1<<COM1A1) | (1<<COM1B1));

// enable Timer1 Interrupt
TIMSK1 |= (1<<OCIE1A);

Am I going to be able to do a find-and-replace for TCCR1* and change it to TCCR3*?


texts: Plug/socket between thermocouple wires and the amplifier

texts:
I am building a temperature monitoring system that has 24 thermocouples. Managing all the wires is a hassle, and I'd like to connect all 48 wires to a few plug and socket connectors. Maybe 6 of these lead wire harnesses from eBay (see below).

The point of this would be to allow me to quickly disconnect all the thermocouples from their amplifiers when I need reposition the arduino, and then reconnect them afterwards without tracking each individual cable.

I don't know if this will have a negative impact on the function of the thermocouples. Is it ok to have a 'joint' (i.e., the socket) in the thermocouple cables, or do they need to remain intact from the end all the way to the amplifier?

Alternatively, would having a few inches of regular copper wire inserted between the thermocouple wires and the amplifier be ok? That is, having two copper wires attached to the amplifier, joining 8 of these wires together in a socket, and attaching the plug to the actual thermocouple (alumel/chromel) wires? The thermocouple wires are several feet long.


texts:
I'm new at using Xbee and I would like to get some help on how to interpret API packets. Me setup consists of two arduino unos, two xbee S2, two xbee shields and a one magnetometer sensor HMC5883L.  The sensor is connected to the arduino via I2C and transmitting the data to the xbee (router) using serial communication. On the other side (coordinator) I'm reading and displaying the data on the serial monitor. I have read the data sheet of the xbee but I still can't figure how to interpret the packet. Here is a screen shot of the values that I'm getting on the serial monitor on the router and the corresponding packets on the coordinator's serial monitor.

There are four bytes that are changing each time so how can I translate them to an integer value. Any help would be greatly appreciated.


texts: PWM pins weird on Arduino Mega, works on Arduino Uno

texts:
I've bought one of those cheap 2.4" TFT LCD resistive touchscreens, one of these:

It works great on my Arduino Uno, using the code from this github repository.  Now I'm trying to get this to work on my Arduino Mega.

On the Arduino Uno, the LCD controller data lines are configured as:

data[0:7] = PORTB[0:1] | PORTD[2:7]

ie. data pins 8, 9, 2, 3, 4, 5, 6, 7 make up the LCD controller data lines.

On the Mega, the pin numbers are the same but the ports are configured differently, so that:

data[0:7] = ((PORTH >> 5) & 0x03)
   | ((PORTH << 3) & 0xc0)
   | ((PORTG >> 1) & 0x10)
   | ((PORTE >> 2) & 0x0C)
   | ((PORTE << 2) & 0x20)

I've rewritten the TFTLCD::read8 and TFTLCD::write8 functions accordingly.

The screen doesn't work, though.  I've cut example code down to just resetting the LCD controller and reading the chip ID register, ie:

Tft.writeData(0);
Tft.writeData(0);
Tft.writeData(0);
Tft.writeData(0);

Tft.writeCommand(0);
unsigned id = Tft.readData();

Now, 9 times out of ten, this obtains the correct device ID, 0x9325.  But the other time, it obtains the device ID of 0.

I initially suspected that this was due to the Mega running somewhat faster, but liberally sprinkling delayMicroseconds(10) through the writeData, writeCommand and readData functions doesn't seem to make any difference.

Is there something that I'm missing that is messing with the use of the PWM lines on the Arduino Mega as ordinary digital port pins?


texts:
I am making a fun LED Christmas tree project using this code:

// Source location \\adam\U_DRIVE\_BACKED_UP\_Documents\Electronics\XmasTree
#include <FastLED.h>
#define NUM_LEDS 102
#define DATA_PIN 6
CRGB leds[NUM_LEDS];
void setup() {
  Serial.begin(9600);
  Serial.println("Boot");
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

  //  SetRandomLight;
  SetAllOff();
  delay(10); //Delay before getting going.
  BootUp();
  randomSeed(analogRead(0) + analogRead(1) + analogRead(2) + analogRead(3) + analogRead(4) + analogRead(5) + analogRead(6));
}

void loop() {
  // put your main code here, to run repeatedly:
  SingleDrift();
  FastLED.show();
  //delay(random(50));
}

void FadeAll(int x)
{
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i].subtractFromRGB(x);
  }
}

void SetRandomLight() {
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i].r = random(128);
    leds[i].g = random(128);
    leds[i].b = random(128);
    Serial.println(i);
  }
}

void SetAllOff()
{
  Serial.println("Blanking all.");
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] = 0x000000;
    leds[i].r = 0;
    leds[i].g = 0;
    leds[i].b = 0;

    //Serial.println(i);
  }
  FastLED.show();
}

void SingleDrift() {
  int mini = 5;
  int maxi = 255;
  FastLED.setBrightness(maxi);
  for (int i = 0; i < NUM_LEDS; i++)
  {
    if (leds[i].r > 64) leds[i].r = leds[i].r - 8;
    if (leds[i].g > 64) leds[i].g = leds[i].g - 8;
    if (leds[i].b > 64) leds[i].b = leds[i].b - 8;

    int rnd = random(10);
    if (rnd == 1 && leds[i].r >= 2) leds[i].r = leds[i].r - 1;
    if (rnd == 2 && leds[i].g >= 2) leds[i].g = leds[i].g - 1;
    if (rnd == 3 && leds[i].b >= 2) leds[i].b = leds[i].b - 1;
    if (rnd == 4) leds[i].fadeToBlackBy(2);
    if (rnd == 5) leds[i].g++;
    //if (rnd == 6 && leds[i].g < 240) leds[i].g = leds[i].g + 1;
    //if (rnd == 7 && leds[i].b < 240) leds[i].b = leds[i].b + 1;
    if (leds[i].g < 2) leds[i].g = 2;
  }

  int i = random(NUM_LEDS);
  Serial.println(i);
  if (leds[i].r + leds[i].g + leds[i].b > 10) return; //If the LED is still bright, do not change it.
  if (random(100) > 80)
  {
    //Choose a colour
    int r = random(20);
    switch (r)
    {
      case 99:
        for (i = 0; i < NUM_LEDS; i++)
        {
          int x = leds[i].r;
          leds[i].r = leds[i].b;
          leds[i].b = x;
        }

      case 1:
      case 2:
      case 3:
        leds[i] = CRGB::Red;
        break;
      case 4:
      case 5:
      case 6:
        leds[i] = CRGB::Green;
        break;
      case 7:
        leds[i] = CRGB::Blue;
        break;
      case 8:
        leds[i].r = random(128, 255);
        leds[i].g = random(128, 255);
        leds[i].b = random(128, 255);
      case 9:
        leds[i] = CRGB::Yellow;
        break;
      case 10:
        leds[i] = CRGB::Crimson;
        break;
      case 12:
        leds[i] = CRGB::Aqua;
        break;
      case 13:
        leds[i] = CRGB::BlueViolet;
        break;
      case 14:
        leds[i] = CRGB::MidnightBlue;
        break;
      case 15:
        leds[i].setRGB( 255, 255, 255);
        break;
    }
  }
}

void BootUp()
{
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i].b = map(i, 0, NUM_LEDS, 0, 255);
    leds[i].r = map(i, NUM_LEDS, 0, 0, 255);
  }
  for (int pc = 0; pc < 100; pc++)
  {
    FastLED.setBrightness(pc);
    FastLED.show();
    delay(3);
  }
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] = -leds[i];
    FastLED.show();
    delay(10);
  }

  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i].setRGB( 0, 10, 0);

    FastLED.show();
    delay(10);
  }
}

The LED cycle currently fades to green every time, so I would like to add different color fades. However, I could not figure out how to change the color/timing after poking around. Could someone please point me in the right direction for what I changes to the code I need to make?


texts: PCINT with my arduino UNO says redefinition of 'void __vector_4()'

texts:
So i'm working on a quadcopter controlled by the arduino UNO, and focusing in pin interrupts for the reciever. This is the code for the reciever.

unsigned long timer[4];
byte last_channel[4];
volatile int input[4];

void rx_initialize() {
  PCICR |= (1 << PCIE0);
  PCMSK0 |= (1 << PCINT0);
  PCMSK0 |= (1 << PCINT1);
  PCMSK0 |= (1 << PCINT2);
  PCMSK0 |= (1 << PCINT3);
  Serial.begin(9600);
}

ISR(PCINT1_vect) {

  timer[0] = micros();//Lire la valeur PWM en microsecondes

  //////////////////////////CHANNEL1/////////////////////////////
  if(last_channel[0] == 0 && PINB & B00000001){//vaut digitalRead(HIGH); mais en plus rapide
    last_channel[0] = 1;//le state est HIGH
    timer[1] = timer[0];//Lire combien de temps HIGH
  }
  else if(last_channel[0] == 1 && !(PINB & B00000001)){
    last_channel[0] = 0;//le state est HIGH
    input[0] = timer[0] - timer[1];
  }

  //////////////////////////CHANNEL2/////////////////////////////
  if(last_channel[1] == 0 && PINB & B00000010){//Rising
    last_channel[1] = 1;//le state est HIGH
    timer[2] = timer[0];//Lire combien de temps HIGH
  }
  else if(last_channel[1] == 1 && !(PINB & B00000010)){//Falling
    last_channel[1] = 0;//le state est HIGH
    input[1] = timer[0] - timer[2];
  }

  //////////////////////////CHANNEL3/////////////////////////////
  if(last_channel[2] == 0 && PINB & B00000100){//Rising
    last_channel[2] = 1;//le state est HIGH
    timer[3] = timer[0];
  }
  else if(last_channel[2] == 1 && !(PINB & B00000100)){//Falling
    last_channel[2] = 0;//le state est HIGH
    input[2] = timer[0] - timer[3];
  }

  //////////////////////////CHANNEL4/////////////////////////////
  if(last_channel[3] == 0 && PINB & B00001000){//Rising
    last_channel[3] = 1;//le state est HIGH
    timer[4] = timer[0];
  }
  else if(last_channel[3] == 1 && !(PINB & B00001000)){//Falling
    last_channel[3] = 0;//le state est HIGH
    input[3] = timer[0] - timer[4];
  }
}

I'm using various files for every other part of the quadcopter such as PID controlling and IMU Reading.

But avrdude tells me that I did a redefinition of 'void __vector_4()'.
Itried to look into PinChangeInt.h in the Arduino library folder but still no solution to the problem.

Thank you for your help!


texts: I have an Arduino Uno rev 3. Today i tried to mount a breadboard as a shield for my Arduino on top of it. I plugged in the pin headers i bought and was surprised that the breadboard won't fit. As you can see in the picture below the distance between Vin and A0 is exactly the size of a pin, but the distance between pin 7 and 8 is less than that and so the breadboard won't fit on this side. What's the reasoning behind this (in my eyes) bad design ?


texts: Serial Port fails with speeds greater than 19200

texts:
In Arduino Mega 2560 R3, properly selecting the Serial Monitor bauds, this code works with #define R 38400, but for some reason, not with #define R 19200 (?),

#define R 38400
int rate=R;
HardwareSerial* hwSerial[]={&Serial,&Serial1,&Serial2,&Serial3};
void setup() {
    for (int i=0;i<=3;i++){
        hwSerial[i]->begin(rate);
        while (!hwSerial[i]);
    }
    hwSerial[0]->print("Hello World");
}

void loop() {
}

Both speeds should be not problematic for Arduino, what is happening?

It seems the int rate R; is problematic when changing speeds (??).


texts: Arduino-compatible Bluetooth classic module to use in a product

texts:
I've been designing a product for some time using arduino language, but on our own hardware. Recently a need arose to add some Bluetooth capability to our product. We decided to use BT classic instead of BLE, because not every phone has BLE capability yet. Of course immediately I went to check HC-05 modules and their cousins. The issue is I believe they are a chinese product and have no FCC certification and I can't buy them from any reputable source (digikey,mouser,farnell etc.).

Seeing that this is an issue for a product I went and checked the mentioned suppliers to see what they offer. The thing is though, I'd like to stay in the arduino environment so I'm looking for a module that has some support from the arduino side.

I found this module from Cypress, that has this "arduino-compatible" code. However when a tried to find any library that I could use to program this board using arduino environment on Cypress's site I only found mentions of their own SDK.

Thus comes the question: are there any FCC compliant bluetooth modules that have an easy to use arduino library available?


texts: using references to SFRs in gcc inline assembler

texts:
I want to write a driver that can use either timer0 or timer2, based on a choice made at compile time.

So I want all references to timer registers to be abstracted, e.g. OCRA for OCR0A/OCR2A, etc.

I could do it with plain macros, like so:

#define _CONCAT3(a,b,c)   a##b##c
#define CONCAT3(a,b)   _CONCAT3(a,b,c)

// set timer number globally
#define MY_TIMER 2

// define an alias for each control register
#define OCRA CONCAT3(OCR, MY_TIMER, A)

but for some reason I don't want to use macros there.

So I came up with this scheme:

typedef volatile uint8_t& tRegister;

constexpr volatile uint8_t& timer_register (volatile uint8_t& a, volatile uint8_t& b)
{ return MY_TIMER==0 ? a : b; }

tRegister OCRA = timer_register (OCR0A, OCR2A);

It works pretty well for all its awkwardness, but when I try to use this definition in an inline assembly directive, I get strange results:

asm volatile("lds r24, %0" : : "i"(&OCRA));

will get an error: impossible constraint in 'asm'

Now this:

asm volatile("lds r24, %0" : : "i"(&timer_register (OCR0A , OCR2A )));

will compile (and produce lds r24, 0x00B3 as it should).

By definition a reference to a static variable is a constant address, known at compile time, so I can't see why it can't be used in this context.

So my questions are:

what is going on there?
how to alias these registers (without macros) to please the inline assembler?


texts: What is the sizeof() Arduino's built in HIGH and LOW?

texts: This might be a stupid question to ask but I'm curious. I decided to test this myself and I got a value of 2 for both HIGH and LOW, why would it output 2?


texts: How to send sensor data from Arduino through NRF24L01 to Raspberry Pi

texts:
I am able to send text from the Arduino wirelessly to RPi.  I am now trying to send the sensor data I'm measuring to the Pi.  This is what I have below:

int moisture = A0;
int temp = 3;

//Skipping the setup and reading of the values

radio.write(&moisture);
radio.write(&temp);

//the above couple lines is where I start having trouble.  The RPi will spit output a seemingly random selection of numbers


texts: MacOS 10.15.1 Catalina CU port always busy, and TTY port not selectable

texts:
I am trying to use an FTDI breakout board to connect to my custom made Arduino compatible board. I am using a new 16 inch macbook pro with USB-c ports, so I am using a dongle, in case that could be the problem.

Every time I try and upload a sketch I get the error: "can't open device "/dev/cu.usbserial-D306P6WW": Resource busy". When I check the /dev/ folder, both "/dev/cu.usbserial-D306P6WW" and "/dev/tty.usbserial-D306P6WW" show up, however in Arduino IDE I can only choose the "/dev/cu.usbserial-D306P6WW" option. I have installed FTDI VCP drivers, CH340 drivers and all kinds of other drivers to try and fix this issue. I have restarted countless times, and I have used a multitude of commands to check for programs hogging the usb port, but there is never a program. Plugging a harddrive into the same port causes no problems, so the port can't really be the problem. I am using a "FTDI FT231XS" board from Sparkfun.


texts:
I'm using an Arduino Due with various sensors. At the moment, I'm using the majority of the pins along the width (the double width pins). I want to make the setup more permanent, however I can't seem to find any ribbon cables with 36-conductors. What do you use for long term connections on the Due, especially if you occasionally need to unplug all the connections? Would a 40-pin ribbon cable work as they're easy to come by.

Thanks


texts: ADXL345 Data Rate seems to depend more upon Baud rate than the actual Data Rate that I set


texts: Menu with switch case not behaving correctly

texts:
I hope this the right place to post this question :)

I'm trying to display a menu on a SSD1351 OLED display, to which I communicate with U8glib. I'm trying to obtain an Init screen, then, with a long press on a button (Menu), get in to a menu with 3 options (let's say option1, option2 and back). I got it working this way:

#include <Button.h>  // https://github.com/JChristensen/Button.git
#include "U8glib.h"
#include <Wire.h>

#define PULLUP true
#define INVERT true
#define DEBOUNCE_MS 20

Button ok(2, PULLUP, INVERT, DEBOUNCE_MS);
Button menu(5, PULLUP, INVERT, DEBOUNCE_MS);
Button down(3, PULLUP, INVERT, DEBOUNCE_MS);
Button up(4, PULLUP, INVERT, DEBOUNCE_MS);
U8GLIB_SSD1351_128X128_332 u8g(8, 9, 7);
uint8_t screen = 0;
uint8_t menu_current = 0;
void setup() {
  u8g.setFont(u8g_font_unifont);
  u8g.setDefaultForegroundColor();
  drawScreen();
}

void loop() {
  ok.read();
  menu.read();
  up.read();
  down.read();
  if (menu.pressedFor(1000) && screen == 0) {
    screen = 1;
    menu_current = 0;
    drawScreen();
  }
  if (screen == 1) {
    if (up.wasReleased()) {
      if (menu_current > 0) {
        menu_current--;
        drawScreen();
      }
    }
    if (down.wasReleased()) {
      if (menu_current < 2) {
        menu_current++;
        drawScreen();
      }
    }
    if (ok.wasReleased()) {
      switch (menu_current) {
        case 0:
          screen = 2;
          break;
        case 1:
          screen = 3;
          break;
        case 2:
          screen = 0;
          break;
          break;
      }
      drawScreen();
    }
  }
  if (screen == 2 || screen == 3) {
    if (menu.wasReleased()) {
      screen = 1;
      menu_current = 0;
      drawScreen();
    }
  }
}

void drawScreen() {
  u8g.firstPage();
  do {
    whatToDraw();
  } while (u8g.nextPage());
}

void whatToDraw() {
  switch (screen) {
    case 0: {
        u8g.drawStr(0, u8g.getFontLineSpacing(), F("Init"));
      } break;
    case 1: {
      const char *menu_strings[3] = { "option1", "option2", "Back" };
      uint8_t i, h;
      u8g_uint_t w, d;
      u8g.setFontRefHeightText();
      u8g.setFontPosTop();
      h = u8g.getFontAscent() - u8g.getFontDescent();
      w = u8g.getWidth();
      for ( i = 0; i < 3; i++ ) {
        d = (w - u8g.getStrWidth(menu_strings[i])) / 2;
        u8g.setDefaultForegroundColor();
        if ( i == menu_current ) {
          u8g.drawBox(0, i * h + 1, w, h);
          u8g.setDefaultBackgroundColor();
        }
        u8g.drawStr(d, i * h, menu_strings[i]);
      }
    }
    break;
    case 2: {
      u8g.drawStr(0, u8g.getFontLineSpacing(), F("Option1"));
    }
    break;
    case 3: {
      u8g.drawStr(0, u8g.getFontLineSpacing(), F("Option2"));
    }
    break;
    break;
  }
}

Everything seems to be working except the back option: when I select it, the display gets blanked instead of visualizing screen 0 ("Init"). Variables seem to be set correctly. Does anybody have an idea why this isn't working?

Thank you :)

Dario

EDIT: copied the whole sketch as requested :)


texts:
So I'm working for a project to control RGB Led Strip using microphone or sound sensor with Arduino Nano. I'm using 5050 RGB Led Strip around 120 LEDs, and I control them using simple transistor circuit to each channel R, G, and B, then I connect the base of the transistors to the resistors and PWM Outputs of the Arduino. And then I'm using KY-038 Sound Sensor (I'm using the Analog Output pin) and connect it to Arduino A0.

The problem is when I didn't connect the LEDs, the microphone worked correctly. I processed the analog input, put filter and threshold. When I connected the LEDs, the reading of the A0 is disturbed by the transition of the LED (for example from 0% PWM to 50% PWM or ON). As the result, my analog read detected it as a voltage swing and recognize it as a sound, and trigger the LEDs, then oscillating without any external sound. If I disconnected the LEDs, it worked correctly, for example I change it to Arduino Built-In LED, it turned on according to the external sound.

Why does this happen? I don't think they share the same timer, and I also use proper Power Supply and Capacitor to provide the enough power.

My project is similar to this project.


texts: Coding and libraries for Maxtronix Ultrasonic sensors

texts:
I need to access distance data using a LV-EZ0 Maxtronix ultrasonic sensor: MB1000
LV-MaxSonar®-EZ0™High Performance Ultrasonic Rangefinder

Can anyone suggest what particular arduino libraries or code would be most useful?

I noticed this new ping library, NewPing

Would this work for my purposes with this particular sensor?


texts: Is there a way to setup an interrupt to trigger at n number of clock cycles from now?

texts:
I currently have an nRF transmitter/receiver pair setup on my desk. The transmitter is sending a single byte (0xAA) every 5ms. The receiver sets an LED high to indicate that it received the byte, which is about 10us (+/-2) after the byte was sent. I want to use this nRF pulse for a precise timing/sync application with +/-0.5us accuracy so I need to filter these receiver pulses such that I can estimate the time the transmitter actually sent the byte and the time the next one should arrive. I created an algorithm that uses past nRF pulse times (measured in clock cycles using Teensy's ARM_DWT_CYCCNT register) to estimate the next pulse and it seems to be working reasonably well - though I can't say yet if I'll get the 0.5us accuracy I want.

Now I want to take that estimate and have my microcontroller set an output pin high as soon as the clock count reaches the estimated clock value. Currently I do this by waiting in a while loop and polling the register, but the loop itself takes up several hundred clock cycles which reduces my accuracy. Is there a way to instead have an interrupt trigger when the clock cycle counter reaches my estimated value? I would somehow need to set this interrupt after computing each estimate.

Thanks!


texts:
I am facing issues while uploading sketch to Adafruit Feature 32u4 Bluefruit LE devices. When i try to upload Blink demo it was working fine and my device also blinking, But bellow error i am getting every time when i upload sketch.

   System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
     User configuration file is "/Users/myMacmnin/.avrduderc"
     User configuration file does not exist or is not a regular file, skipping

I am using Adafruit Feature 32u4 Bluefruit Le device,Arduion 1.8.3 version, MacMini with macOs Sierra(10.12.3).


texts: else if is ignored if not Serial.println anything before

texts:
I encountered to me inexplicable behavior on an arduino uno.
I'm serial reading a string from the serial monitor/python serial. This string is the conditional on several if/else if statements.
The crazy thing is, some strings just get ignored, but if I print out the read string after reading it, the ignored statements then get executed and the script works the way it's supposed to.
This is the code:
// power outlet 1
# define OUT_1_1 2 // relay #4
# define OUT_1_2 3 // relay #3

// power outlet 2
# define OUT_2_1 4 // relay #2
# define OUT_2_2 5 // relay #1

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  // power outlet 1
  pinMode(OUT_1_1, OUTPUT);
  pinMode(OUT_1_2, OUTPUT);

  // power outlet 2
  pinMode(OUT_2_1, OUTPUT);
  pinMode(OUT_2_2, OUTPUT);

  // init outputs to HIGH
  digitalWrite(OUT_1_1, HIGH);
  digitalWrite(OUT_1_2, HIGH);
  digitalWrite(OUT_2_1, HIGH);
  digitalWrite(OUT_2_2, HIGH);

  Serial.begin(9600);
}

void loop() {
  String str = "";

  // checking for bytes in the buffer
  if (Serial.available() > 0) {
    str = Serial.readStringUntil("\n");
  }
  // Serial.println(str); // if this line is uncommented serial input "2_ON\n" and "2_OFF\n" is recognized and outled 2 is successfully switched

  // identity
  if (str == "IDN\n") {
    Serial.println("Serial Power Outlet");
  }

  // controlling power outlet 1
  else if (str == "1_ON\n") {
    digitalWrite(OUT_1_1, LOW);
    digitalWrite(OUT_1_2, LOW);
  }
  else if (str == "1_OFF\n") {
    digitalWrite(OUT_1_1, HIGH);
    digitalWrite(OUT_1_2, HIGH);
  }

  // controlling power outlet 2
  else if (str == "2_ON\n") {
    digitalWrite(OUT_2_1, LOW);
    digitalWrite(OUT_2_2, LOW);
  }
  else if (str == "2_OFF\n") {
    digitalWrite(OUT_2_1, HIGH);
    digitalWrite(OUT_2_2, HIGH);
  }
  delay(1000);
}

If I serial input 2_ON\n or 2_OFF\n the according else if blocks are just ignored (all other inputs work correctly).
But after I've uncommented // Serial.println(str); these blocks are executed the way they are supposed to and all works just fine.
Where is my mistake, what am I getting wrong here?
These blocks also get executed if I Serial.println any random output.
Why do I have to Serial.println something first so my script works according to plan? What am I missing?
EDIT: added all of the code.


texts: How to flash hex files from a micro SD card to an Arduino Nano using an SD card module?

texts:
I want to flash a hex file stored in a micro SD card into an Arduino [Uno/Nano]. So far I can read and write to the SD card using Arduino.

Without modifying the bootloader, is it possible to flash the Arduino using micro SD card module?


texts: Setting reading frequency SCT013 current sensor code using Arduino Uno

texts:
I found this code below for the Arduino platform to obtain current measurements from the SCT013 sensor, and I am wondering how can I define the 'delay' or 'frequency' of my readings? I'd be looking for 200Hz.

Code:

//
#include "EmonLib.h"                   // Include Emon Library
EnergyMonitor emon1;                   // Create an instance

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

  emon1.current(5, 60);             // Current: input pin, calibration.
  //calibration is explained bellow
}

void loop()
{
  double Irms = emon1.calcIrms(1480);  // Calculate Irms only

  Serial.print(Irms*230.0);        // Apparent power
  Serial.print(" ");
  Serial.println(Irms);            // Irms
}
//


texts:
I often see code like this:

const int piezo = A0;
const int sensorPin = A1;

From my understanding, an int variable can hold things like -123, 0, 1, 456, etc.

How can A0 or A1 be an int?


texts:
My project, briefly explained is a weather station that will send data periodically from an Arduino UNO (later an attiny85) to my PC for processing. I'm using a HC-05 bluetooth module to establish a serial connection to my (Linux Mint) Laptop. That all works with blueman-manager and rfcomm using gui tools manually.

So here comes the twist. Since the bluetooth module draws significant current, I will shut it down when it's not used by simply disconnecting the power to it and the sensors. Then I would like the module to wake up when the power comes on again and send the readings to the PC, automatically.

From what I read a bluetooth module can only initiate a connection in master mode. I have tried setting this with an AT command and that part works, but I don't know how to go about creating the persistent connection to my PC that will connect up again after a power loss so that I can send the next reading.

Another part of this is of course that the Laptop running Linux Mint must be able to create the serial port (or ideally use the same port) when the bluetooth module wants to send data.

I realize this question is a bit broad, but any pointers are welcome and I'm curious first of all if this is the right way of accomplishing this task.

Thank you!


texts: WiFi connections being lost on connection reset

texts:
Look at the trick in the last few lines of this code:

#include <ESP8266WiFi.h>

const char* ssid = "xxxxx";
const char* password = "yyyyyyy";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

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

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

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

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

 int delays = 0;

 // Wait until the client sends some data
 Serial.println("new client");
 while(!client.available()){
    delay(1);
    delays++;  // First line of trick.
    if (delays > 10) {
       return;
    } // Trick ends.
  }
  ...// Handle some events.
}

Code works ok without the trick (only delay(1); inside the loop), but the problem is it gets stucked there, if some responses are asked from browser so that tab is closed in between the requests.

One response is for favicon:

 if (req.indexOf("favicon.ico") != -1) {
    String s = "HTTP/1.1 404 WTF Favicon !!\r\n";
    client.print(s);
    client.flush();
    return;
 }

I had also one similar response starting with 200 OK for certain URLs and then a response of plain json text.

I would like to know why my server gets stucked on this delay(1);? Also, when the trick is needed, what is correct delays value?

Also I did add a client.flush(); after every client.print();. May that affect anything?


texts:
Question: Where do I put code if I want it to execute only once per Arduino startup?

Background: I tend to use my Arduino to perform tasks that should be executed once per power cycle.  (For example, my robot should only drive forward once every time I turn it on--more than that, and it might fall off the table.)

The standard Arduino IDE "template" consists of a loop() and a setup() function.  The setup code is run once per power cycle, and the loop is re-started every time it finishes.

I see two approaches to code "1 time tasks:"

Method 1: "Loop once"

void setup() {
  //do setup stuff
}

void loop() {
  //do task

  while(1) ; //Repeat forever, preventing function from re-starting
}

Method 2: "Setup only"

void setup() {
  //do setup stuff

  //do task
}

void loop() {
  //do nothing
}

More detailed form of question:  Is one of these methods "better" from a hardware/software sense?  (e.g. is there anything "special" about the setup function, like it can only run for so much time?)
And, if they are the same from a hardware/software perspective, is there a "best practice" or standard way of writing code for these situations in the Arduino community?


texts: Thin battery to power arduino micro with nRF8001?

texts:
I'm building a project which needs to fit in a wallet. I have an Arduino Micro hooked up to a nRF8001. I attempted three button cells wired in series, which provided a solid 7.5 volts, but only 20mA.

A 9V battery successfully powers it, but that's too big to fit in a wallet. I was considering using an A27 battery, but even that's thicker than I would like.

Is there any battery I can use that's a reasonable thickness, and won't explode on me? Thanks!...


texts: How to read differential TTL signal from encoder using Arduino?

texts: I am using Arduino UNO/ MEGA to read the incremental encoder pulses (Baumer encoder EIL580). Currently, I am using it in single-ended mode (reading A,B and Z outputs) as I am not sure how to read the differential signal in Arduino (A, Ainv, B, Binv, Z, Zinv) as it would improve the reliability of the data. Is there any addon shield or circuitry to interface this signal with Arduino?


texts: Laser emitter + receiver for Arduino (Arduino to Arduino communication)

texts:
I'm working on a project using 2 Arduinos connected to 2 computers to demo Serial to Serial communication.

We're using Arduino Uno connected to the computer via Serial and software serial for inter-Arduino communication. We used wires to connect software serial RX & TX lines, but we'd like to connect these pins to a laser transmitter and receiver.

We're trying to show wireless communication using an optical medium, which is why we wanted to use a Laser transmitter and receiver.

We're trying something like the setup in this YouTube video $3 laser transmits audio over 100m (Arduino)

Any idea how high a baud rate we will be able to achieve using the transmitter and receiver?

Receiver: Laser Sensor Module non-modulator Tube Laser Receiver

Transmitter: 5V ... Board For Arduino AVR ... KY-008 Laser Transmitter


texts: How to update a variable in an ISR using Timers

texts:
I'm trying to check the frequency of Timer3 using a counter. The value of the counter, declared as volatile, is incremented in the ISR and every second the sum is shown in the main loop and the value reset to zero.

The timer has been set up correctly. (If I choose a 3Hz timer I can see the led blinking)

The problem

The counter isn't incremented. Here is the output:

Setup Completed
tick: 1
tick: 0
tick: 0
tick: 0

CODE

volatile int cont = 0;

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

  pinMode(13, OUTPUT);

  // Initialize Timer
  cli();          // disable global interrupts
  TCCR3A = 0;     // set entire TCCR3A register to 0
  TCCR3B = 0;     // same for TCCR3B

  // set compare match register to desired timer count: 800 Hz
  OCR3B = 20; // 800Hz 5; // 3 Hz
  // turn on CTC mode:
  TCCR3B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR3B |= (1 << CS30) | (1 << CS32);
  // enable timer compare interrupt:
  TIMSK3 |= (1 << OCIE3B);
  // enable global interrupts:
  sei();

  Serial.println("Setup completed");
}

void loop()
{
  if (millis() % 1000 == 0)
  {
    Serial.print(" tick: ");
    Serial.println(cont);
    cont = 0;
  }
}

ISR(TIMER3_COMPB_vect)
{
  //digitalWrite(13, digitalRead(13) ^ 1);
  cont++;
}

EDIT
This timer is used to read an anlog value from an accelerometer and store it in an array of float. But at the moment I'm stuck on this update issue.

SOLUTION 1
Thanks to Gerben

volatile int cont = 0;

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

  // Initialize Timer
  cli();          // disable global interrupts
  TCCR3A = 0;     // set entire TCCR3A register to 0
  TCCR3B = 0;     // same for TCCR3B

  // set compare match register to desired timer count: 800 Hz
  OCR3A = 20; // 20; //800Hz 5; // 3 Hz
  // turn on CTC mode:
  TCCR3B |= (1 << WGM32);
  // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR3B |= (1 << CS30) | (1 << CS32);
  // enable timer compare interrupt:
  TIMSK3 |= (1 << OCIE3B);
  // enable global interrupts:
  sei();
  Serial.println("Setup completed");
}

void loop()
{
  delay(1000);
  Serial.println(cont);
  cont = 0;
}

ISR(TIMER3_COMPB_vect)
{
  cont++;
}

SOLUTION 2
Thanks to BrettM

volatile int cont = 0;

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

  // Initialize Timer
  cli();          // disable global interrupts
  TCCR3A = 0;     // set entire TCCR3A register to 0
  TCCR3B = 0;     // same for TCCR3B

  // set compare match register to desired timer count: 800 Hz
  OCR3B =  20; //800Hz 5; // 3 Hz
  // turn on CTC mode:
  //TCCR3B |= (1 << WGM32);
  // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR3B |= (1 << CS30) | (1 << CS32);
  // enable timer compare interrupt:
  TIMSK3 |= (1 << OCIE3B);
  // enable global interrupts:
  sei();
  Serial.println("Setup completed");
}

void loop()
{
  Serial.println(cont);
  cont = 0;
  delay(1000);

}

ISR(TIMER3_COMPB_vect)
{
  TCNT3 = 0;
  cont++;
}


texts:
When I compile my code, the Arduino IDE returns the binary sketch size in byte.

Is there a good way to find out (approximately) what function or what part of my code takes up how much memory in flash, so that I get a feeling what feature takes most of precious flash memory or where I may be wasting flash and should start optimizing?


texts: Why does the battery eliminator connected to the wall provide a better spin to my dc motors than my battery of the same voltage?

texts: Using a H-bridge, I've connected my DC Motors to an Arduino. When I accept the external power source from a wall, using a 9V battery eliminator, the motors spin well and consistently. However, when I connect it to a 9V battery, the motors spin slower, and the speed deteriorates till the motors stop. This happens in approximately 5 minutes. I checked with multiple 9V batteries of the same type. I have tested the batteries to check if they're dead after the motors stop. They are not, and if I reconnect the motors to them, the same process occurs all over again. I have checked for short circuits, and there are none. Any possible ideas as to why this is happening?


texts: Is it possible to use Adafruit's Circuit Playground Express's 2MB storage in Arduino IDE?

texts: I understand that the extra 2MB of memory is for circuit python.  However, I wouldn't mind having access to 2MB of storage and using the Arduino IDE/low level C to access it.  Is that possible?  If so, how?


texts: Error in sending AT commands in esp8266 connecting to arduino IDE

texts:
I am working on esp8266 with Arduino.

I have connected pins like arduino-esp 3.3-vcc
gnd-gnd 3.3-CH_PD RX-TX TX-RX  and reset to gnd using 3k resistor.

I couldn't send AT commands in serial monitor in Arduino IDE.

Later I connected a capacitor between Vcc and Gnd. Now I could send AT commands and I am getting same commands back. Whatever I entered, I am getting the same back.

I didn't get reply as OK. And I got some random characters too. Can anyone help me with this?


texts:
I want two Arduino cards to communicate with each other using SPI and move the servo motor with potentiometer as a result. I've done the pre-burning led or the led burning led on the SPI, I am waiting for your help. I will give the code below.

MASTER Arduino code

#include <SPI.h>
/* SPI haberleşmesinde Master olarak görev yapan Arduino kodu */
const int pot=A0;   // Servo kontrol potunu bağlayacağımız analog giriş.
int potdurum=0;
int pos = 0;
const int SSpini = 8;
/* Slave görevindeki Arduino'nun seçilmesi için 8 bumaralı pin SS olarak belirlendi */

void setup()
{
  Serial.begin(9600);
  pinMode(SSpini, OUTPUT);
  /* SS pini çıkış olarak ayarlandı */
  digitalWrite(SSpini, HIGH);
  /* Slave olan Arduino başlangıçta haberleşmeye geçmemesi için SS pini HIGH yapıldı */
  SPI.begin();
  /* SPI haberleşmesi başlatıldı */
}

void loop()
{
  potdurum=analogRead(pot);
  pos= map(potdurum,0,1023,0,180);//Pottan okunan değeri  180e oranlıyoruz.
  veriGonder(pos,SSpini);
}

/* SPI üzerinden veri göndermek için yazılmış fonksiyondur */
void veriGonder(int veri, int SSpini)
{
  digitalWrite(SSpini, LOW);
  /* Diğer Arduino'nun veri dinlemeye başlaması için SS hattını LOW düzeyine çekmeliyiz */
  delay(1);
  /* Kısa bir süre bekleyelim */
  Serial.print("Aci Degeri = ");
  Serial.println(veri);
  delay(15);
  SPI.transfer(veri);
  /* veri karakteri diğer Arduino'ya yollandı
  * Fonksiyon diğer arduino'dan gelen veriyi vermektedir
  * Geri gelen veri LEDDurumu değişkeninde tutulmuştur
  * Bu değişken Seri port üzerinden bilgisayardaki Serial monitöre yollanmıştır
  */
  digitalWrite(SSpini, HIGH);
  /* Haberleşmeyi bitirmek için pin LOW konumuna çekilmiştir */
}

SLAVE Arduino code

#include <Servo.h>
int i = 0;
Servo myservomotor;

void setup()
{
  Serial.begin(115200);
  myservomotor.attach(3);
  pinMode(MISO, OUTPUT);
  pinMode(SS , INPUT);
  /* MISO pini OUTPUT, SS pini INPUT olarak ayarlandı */

  SPCR  |= 0b11000000;
  SPSR  |= 0b00000000;
  /* Slave mod ve interrupt için ayarlamalar yapıldı */

  sei();
  /* Interruptlar çalıştırıldı */
}

void loop()
{
}

/* SPI kesmesi olduğunda çalışacak fonksiyon */
ISR(SPI_STC_vect)
{
  cli();
  /* Interruptlar durdurulmuştur */
  while(!digitalRead(SS))
  {
      SPDR = i;
      i ++;
      if ( i > 255)
        i = 0;
      while(!(SPSR & (1 << SPIF)));
      /* SPI hattında veri aktarımı bitene kadar bekle */
      int gelenVeri;
      gelenVeri = SPDR;
      myservomotor.write(gelenVeri);
      Serial.print("Aci Degeri Slave= ");
      Serial.println(gelenVeri);
      delay(15);

//      if(gelenVeri == 'a'){
//        digitalWrite(SERVO,HIGH);
//      }else if(gelenVeri == 'b'){
//        digitalWrite(SERVO,LOW);
//      }
      /* SPI üzerinden gelen verinin değerine göre LED'in konumu değiştirildi */
  }
  sei();
  /* Interruptlar başlatılmıştır */
}


texts:
I recently purchased a Leonardo Eth and a 5v POE module in an attempt to have a POE micro-controller.  I installed the module in the holes closest to the Ethernet jack side of the board, but when I apply power, the green power light turns on every second or so, but never fully turns on.

What am I doing wrong? Did I install the module wrong? Is it the wrong module?


texts:
I have been a bit confused about calculating the input current, so I'd be much obliged if someone could help.

Let's say that we have a potentiometer connected with an analog input as shown below. In a middle position the resistance of the potentiometer is spitted to R1 and R2.

How can I calculate the current in A0?
How much will be the current value if (R1=0, R2=Rmax), (R1=Rmax, R2=0), (R1 and R2 !=0,Rmax)?

 5V --------
           |
           R1
           |
 A0 --------
           |
           R2
           |
          GND


texts: Using Arduino libraries for adding more functionalities to a bootloader

texts:
I have a short question to ask before putting time for research.

I have an Arduino Leonardo with the LUFA mass storage bootloader flashed. Now what I need to do is to add more functionalities to the bootloader. Because in the final product, the Leonardo board will be connected to a fitness machine (permanently connected) and the machine has Windows OS. Then the Leonardo should be able to read an RFID card (I need to add an RFID reader to the board, each user has his own RFID card) and then mount a remote server directory to the local USB Host based on the selected user.

I will have to use a wifi shield too. My question is this: is it theoretically possible to add all these functionalities to the LUFA mass storage bootloader? Because it's not possible to use the Arduino IDE for this purpose, since I'm not uploading any sketch on top of the bootloader, rather than editing the existing mass storage bootloader with the required functionalities and re-flash the chip. Am I correct? (This is what I understood after some research. And I'm a noob :D).

Could you please elaborate what would be the first step for solving this issue?


texts: Cannot connect to database Ethernet Shield

texts:
I am using an LDR sensor to store its readings into the database. My code is as follows:

  #include <SPI.h>
  #include <Ethernet.h>

  const int ledPin = 13;   //the number of the LED pin
  const int ldrPin = A0;  //the number of the LDR pin

  byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

  IPAddress ip(192, 168, 1, 177); // ip of arduino

  char server[] = "192.168.1.105"; // IMPORTANT: If you are using XAMPP you
  will have to find out the IP address of your computer

   // Initialize the Ethernet server library
   EthernetClient client;

   void setup() {

   // Serial.begin starts the serial connection between computer and Arduino
   Serial.begin(9600);
   pinMode(ledPin, OUTPUT);  //initialize the LED pin as an output
   pinMode(ldrPin, INPUT);   //initialize the LDR pin as an input
   // start the Ethernet connection
   Ethernet.begin(mac, ip);

 }

Next, I wrote the setup code:

 void loop() {

  int ldrStatus = analogRead(ldrPin);   //read the status of the LDR value

  //check if the LDR status is <= 300
  //if it is, the LED is HIGH

  if (ldrStatus <=300) {

   digitalWrite(ledPin, HIGH);               //turn LED on

   }
 else {

digitalWrite(ledPin, LOW);          //turn LED off

}

// Connect to the server (your computer or web page)
if (client.connect(server, 80)) {
client.print("GET /info.php?"); // This
client.print("value="); // This
client.print(ldrStatus);
client.println(" HTTP/1.1"); // Part of the GET request
client.println("Host: 192.168.1.105");
client.println("Connection: close"); // Part of the GET request telling the
server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop();    // Closing connection to server

}

else {
// If Arduino can't connect to the server (your computer or web page)
Serial.println("--> connection failed\n");
}

// Give the server some time to recieve the data and store it. I used 10
seconds here. Be advised when delaying. If u use a short delay, the server
might not capture data because of Arduino transmitting new data too soon.
delay(1000);
}

The problem is that when I try connecting to database, it gives a database connection failed. I have crosschecked the ip address of my computer and have even logged into it using xampp to check if it is working.
However, the problem is still persistent.


texts: Several ESP8266 in wifi network should share information

texts: I am currently working on a project for my home where several ESP8266 (each with a relay) control lights. I have developed an android for this where I find the ESP8266s via mdns but the problem is that sometimes one or two won't be found ever (depends on the position where I am trying it). So my idea was to make them talk to each other so everyone knows like an list of ip addresses from the others. This would give me the possibility to find every ESP as soon as i have found one.


texts: How to connect an ESP8266 using an ESP-01 adapter to an Arduino Uno?

texts:
I am pretty new to Arduino programming and wanted to learn how to connect an ESP8266 generic WiFi module to an Arduino Uno using the ESP-01 Adapter shown in the image below.
I tried doing it on my own while connecting the Vcc, GND, Tx and Rx pins of the adapter to the 5V, GND, Tx and Rx of the Arduino Uno respectively but was getting the following error while trying to upload the sketch:

warning espcomm_sync failed
error espcomm_open failed
error espcomm_upload_mem failed

To the best of my knowledge there is no tutorial on the internet that explains about the above mentioned adapter and its interfacing with the wifi module in detail. It would be a great help if someone could please guide me through the process so as to convert my Arduino into a server.


texts: Motor keeps spinning crazily after UNO board reset

texts:
I'm using a NEMA 17 stepper motor with A4988 motor driver and Arduino Uno board. I have used full microstepping (1/16th, so one revolution = 3200 steps).

I'm coming across this strange problem. Whenever I upload any code, for example

void loop()
{  delay(20);
   digitalWrite(stepPin, HIGH);
   delayMicroseconds(100);
   digitalWrite(stepPin, LOW);
   delayMicroseconds(100);
}

the motor spins rapidly for about 1000 steps clockwise (before "avrdude done. Thank you." appears), and then executes the code. When a similar code is placed in void steup() with an empty void loop (), the same thing happens - motor spins rapidly, executes what's written and then stops. The initial rapid spinning is always the same speed and direction, no matter what code is uploaded.

When I upload empty code -

void setup() {}
void loop() {}

the motor continuously spins rapidly with the same speed, same direction. If I add a delay(1000) anywhere in the above program, same thing happens. When I long/short press the reset button on the board, same thing happens. When I upload programs unrelated to the motor, like the example Blink program, same thing happens. Buddy of mine told me to upload the eeprom_clear program from Examples, same thing happened.

I tried uploading this program -

void setup(){
for (int i=0; i<=13; i++)
  {pinMode(i,OUTPUT);
  digitalWrite(i,LOW);

  }

}
void loop(){}

and motor spun like crazy while uploading (same ~1000 steps, clockwise direction) and then stopped. Uploading any program after this has same behaviour. If it an empty/delay only program, motor spins crazily forever. If it is a specific program (example - run for 1000 steps), it spins crazily while uploading, executes the main program, then stops.

As I'm typing this, the motor is spinning like a crazed maniac even though I just uploaded an empty void setup() {} void loop() {} program.

I've tried changing the computer that the Arduino is connected to, I've changed the motor driver and plugged in a brand new one, I've changed the USB cable, I've changed the motor and I've reset all Arduino and breadboard connections. I went to Device Manager > Ports (COM & LPT) > USB-SERIAL CH340(COM5) and updated driver. Current Arduino IDE is Arduino 1.8.10 on Windows 10.

No change in outcome. This problem has been spoiling my sleep for the past few nights as I can't upload anything to the board without the Arduino either spinning crazily endlessly or spinning crazily just while uploading and then behaving properly.

Any solutions? Thanks a lot!

Edit - Added schematic of the electronics connections. Original image from www.lastminuteengineers.com


texts: Optimization Teensy 3.6 Arduino IDE fast I/O Multiplexing Led Matirx

texts:
I'm currently working on a 10x10 LED Matrix which is controlled by 5 Shift registers using multiplexing. I've the problem that the Teensy 3.6 is too fast/slow.

One part of my code is the Shiftout function. If I use normal digitalWrite() its working perfectly fine, but its slow. If I use digitalWirteFast() or something like GPIOA_PSOR = (1 << 12); the matrix starts to display crap.

Teensy 3.6 180MHz

74HC595 shift register

SS8050 BJT's to protect the whole thing

scematic here: circuits.io

void ShiftOut(uint8_t myDataOut) {
// This shifts 8 bits out lngMsLoopstartB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
uint8_t i = 0;
//clear everything out just in case to
//prepare shift register for bit shifting

//digitalWriteFast(dataPin, LOW);//Data aus
GPIOA_PCOR = (1 << 12); // Datapin low

//digitalWriteFast(clockPin, LOW);//Clock aus
GPIOA_PCOR = (1 << 13); // Clockpin low

//for each bit in the uint8_t myDataOut
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i = 0; i <= 7; i++)  {

//digitalWrite(clockPin, LOW);//Clock aus
GPIOA_PCOR = (1 << 13); // Clockpin low

//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1 << i) ) {
  //digitalWriteFast(dataPin, HIGH);//Data an
  GPIOA_PSOR = (1 << 12); // Datapin high

} else {
  digitalWrite(dataPin, LOW);//Data aus
  //GPIOA_PCOR = (1 << 12); // Datapin low
}

//register shifts bits on upstroke of clock pin
digitalWrite(clockPin, HIGH);//Clock an
//GPIOA_PSOR = (1 << 13); // Clockpin high

digitalWrite(clockPin, LOW);//Clock aus
//GPIOA_PCOR = (1 << 13); // Clockpin low

//zero the data pin after shift to prevent bleed through
digitalWrite(dataPin, LOW);//Data aus
//GPIOA_PCOR = (1 << 12); // Datapin low
}
}

if somebody needs the complete code, please let me know!

How it looks like when I use GPIO 2.Picture how it should look like: Imgur

Problem

The thing I want is to make the whole multiplexing faster. Currently 1 Time all 10 rows takes about 480 microseconds. Then add a 4 Bit Bit angle modulation (480*16) its: 7680 microseconds (7.68ms). So if you now divide 1000 by 7.68 = 130,2 Hz refresh rate. Thats ok and Im fine with that.

The main problem is that I want 8 bit. so same thing again 480 * 256 = 112880 (112,88ms). So now divide 1000 by 112,88 = 8,86 Hz refresh rate. That looks really bad. I would like to get about 60-100.

The Problem is not the big LED array or setting each value every frame new. This only takes 80 microseconds.


texts: Powering Arduino Uno from 5V pin, what exactly is the voltage range/tolerance?

texts:
I want to bypass the onboard regulator and use the 5V pin to feed arduino with external, regulated source.

Everybody just keeps saying regulated 5V, but how precise does the regulation need to be exactly? Can you state a voltage range and what makes you think so?

10 ways to destroy arduino, Method #5: Apply >5V to the 5V Connector Pin mentions "applying more than 6V", can anyone elaborate how it can be calculated?

Is there a higher spike that arduino can handle for a short period of time?
My concern is that the current draw from arduino might be under 60mA (right after switching power on and before the program initilizes and starts running), which is the lowest draw at which my source guarantees the 5V regulation --- when unloaded it gives out 6.5V. How could I resolve this better than putting a 60mA dummy load between the regulator and arduino itself?


texts: Good quality sound using a microcontroller

texts:
I am a hobbyist. Doing some experiments with sound quality. I'll pin point my problem and requirements.

Problem statement :I want to play audio files ( recorded in human voice, not music files, just some plain human speech files)
I have tried : a project with an Arduino microcontroller and MicroSD card but audio quality was not at all good from the link below
https://www.instructables.com/id/Audio-Player-Using-Arduino-With-Micro-SD-Card/
https://circuitdigest.com/microcontroller-projects/arduino-audio-music-player
It just used an arduino UNO board, microSD using SPI, a speaker and an LM386 Audio Amplifier.

I read about the details and got to know that I need a DAC for better quality (as PWM cannot serve the purpose), and a speaker also. But there are a number of things available and I dont understand which one to buy and start a project.

Can you share the details of some micro-controller board with a DAC which suffice my purpose, memory to store audio files (or I can use a microSD card device), and a speaker project which I can follow and make one.
I am looking for a board based solution, after getting some results, I can go for separate micro-controller and DAC.

Thanks in advance.


texts: FreeRTOS : Create Tasks but don't start Scheduler

texts:
I'm using FreeRTOs on Arduino for the first time. In my setup(), i would like to create my tasks but i have few more configuration to do after so i would like to create my tasks but don't start the scheduler immediately.
This is my code currently with xTaskCreate and vTaskScheduler, but my code start the task immediately when they are created :

   //Create Tasks
   s1 = xTaskCreate(TaskAcquisition, NULL, configMINIMAL_STACK_SIZE, NULL, 2, &Acquisition);
   s2 = xTaskCreate(TaskStockage,NULL,configMINIMAL_STACK_SIZE + 200, NULL, 1, &Stockage);

.... Some more config

   Serial.println(F("Config finished"));

  //Check errors
  if(fifoData==NULL || fifoSpace == NULL || s1 != pdPASS || s2 != pdPASS){
  Serial.println(F("Creation error"));
  while(1);
  }
  Serial.println(F("Fifo and Tasks created"));

  //starting
  vTaskStartScheduler();

  //if the scheduler start the code don't came here
  Serial.println(F("Ram issue"));
  while(1);

Thanks for your help !


texts:
I have a camera I'm planning on attaching to an arduino uno, that I want to take pictures and extract the average RGB value from each image.
This is the camera I have, but I've now realized that it takes pre-compressed JPEG images, and so I cannot make use of the data it's giving me.

I realize that an arduino is not the optimal tool to use in this case, but I'm curious as to whether there would be any way to decompress the images and convert them to a format I could use. It does not need to be fast, and I do not need to take the pictures quickly. I have experience with programming but have not done many projects with the arduino, so any help or advice is appreciated.


texts: is a 5V cellphone power supply stabilised?

texts:
can I feed my arduino UNO with a 5V cellphone USB power supply ?
Since the arduino board doesn't regulate the 5V from the USB input, is a cellphone power supply sufficiently regulated ?


texts: Is a 9v battery appropriate for a piezo and 1 LED?

texts:
I'm making a basic "door open" detector that, when a door is opened, it turns on an LED and then sounds an alarm via a piezo.

This is controlled via a 5v Adafruit Trinket.

Is a 9v battery the correct thing to power this with, if the goal is to change batteries as infrequently as possible?

Here's the code, incase that's relevant.

#include <elapsedMillis.h>
elapsedMillis timeElapsed;

const int switchPin = 2;
const int ledPin = 1;
const int piezoPin = 0;
const uint32_t openLength = 5 * 1000L; // X seconds
int notes[] = {862,294,730};

void setup() {
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(piezoPin, OUTPUT);
  digitalWrite(switchPin, HIGH);
}

void loop() {
  if(digitalRead(switchPin) == LOW){
    digitalWrite(ledPin, LOW);
    timeElapsed = 0;
  } else {
    digitalWrite(ledPin, HIGH);

    if (timeElapsed > openLength){
      for (int n = 0; n < 200 ; n++){
        beep(notes[random(0,2)]);

        if(digitalRead(switchPin) == LOW){ break; }
      }
    }
  }
}

void beep(int delayAmount)
{
  for (uint16_t t = 0; t < 30*1000/2; t += delayAmount)
  {
    digitalWrite(piezoPin,HIGH);
    delayMicroseconds(delayAmount);
    digitalWrite(piezoPin,LOW);
    delayMicroseconds(delayAmount);
  }
}

UPDATE: I had a 9V plugged in to this for about 3 days before it used all the power in 9V. Is that an issue w/ voltage on the battery (i.e. I should be using AA's instead of a 9V)? Or does that point largely to some other inefficiency w/ the code or hardware?


texts: Arduino Uno outputs 8V when pin is set to HIGH

texts:
I am doing the following in setup:

 pinMode(13,OUTPUT);
 digitalWrite(13, HIGH);

When I check with the multimeter, I get an output voltage of 8V rather than 5V. What may be the problem and how do I troubleshoot it?.


texts:
An ATMEGA328-P chip is used with a toggle switch attached to pin 8 and a momentary switch attached to pin 9. My objective is to send the following information over serial:

The status of pin 8, every second.
Count the number of presses of pin 9, sending the value as the counter increments

I understand that to achieve point 2 I will need to utilise interrupts, but I have become stuck in the way I am trying to use them.

I am familiar with the following code's simple style:

Within the loop...
Poll the status of the input
Send status over serial

Code A:

const int SWITCH_1 = 8;
const int READ_INTERVAL = 1000;

int val_s1 = 0;

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

    pinMode(SWITCH_1, INPUT);
    digitalWrite(S1, HIGH);
}

void loop() {
    val_s1 = digitalRead(SWITCH_1);
    Serial.print("S1:");
    Serial.print(val_s1);
    Serial.print("\n");

    digitalWrite(LED_BUILTIN, HIGH);
    delay(10);
    digitalWrite(LED_BUILTIN, LOW);
    delay(READ_INTERVAL);
}

When introducing the concept of interrupts, I have tried to retain the simplistic style of code A for testing purposes. The next snipped attempts to achieve the following:

Attach an interrupt to pin 9 when the voltage rises
No need for loop function (?)
Within interrupt callback function...
Increment the counter
Send the counter value over serial

Code B:

void c1_rise();

const int COUNTER_1 = 9;
const int READ_INTERVAL = 1000;

volatile int val_c1 = 0;

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

    pinMode(COUNTER_1, INPUT_PULLUP);
    attachInterrupt(COUNTER_1, c1_rise, RISING);
}

void loop() {
}

void c1_rise() {
    val_c1 ++;
    Serial.print("C1:");
    Serial.print(val_c1);
    Serial.print("\n");
}

I've tried to learn where I'm going wrong, but I have become stuck and have decided to ask my questions here.

Observation: I expect to see some data sent over serial when the button is pressed, but actually nothing observable happens.
Problem 1: This might be because the interrupt isn't being attached at all.
Problem 2: This might be because I misunderstand the limitations of interrupt callback functions.

While trying to solve problem 1, Arduino documentation implies that to use the attachInterrupt function, parameter 1 must be an interrupt, from digitalPinToInterrupt, but if I use that function I receive the following error message: error: ‘digitalPinToInterrupt’ was not declared in this scope.

From reading up about how interrupts behave, I found problem 2: it seems that even though I have declared the integer as volatile, using Serial from within a callback function isn't allowed. This is the limit of my knowledge currently, I hope that someone can help me out.


texts: Setting serial number on CH340 USB-Serial device

texts:
Reading http://playground.arduino.cc/Linux/Udev there appears to be a way to write out to a FTDI USB-Serial EEPROM to set a given SerialNumber, allowing you to identify a given nano/other arduino to handle it specifically in UDEV.

I have a nano-style boad with a QinHeng Electronics HL-340 USB-Serial adapter, which clearly isn't an FTDI chip, and the FTDI programmer therefore doesn't work. Does anyone know of an alternative utility/where I can find information to do the same with this chip?

Currently the device identifies itself with:

[ 6850.608080] usb 2-1.2: new full-speed USB device number 7 using ehci-pci
[ 6850.701496] usb 2-1.2: New USB device found, idVendor=1a86, idProduct=7523
[ 6850.701505] usb 2-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 6850.701510] usb 2-1.2: Product: USB2.0-Serial
[ 6850.702201] ch341 2-1.2:1.0: ch341-uart converter detected
[ 6850.704210] usb 2-1.2: ch341-uart converter now attached to ttyUSB0

Which is essentially useless, as I can't identify the given board attached (when I attach two, their details are the same).


texts: Arduino Nano clone doesn't fit into breadboard. How can I work around this?

texts:
I have bought an arduino nano clone (called funduino) and upon trying to place it into my breadboard to work with it I realised that the pins do not line up with the holes on the breadboard so I simply can't use the funduino...

Does anyone have any recommendations on how I can get around this?


texts: How can I rename how my Arduino shows up on the computer?

texts:
I have a clone of a Mega 2560, and the Chinese manufacture apparently had a broken shift key. To my annoyance, whenever I connect it to my computer it reads, arduino compatible mega 2560. With my extreme annoyance with slightly misspelled or incorrectly capitalised English, it has been very distracting to me.

However, the reason that I'm asking this question is for more than how to rename it to be capitalised. Think of how many projects could be simplified by this! Or for many Arduinos, you can label they physically and then rename them Arduino #1, etc. so you can tell which port it is on using device manager. If you designed a product with Arduino, then you can even rename it to your product name.

I would imagine that there would be an easy way to do this by reburning the firmware to the [Insert USB chip model #### here]. I've seen it done for keyboards on the Uno, so I would imagine that you could modify it somehow.


texts: How does an arduino microprocessor compare to some of the older computers in RAM, and computational speed? Like how does it compare to the Intel 400 or the original IBM PC. I'm interested in both the Atmega328 and the 2560. Just how much better/worse is the arduino compared to an old computer?


texts: Help me determine the power consumption/rating of the circuit below?

texts: Please help me determine the circuit's power consumption from the battery and help me outline the steps to calculate?


texts: How to concatenate a part of a string and convert then to a int?

texts:
Lets say I have

String myString="AR0236";

I wish to extract the number 236 and assign it to an int. How can this be done?

P.S: I'me new to programming and I tried searching the forums for similar problems but surprising none of them worked for me!


texts: Select which XBee router will receive data

texts:
I am working on a project which has one Coordinator XBee and 2 Router Xbees.

Now, following a condition which will be defined by code in MATLAB (Yes/NO condition), I want the XBee router 1 to receive a command (YES Condition) and if the condition is reversed (NO Condition), the XBee router 2 will receive a command. Each XBee router is connected to a different motor to perform different functions.

Is this possible?

If yes, I would like any help that can be offered. I am a complete amateur at this stage to Arduino and XBee communication.


texts: Power source for Arduino uno, sparkfun usb shield and adafruit motor shield

texts: I'm having trouble powering my boards altogether. Right now, I'm using 8x AA batteries to power everything. Running my arduino with one shield runs fine, but not with both shields stacked on top of my arduino. I've even tried powering it with an extra 4x AA batteries on my motor shield, but it still won't run. The way it's stacked is; arduino uno board, usb host shield then motor shield.


texts: Using strings inside mBlock extensions code

texts:
The following question is about a 3rd party Arduino programming enviroment mBlock and creating extensions for it. I hope that there are some of you out there, who are fammiliar with it.

I was recently making an extensions for mBlock that can be used to write code for Arduino, when I came over this obstacle. I tried to write a function inside the "work":"" statement.

It looked like this:

"work":"Serial.print("Hello world");"

The extensions could not be imported, due to the quotation marks around the Hello world string. I tried removing the quotation marks, the extension was sucessfully added, but the program did not work, beacause quotation marks are needed inside C++ code to define a string.

Is there a way to add them in the extensions, without screwing up the code?


texts: integration of GSM module and Bluetooth using arduino

texts: Please help me. There is a conflict when I put GSM and Bluetooth module in one MCU. The problem is when I use the GSM, the Bluetooth will not respond and vice-versa.


texts: Unable to load sketch: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x41

texts:
I've stumbled upon what I've later found it's quite common error, but there seems not to be simple troubleshooting way and solution (people often try various things, sometimes they succeed, sometimes not).

I am using DAGU mini driver, I was able to load sketch as described here - chose Arduino NG ATMega8 as board, connect to my PC via USB (with the driver listed on the product page).

Later on I've plugged RedBot wheel encoders sensor and write some simplistic program to check whether it works at all. I've summarized the steps in a github issue, so that it's easy to reference it.

When I tried to upload the sketch I've receiced stk500_initialize(): (a) protocol error, expect=0x14, resp=0x42, stk500_getparm(): (a) protocol error, expect=0x14, resp=0x41. The full log is included in comment on that github issue.

The D13 diode is making series of 3-blink bursts - 8 bursts after start. More diagnostic I did in the github issue as well.

My question (apart from obvious 'how to fix it!?!' ;) ) is whether there is some kind of documentation for this protocol? On the various topics I've found people seem to have somewhat different problems (the numbers and messages were different). I just want to know why the first few messages are exchanged OK (avrdude receives some basic info from the chip), but later ones (namely Send: A [41] . [81]   [20]) are producing protocol errors.


texts: Sketch works on MEGA 2560 timer2, but does not work on timer1

texts:
I set the PWM frequency on MEGA 2560 like this:

  TCCR2A = 0;
  TCCR2B = 0;
  TCNT2  = 0;

  TCCR2A = _BV(COM2A1)
           | _BV(COM2B1)
           | _BV(WGM20);
     TCCR2B = (TCCR2B & 0b11111000) | 0x02;

it works good, now I want to use timer1 on PWM and I changed the code like follow but no work:

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

  TCCR1A = _BV(COM1A1)
           | _BV(COM1B1)
           | _BV(WGM10);

  TCCR1B = (TCCR1B & 0b11111000) | 0x02;

What's wrong with the changes?

I added 'TOP = ICR1', and when I tested, the ICR1's value effected both the PWM's frequency and duty cycle, how to avoid ICR1 effect dutu cycle?


texts: Trouble reading from multiple analog ports

texts:
So I'm trying to read 4 different analog values and store each one to a variable.  I imagine doing this by first initializing the ADC registers and each time it enters the ADC ISR checking which port it read from and saving it to the corresponding variable.  Then setting the ADMUX to the next ADC port and repeating the whole process.  Unfortunately something goes wonky and I just can't figure out what it is.  If I get rid of the switch case and just read from one port it all works fine, but if I put the switch case back in and try to cycle through them it stops working.  Please ignore the rest of code as this is not complete.  I just included everything I could.  Eventually this will take in 4 values.  Then use them for error checking and a PID loop.

Thanks for any help!

/*
 * Throttle_by_Wire.c
 *
 * Basic throttle by wire controller
 * for the 2015 Formula Hybrid car
 *
 *  Created on: Nov 24, 2014
 *  Author: Austin R. Bartz
 *
 *  Pin Connections:
 *      PB2 - Motor Speed (Enable pin) (PWM)
 *      PB4 - Direction control (Counter-Clockwise)
 *      PB5 - Direction control (Clockwise)
 *      PC0 - Throttle Pedal Sensor A (TPA) (Shallower Slope)
 *      PC1 - Throttle Pedal Sensor B (TPB) (Steeper Slope)
 *      PC2 - Throttle Valve Sensor A (TPSA) (Negative Slope)
 *      PC3 - Throttle Valve Sensor B (TPSB) (Positive Slope)
 */

#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdlib.h>

uint16_t TPA = 0;
uint16_t TPB = 0;
uint16_t TPSA = 0;
uint16_t TPSB = 0;
uint16_t analogpin = 0;

long map(long x, long in_min, long in_max, long out_min, long out_max);

int main(void)
{
    //Configure ADC for single shot conversion
    ADMUX |= (1<<REFS0);
    ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADIE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
    DIDR0 = (1<<ADC4D)|(1<<ADC3D)|(1<<ADC2D)|(1<<ADC1D)|(1<<ADC0D);
    //Configure timer/counter1 for FastPWM
    TCCR1A = (1<<COM1B1)|(1<<WGM11)|(1<<WGM10);
    TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS10);
    OCR1A = 800;    //20kHz
    //Set motor control pins as outputs
    DDRB = (1<<PB2)|(1<<PB4)|(1<<PB5);
    PORTB |= (1<<PB5);
    //Enable global variables and interrupts
    sei();

    while(1)
    {
        //Control PWM % to motor
        OCR1B = map(TPA, 0, 1023, 0, OCR1A);
    }
}

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

ISR(ADC_vect)
{
    //Save current conversion's ADC value
    analogpin = ADMUX & 0b00001111;
    switch (analogpin)
    {
    case 0:
        TPA = ADCW;
        //Increment ADC port to ADC1
        ADMUX |= (1<<MUX0);
        break;
    case 1:
        TPB = ADCW;
        //Increment ADC port ADC2
        ADMUX &= ~0b00001111;
        ADMUX |= (1<<MUX1);
        break;
    case 2:
        TPSA = ADCW;
        //Increment ADC port to ADC3
        ADMUX &= 0b00001111;
        ADMUX = (1<<MUX0)|(1<<MUX1);
        break;
    case 3:
        TPSB = ADCW;
        //Reset ADC Port to ADC0
        ADMUX &= ~0b00001111;
        break;
    }
    //Start next conversion
    ADCSRA |= (1<<ADSC);
}


texts:
I have an ESP32 cam, and I attached an i2c light sensor to it. I need to read the light level at startup, then I don't need the i2c connection again.
The problem is, the board uses 2 i2c connections I think (for the camera and such). So I use my custom pins for the sensor (15 and 16). It works well, I can read the light just fine, but then the camera fails because (I believe) the Wire.begin(15,16) changes the default pins and the camera gets confused.
So I would like to do something like Wire.end() to forget that I started the Wire.begin(). Any idea on how I can do that?
Here is the relevant code:
#define I2C_SDA 16
#define I2C_SCL 15
BH1750 lightMeter (0x23);
TwoWire I2Clightmeter= TwoWire(1);

void setup()
{
  I2Clightmeter.begin(I2C_SDA, I2C_SCL);
  lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE,0x23,&I2Clightmeter);

  delay(1000);
  uint16_t lux = lightMeter.readLightLevel();

//rest of the code


texts:
I dont know if that is the right place to put my question or no.
So my question is how to write a 250s delay using assembly for my pic16f84a


texts: ARDUINO Circuit simulation with PV panel

texts:
I need to create a circuit with the Arduino Uno board like you do in Tinkercad where I show how I connected each pin of the board. The problem is that in Tinkercad I do not have a module for a PV panel. I tried to search other simulators but none seems to have a PV module.
Is there any way I can create this circuit where I connect the Arduino board with the PV panel?


texts: Using 3.3V XBee with Arduino Pro Mini 5V Version

texts:
The Xbee requires a 3.3V power input and the Arduino Pro Mini (5V version) only provides a regulated 5V.

Question: What will be the simplest way to provide a 3.3V rail to the XBee from the Arduino Pro Mini?

If we use a voltage divider consisting of 2 resistors, the ratio should be 66/100, but how do we choose the resistor values?

If we choose a 3.3V voltage regulator, will the STMicroelectronics L78L33ACZ be suitable?

Between the voltage divider and voltage regulator, which is the preferred method? Is there a better alternative?


texts: Can I connect a servo directly to arduino uno without a transistor?

texts: I am going to mount an ultrasonic sensor on the servo.


texts: Could someone explain this weird looking code, used to setup timers?

texts:
While looking at sketches other people have written, I occasionally come across code that looks somewhat like this:

TCCR1A = 0;
TCCR1B = 0;

TCNT1 = 34286;
TCCR1B |= (1 << CS12);
TIMSK1 |= (1 << TOIE1);

All I know is that is has something to with timing/timers (I think). How can I decipher—and create—code like this? What are TCCR1A, TCCR1B, TCNT1, CS12, TIMSK1, and TOIE1?


texts: How can I reduce current drawn by micro SD card module?

texts: I am using a servo along with a sensor and micro SD card module and speaker in arduino uno in order to play a wav file at certain conditions . But when i run the whole system the sd card module is consuming high current and the servo stops working as the current in that is in order of some micro amps. So please help me to solve the problem.


texts: Can 2 H-Brides be controlled by one Arduino?

texts:
The three motors are from windshield wipers, with one of the brushes disconnected in each. The controllers are BTS7960 43A modules

One Bridge for two drive motors (speed and direction), and the second Bridge for a third [modified servo-like] motor (for Ackerman steering).

Is this possible/recommended?


texts: How to get a list of IPs in a LAN using NodeMcu?

texts: I'm going to create an IoT system. I use a Raspberry Pi as a MQTT broker and as a webserver. Every day, the Pi gets a new IP address, so I need to find its new IP address via ESP8266 to use this information in my code. I know that I can use a fixed IP, but I don't want to, so it is better if I can find a solution.


texts: Is there any way to flash sketches using custom firmware?

texts:
I am using HIDUINO as my firmware (flashing via dfu-programmer), and to upload sketch I need to re-flash original firmware, upload sketch and then flash HIDUINO again.

Is there a way to flash sketches without reflashing original firmware?


texts: Is it possible to use the DASH7 protocol in an arduino?

texts: I've been reading about the protocol DASH7 but can't find much documentation about it. There seems to be a protocol stack called OpenTag writen in C and I want to know if there is something familiar written in arduino code and why can't I find a lot about this tecnology.


texts:
I'm trying to communicate between Arduino Nano and Arduino Uno using nRF24L01+.

I tried using RF24 by ManiacBug and TMRH20, but when I open the serial monitor after uploading the Example Programs Getting Started from ManiacBug and pingpair Program from TMRH20, it does not change its address.

The addresses for reading and writing I'm using are 0xF0F0F0F0E1LL and 0xF0F0F0F0D2LL, but the response I'm receiving is as follows:

I check all the connection and tried different examples available on the internet, but nothing worked at all.


texts: Weird behaviour of rotary encoder values

texts:
The plan is to control a NEMA 17 stepper motor with an endless rotary encoder.

First, I found a code to read the rotary encoders data on www.HowToMechatronics.com by Dejan Nedelkovski. It basically manipulates an integer and outputs it on the Serial Monitor.

Works almost perfectly except that it actually doubles the count of steps the rotary encoder does.
So a clockwise turn subtracts 1, outputs it in the SM, subtracts 1 and outputs it in the SM again. Same in the other direction with adding 1. Although being not a big deal for intended use of the rotary encoder data, I think this has something to do with the problem.

In the code down below you will find a modified version of the code from Mr. Nedelkovski. I added a few lines to move the motor a few steps in each direction.

Clockwise rotation works as I expected.
One step on the rotary equals subtract, output, movement, subtract, output, movement.

But counterclockwise rotation now adds 1 to the rotary position and subtracts it immediately, leaving the motor in moving back and forward.
But if I move the rotary very very slowly it will work.

Why are the rotary values jumping around once I added the lines?
Is there a way to solve this?

The code:

/*     Arduino Rotary Encoder Tutorial
 *
 *  by Dejan Nedelkovski, www.HowToMechatronics.com
 *
 *  to make it work with a stepper
 *  modified by me
 *
 */

#include <Stepper.h>

#define outputA 52
#define outputB 50

int counter = 0;
int dir = 0;
int aState;
int aLastState;

Stepper myStepper(200, 47, 49, 51, 53);

void setup() {

  pinMode (outputA,INPUT);
  pinMode (outputB,INPUT);

  Serial.begin (9600);
  // Reads the initial state of the outputA
  aLastState = digitalRead(outputA);

  // set the speed at 60 rpm:
  myStepper.setSpeed(60);

}

void loop() {

  aState = digitalRead(outputA); // Reads the "current" state of the outputA
  // If the previous and the current state of the outputA are different, that means a Pulse has occured

  if (aState != aLastState){
    // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise

    if (digitalRead(outputB) != aState) {

      counter ++;
      myStepper.step(50);

    } else {

      counter --;
      myStepper.step(-50);

    }

    Serial.print("Position: ");
    Serial.println(counter);
  }

  aLastState = aState; // Updates the previous state of the outputA with the current state
}

Thanks for taking your time to read this and help me. I hope that a detailed explanation will help solving the problem.


texts: how do i know what battery(how much ampere and voltage) my circuit needs to work perfectly?

texts:
i really love to make a lot of things  but i always have this problem that i don't know how can i determine what battery(with how much voltage and amp)my circuit must have to work perfectly! please help me:( for example i have two circuits.circuit 1  includes:arduino uno ,2 servo motors and a DFplayer module and an led but i don't know is a 7.4 voltage Lipo battery with 1500mAh suitable for it or not???
and circuit 2 includes:arduino uno,L298 driver & 2 dc motors & 2 ultrasonics sensor but i don't know what battery does it need?
i really love to learn it (determine the battery  my self)


texts: How to count the number of button presses then play a sequence?

texts:
When I press the button once, sequence s1() plays.
When I press the button twice, sequence s2() plays.
When I press the button thrice, sequence s3() plays.
When I press the button 4 times, sequence s4() plays.

const int buttonPin = 10;
int buttonState = 0;

void setup(){
  Serial.begin(9600);
  //initialize pin 2 - 9 as output
  for(int i=2;i<=9;i++){
    pinMode(i,OUTPUT);
  }
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    s1();
    s2();
    s3();
    s4();
  }
}

void s1() {
  int i = 2 ;
  for(int z=0;z<=1;z++) {
    for(int x=i;x<=9;x++) {
      digitalWrite(i,HIGH);
      digitalWrite(x-1,LOW);
      delay(500);
      i = i + 1;
    }
    i = 2;
    if(i = 2) {
      digitalWrite(9,LOW);
    }
  }
}

void s2(){
  int y = 9;
  for(int i=0;i<=1;i++) {
    for(int x=2;x<=5;x++) {
      if(y>=1) {
        digitalWrite(x,HIGH);
        digitalWrite(y,HIGH);
        delay(500);
        y = y - 1;
      }
    }
    off();
    y = 9;
    delay(500);
  }
}

void s3() {
  for(int i=0;i<=2;i++) {
    for(int z=2; z<=9;z++) {
      if(z % 2 == 0) {
        digitalWrite(z,HIGH);
      }
    }
    delay(500);
    for(int z=2; z<=9;z++) {
      if(z % 2 == 0) {
        digitalWrite(z,LOW);
      }
    }
    delay(500);
    for(int z=2; z<=9;z++) {
      if(z % 2 != 0) {
        digitalWrite(z,HIGH);
      }
    }
    delay(500);
    for(int z=2; z<=9;z++) {
      if(z % 2 != 0) {
        digitalWrite(z,LOW);
      }
    }
    delay(500);
  }
}

void s4() {
  for(int i=0;i<=2;i++) {
    for(int x=2;x<=9;x++) {
      digitalWrite(x,HIGH);
      delay(500);
    }
    off();
    delay(500);
  }
}

void off() {
  for(int i=2;i<=9;i++) {
    digitalWrite(i,LOW);
  }
}


texts: Arduino interrupt sleep mode/reset problem

texts:
I want to write a simple program that waits for an X amount of time (hours) then activates my components (LED and release mechanism) when time has elapsed. I have it so that once I press a button interrupt (pin2) it will put the Arduino in power-down sleep mode when I am not using the device.

What I want it to do next is when another button interrupt (pin3) is pushed, it will wake it up but instead of resuming where it left off in the loop, I want it to reset the program to the start of the loop. I am having trouble getting it to reset after it has woken. Is the code actually putting the Arduino in sleep mode? I'm not sure because after the if statement I make the variable false.

Here is my simple code so far:

#include <avr/interrupt.h>
#include <avr/sleep.h>
//Pin set up
int ledPin =12;
int wakePin = 3;
int sleepPin =2;
volatile boolean flag;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(sleepPin, INPUT_PULLUP);
  pinMode(wakePin, INPUT_PULLUP );
  attachInterrupt(0, sleepy, LOW);
  attachInterrupt(1,EMPTY,LOW);
}

void EMPTY(){
  detachInterrupt(1);
}

void sleepy(){
  flag = true;
}

void sleepNow() {
  digitalWrite(ledPin, LOW);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  attachInterrupt(1,EMPTY,LOW);
  sleep_mode();
}

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite (ledPin, LOW);
  delay(1000);
  digitalWrite(ledPin, HIGH);
  delay(1000);
  if (flag) {
    sleepNow();
  }
  flag = false;
}


texts:
I have some C++ code, but I cant convert it to Arduino language.
I just want to ask, what is the same as getline() (C++ code) function in Arduino?

I just wanted to get the first line in my SD card...
I can only display all text inside my SD card...

Example:

line1   <-   only this line should display(and this line will delete in text
             file... but that is another issue... i will just focus to get the
             line1 and get the value)

line2

line3

line4

line5

This code displays all lines

    #include <SPI.h>
    #include <SD.h>

    File myFile;

    void setup() {
      // Open serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port                          only
       }

       Serial.print("Initializing SD card...");

       if (!SD.begin(4)) {
         Serial.println("initialization failed!");
         while (1);
       }
       Serial.println("initialization done.");

       // open the file. note that only one file can be open at a time,
       // so you have to close this one before opening another.
       myFile = SD.open("test.txt", FILE_WRITE);

       // re-open the file for reading:
       myFile = SD.open("test.txt");
       if (myFile) {
         Serial.println("test.txt:");

         // read from the file until there's nothing else in it:
         while (myFile.available()) {
           Serial.write(myFile.read());
         }
         // close the file:
         myFile.close();
       } else {
         // if the file didn't open, print an error:
         Serial.println("error opening test.txt");
       }
     }

     void loop() {
       // nothing happens after setup
     }