texts: Two Leonardos on one USB hub - not working properly

texts:
I have two Arduino Leonardos here. They do different things, but basically they both emulate a keyboard. Here is an example:

const byte SWITCH = 12;

void setup ()
  {
  Keyboard.begin();
  pinMode (SWITCH, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  if (digitalRead (SWITCH) == LOW)
    {
    Keyboard.println ("foo");
    delay (2000);
    }
  }

Now I program a second Leonardo with the same code but send "bar" rather than "foo".

Now if I plug these into my PC (running Ubuntu 14.04) using different USB ports, everything works. When the switch is closed I see "foo" and "bar" being typed into whatever application is open.

However ...

If I plug them both into a D-Link 4-port USB hub (model DUB-1340) only the first one works. The other is ignored.

Doing lsusb shows this (along with other irrelevant devices):

$ lsusb
Bus 003 Device 040: ID 2341:8036 Arduino SA Leonardo (CDC ACM, HID)
Bus 003 Device 039: ID 2341:8036 Arduino SA Leonardo (CDC ACM, HID)

This happens in both cases (if they are both in the USB hub or not).

My question

Is this proper behaviour that two Leonardos on a USB hub fail to both work? (Perhaps you aren't supposed to plug two identical USB devices in at once).

Or, is this a bug in either:

The Leonardo USB interface?
My USB hub?

Update

Further testing revealed that the setup worked OK when plugged into my Mac running OS/X.

Then I went back to Ubuntu and it worked as well! However a mouse that I had plugged into the USB hub now stopped working!

Further investigation reveals that the fourth port on my USB hub is faulty in some way. If I swap the mouse and the Leonardo the Leonardo works but not the mouse.

Following Majenko's suggestion:

  You can try running usb-devices from the usbutils package (should be already installed since lsusb is in the same package) and look for the two Leonardo blocks.

First one:

T:  Bus=03 Lev=02 Prnt=50 Port=00 Cnt=01 Dev#= 66 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=02(commc) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=2341 ProdID=8036 Rev=01.00
S:  Manufacturer=Arduino LLC
S:  Product=Arduino Leonardo
C:  #Ifs= 3 Cfg#= 1 Atr=80 MxPwr=500mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm
I:  If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm
I:  If#= 2 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid

Second one:

T:  Bus=03 Lev=02 Prnt=50 Port=03 Cnt=04 Dev#= 72 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=02(commc) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=2341 ProdID=8036 Rev=01.00
S:  Manufacturer=Arduino LLC
S:  Product=Arduino Leonardo
C:  #Ifs= 0 Cfg#= 0 Atr= MxPwr=
cat: /sys/bus/usb/devices/usb3/3-3/3-3.4/3-*:?.*/bInterfaceNumber: No such file or directory
cat: /sys/bus/usb/devices/usb3/3-3/3-3.4/3-*:?.*/bAlternateSetting: No such file or directory
cat: /sys/bus/usb/devices/usb3/3-3/3-3.4/3-*:?.*/bNumEndpoints: No such file or directory
cat: /sys/bus/usb/devices/usb3/3-3/3-3.4/3-*:?.*/bInterfaceClass: No such file or directory
cat: /sys/bus/usb/devices/usb3/3-3/3-3.4/3-*:?.*/bInterfaceSubClass: No such file or directory
cat: /sys/bus/usb/devices/usb3/3-3/3-3.4/3-*:?.*/bInterfaceProtocol: No such file or directory
/usr/bin/usb-devices: line 79: printf: (none): invalid number
I:  If#= 0 Alt= 0 #EPs= 0 Cls=() Sub= Prot= Driver=

Tentative conclusion

Perhaps I somehow damaged that USB port by drawing too much current during testing at some earlier point.

Although ... now the mouse is working in the port where it was not working before, and the Leonardo has stopped working in the 3rd port, when it was previously not working in the 4th port.

Those error messages above must be relevant, but I don't know enough about it to say in what way.


texts: Stepper motor is not working according to code

texts:
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 480  //2048
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
int Steps2Take;
int dirpin=8;
int steppin=9;
int buttonApin=2;
int buttonBpin=3;

void setup() {
  pinMode(dirpin,OUTPUT);
  pinMode(steppin,OUTPUT);
  pinMode(buttonApin,INPUT);
  pinMode(buttonBpin,INPUT);
}

void loop() {
  int valA=digitalRead(buttonApin);
  int valB=digitalRead(buttonBpin);
  if(valA==HIGH) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(40000);
    delay(1000);
  }
  if(valB==HIGH) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(-40000);
    delay(1000);
  }
  if((valA==LOW)&&(valB==LOW)) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(0);
  }
}

Here I have written this code to rotate stepper motor. When the input on digital pin 2 becomes high, then the motor should rotate clockwise. When the digital pin 3 becomes high, it should rotate in a different direction. When the input on both pins is low, the motor should not move.

But with this code the motor is moving continuously even if you apply high input to digital pins.

Please suggest how to fix this problem. For input signal I am taking signal from relays: if relay is in on condition, it should give a high signal and vice versa.


texts:
I am trying to build a mobile application which will be capable of firing different channels via Bluetooth HC-05 and Arduino UNO. We are getting IR codes from Android to Arduino through Bluetooth and firing via IR transmitter. It is working perfectly for all the channels, but when '0' is there in between a channel number, the digit followed by zero is not being detected by the set-top box.

I am sharing the Arduino program & the IR codes that are fired from Android app:

Program

#include <IRremote.h>

IRsend irsend;

void setup()
{
   // put your setup code here, to run once:
   Serial.begin(9600);
}

void loop() {

   int khz = 0;
   char input = 0;
   int data[55];
   int count=0;
   String temp;
   String numberSequence;
   int i;
   if (Serial.available()>0)
   {
       numberSequence=Serial.readStringUntil('|');
       Serial.println(numberSequence);
       temp.concat(numberSequence[0]);
       temp.concat(numberSequence[1]);

       khz=temp.toInt();
       temp="";
       Serial.print("Frequency in Khz:");
       Serial.println(khz);
       for(i=3;i<numberSequence.length();i++) {
          if( numberSequence.charAt(i) == ',' ){
             data[count]=temp.toInt();
             Serial.println(data[count]);
             temp="";
             count++;
          }
          else
          {
             temp.concat(numberSequence[i]);
          }
       }
       Serial.println("Calling changeChannel");
       irsend.sendRaw(data, sizeof(data) / sizeof(data[0]), khz);
       Serial.println("IR Transmitted");
   }
}

IR Codes:

Digit 1:
{37,2800,764,596,292,596,292,596,736,592,744,1040,292,592,296,596,296,596,292,592,296,596,292,596,292,596,292,596,296,592,292,596,296,592,296,592,296,596,292,600,292,592,292,596,296,596,292,596,292,1040,|}

Digit 2:
{37,2796,768,596,292,596,292,596,736,596,740,1040,292,592,300,592,296,592,296,592,296,596,292,596,292,596,296,592,296,592,296,592,296,592,296,592,296,592,300,592,296,592,296,592,296,596,296,1040,732,596,|}

Digit 3:
{37,2792,772,588,296,592,296,592,740,592,744,1040,296,592,296,592,296,592,296,592,296,592,300,592,296,592,296,592,296,596,292,596,292,596,296,592,296,592,296,592,296,596,292,592,300,588,300,1036,296,592,|}

Digit 4:
{37,2792,768,592,296,592,296,592,744,584,752,1032,300,588,300,592,296,592,296,592,300,588,300,588,300,588,300,588,300,592,296,588,304,588,300,588,300,592,296,592,300,588,300,588,300,1036,740,588,300,588,|}

Digit 5:
{37,2796,768,588,296,596,296,592,740,592,744,1040,292,596,292,596,292,596,292,592,300,592,296,592,296,592,296,592,296,596,292,596,296,592,296,592,296,592,296,592,296,596,292,592,300,1036,736,1040,|}

Digit 6:
{37,2800,764,592,292,596,296,592,740,592,744,1040,292,596,292,596,296,596,292,596,292,596,292,596,292,596,296,592,296,596,292,592,296,596,296,592,296,596,292,596,292,596,292,596,292,1044,288,596,736,592,|}

Digit 7:
{37,2792,768,592,296,592,296,592,740,596,740,1040,296,592,296,592,296,592,296,592,300,588,300,592,296,592,296,592,296,596,292,596,296,592,296,592,296,592,296,592,300,592,296,588,300,1040,292,592,296,592,|}

Digit 8:
{37,2800,764,596,292,592,296,592,740,592,744,1040,296,592,296,596,292,596,292,596,292,596,296,592,296,592,296,592,300,588,296,596,296,592,296,596,292,596,296,592,296,596,292,1040,736,592,296,592,296,592,|}

Digit 9:
{37,2796,768,592,292,596,292,592,740,592,744,1040,292,592,296,596,296,592,292,596,296,592,296,596,292,592,296,592,296,592,296,592,296,596,292,596,292,596,296,596,292,596,292,1040,732,596,292,1036,|}

Digit 0:
{37,2800,764,596,292,596,292,596,736,596,740,1040,292,600,292,592,296,596,292,596,292,596,292,600,288,600,292,596,292,596,292,596,292,596,296,592,296,592,296,596,292,600,288,596,296,596,292,596,292,596,292,596,|}

Any clues on why this is happening? Thanks.


texts:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
c:\program files (x86)\arduino\hardware\tools\avr\bin../lib/gcc/avr/7.3.0/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; reason: Permission denied
exit status 1
Error compiling for board Arduino Uno.
continue error is coming having downloading over more than 15 times. How can i overcome this problem


texts:
I'm using ws2812b 2x2 LEDs and have it switching between green and red, but only one of my LEDs on my 2x2 is lighting up.
I'm using the "blink" FastLED sketch with Data pin 3 on my Arduino Uno, define led 4.
void loop() {
 // Turn the LED on, then pause
 leds[0] = CRGB::Red;
 FastLED.show();
 delay(5000);
 // Now turn the LED off, then pause
 leds[0] = CRGB::Green;
 FastLED.show();
 delay(5000);
}


texts: unexpected behaviour of encoder with increasing rpm

texts:
I am using a DC motor with encoder, and I am trying to calculate how many pulses are  recorded in every one second interval. (note that the power source is of 12V for the motor)
Circuit and code:

int encpin=3;
volatile long npc=0; //new pulse count
volatile long opc=0;  //original pulse count
volatile long pulsecount;
unsigned long int newtime;
unsigned long int prevtime=0;
unsigned long int time;
void setup()
{
  pinMode(encpin, INPUT_PULLUP);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(encpin),function,RISING);
}
void function(){
  npc++;
}
void loop()
{
 newtime=millis();
 time=newtime-prevtime;
 pulsecount=npc-opc;
  if(time==1000){
    Serial.println(pulsecount);
    prevtime+=1000;
    opc=npc;
  }
}

It seems to be rather intuitive that increasing the rpm should increase the number of pulses recorded in one second. However, the results are rather erratic:
 RPM  PULSECOUNT
  26    2365
  32    2367
  38    2400
  44    2375
  52    2400
 116    2412
 142    2384
 195    2416
 280    2406
 350    3008
 416    1580
 520    1975
 624    2370
 730    2334
2737    2188

Increasing RPM sometimes increases the pulsecount, but sometimes decreases it....what could be the reason for this behaviour?


texts: Arduino Uno (master) and ATTiny85 (slave) I2C connection not working

texts:
I am trying to send and receive data using I2C between an Arduino Uno and an ATTiny85. The Arduino Uno is using the Wire library. The ATTiny85 is using the TinyWire library and is programmed (and powered) using the Sparkfun Tiny AVR Programmer.

I am not receiving any data.

Arduino Uno I2C master code

#include <Wire.h>

#define SLAVE_ADDR 0x50

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

void loop()
{
  Wire.requestFrom(SLAVE_ADDR, 1);

  while(Wire.available())
  {
    byte byteReceived = Wire.read();
    Serial.println(byteReceived, DEC);
  }
}

ATTiny85 I2C slave code

#include "TinyWireS.h"

#define SLAVE_ADDR 0x50

void setup()
{
  TinyWireS.begin(SLAVE_ADDR);
  TinyWireS.onRequest(requestEvent);
}

void loop()
{
}

void requestEvent()
{
  byte byteToSend = 23;
  TinyWireS.send(byteToSend);
}


texts: Send an multidimensional array of values from one arduino to another through serial port

texts:
I have connected two arduinos using pins: RX and TX and managed to send a string as an array of values:

//sender

char mystr[6] = "hello";

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

void loop() {
  Serial.write(mystr);
  delay(1000);
}

And receive it:

//receiver

char mystr[6];

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

void loop() {
  Serial.readBytes(mystr,5);

  if(mystr[0] == 'h' && mystr[1] == 'e' && mystr[2] == 'l'){

    for(int i = 0;i < sizeof(mystr);i++){

      Serial.print(mystr[i]);

      if(i == sizeof(mystr) - 1){
        Serial.print("\r\n");
      }
    }
  }
  delay(1000);
}

That worked fine! But I need to send and receive something like this:

int a[3][4] = {
   {0, 1, 2, 3} ,
   {4, 5, 6, 7} ,
   {8, 9, 10, 11}
};

How can I do that?


texts: Trying to make a heart rate analyser with Arduino that will calculate the BPM of a person

texts:
I am trying to make a heart rate analyzer device using an Arduino board that will calculate the BPM of a person by using raw sensor signals greater or equal to the threshold value to calculate pulses/heartbeat in 10 seconds and then multiply the number of pulses by 6.

The circuit is fairly simple: it has a led that is going to flash on the finger of the person. In-front of the finger there is going to be a photoresistor that is going to read changing values of light falling on it. The values will be varying because of the blood flowing through the finger. When there is going to be a  pulse/heart-beat the amount of light falling on the photoresistor will increase, hence the reading of the photoresistor will also increase.

If the raw values read by the sensor are equal to or greater than the threshold value the code will increment the number of pulses by 1. To calculate the heartbeat rate we will have to count the number of pulses/heart-beats for 10 seconds and then multiply the count by 6.

In short the code that I will use will convert raw analog sensor data into BPM (Beats Per Minute) so that a user can get a standard measurement of his pulse rate.

I took the code that I am going to use from a website. Here is a link to page so that you can also have a look at the code.

I had some problem in the code and was wondering if anyone could help me with it. The full code is given below:

int sensorValue = 0;
int sensorValue = 0;
// variable to store the value coming from the sensor
int count=0;
unsigned long time1=0; // store the initial time
unsigned long time2; // store the current time

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  if(count==0) {
    time1=millis();
  }
  time2=millis();
  sensorValue = analogRead(sensorPin);
  if(sensorValue>156) {
    increment();
  }
  if(time2>=time1+10000) {
    counter();
  }
}

void increment() {
  count++;
  while(sensorValue>156) {
    Serial.print("Sensor value is greater than .75V\n");
  }
}

void counter() {
  count=count*6;
  Serial.print("Heartbeat rate is ");
  Serial.print(count);
  Serial.print(" per min\n");
  time1=0;
  time2=0;
  count=0;
}

Part of the code I'm not able to understand. This is located at the very top of void loop():

[note: i pretty much understand how increment and counter functions work but i am not able to understand how the program is able to take input for 10 seconds.basically how the counter function runs for 10 seconds]

 if(count==0) {
    time1=millis();
  }
  time2=millis();
  sensorValue = analogRead(sensorPin);
  if(sensorValue>156) {
    increment();
  }
  if(time2>=time1+10000) {
    counter();

Although I know that this part of the code that I am not able to understand counts the pulses for 10 seconds by taking raw sensor values and checking if these values are above or equal to the threshold value, I am not able to understand how it is working.

I would be highly obliged if anyone could help me with this problem of mine.


texts: ATmega328P - Problem using timer 2 for tone generation

texts:
I'm simply trying to use timer 2 for tone generation and what I get is a very faint and strange tone (almost like its modulated somehow as there is a "pulsing" to it). Here's my simple code:

#include <Arduino.h>

#define SPEAKER_PORT PORTC
#define SPEAKER_BIT 2

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

  TCCR2A = _BV(WGM21);  // CTC mode
  TCCR2B = _BV(CS20);   // clk/1

  OCR2A = 200;  // 8-bit timer, so keep less than 256
  bitSet(TIMSK2, OCIE2A);  // enable OCR2A interrupt
}

void loop()
{
  // NOP
}

ISR(TIMER2_COMPA_vect)
{
  SPEAKER_PORT ^= _BV(SPEAKER_BIT);
}

Any obvious mistakes? Thanks for your help!


texts:
I want to collect GPS data with a cellular-enabled micro-controller to help me find my drone if it gets lost. My drone has GPS, so I tried to connect to it. Many GPS break-out boards have the following connections:

GND
5V/3.3V
TX
RX

Some of the time there are more, but these seem to be the essential ones. But, I'm studying a GPS module that uses only 3 wires. Take a look:

The red and black ones are power and ground. Must the remaining wire be TX?

I've been trying every way I can think of to tap into this GPS on my quad. I spliced into the 3 wires, but I only connected ground and what I suspect to be TX to my micro.

Also, at this point, I'm just curious.

I've studied the GPS a bit more and I can now see it has a compass and some other motion device. So it's not just a GPS board.
It also had it's own micro controller managing all of these devices.  I think the serial data on the wires I've tapped has been reformatted for the flight controller. It's gibberish in the arduino app.

At this point I'm ready give up and just put a second GPS on the thing!
But before I give up I wanted to ask if there are any other methods I can try to listen to the GPS.

Thanks!


texts: How can I make my Arduino Uno press Space on my laptop keyboard?

texts:
So I wanna build something which, when it receives a remote signal, presses the spacebar on my laptop keyboard. I tried using the Keyboard.press() but it is available only for Leonardo. Is there any way I can use it in my Uno, without having to mess with the firmware?
If not, what else can I use to accomplish my goal?


texts: Arduino Starter Kit - firmly wiring longer parts

texts:
I am getting started with project 01 on the Arduino starter kit. I'm facing an issue when wiring parts with long ends e.g. led & resistor. To make the simple circuit with led, resistor & switch work, I have to hold down the resistor & led, and then press the button. The parts don't connect well to the wires underneath the breadboard.

I want ask if someone could suggest how to better deal with such parts. On searching, I found people cut their parts short, but are there other approaches ?
Thanks.


texts:
I have this TFT:

Now, the problem is, I will not use this as a shield (i.e. I will not just put it on top of an Arduino Uno). I will use it with an ESP8266 (NodeMCU). I want to know how to wire them up together. There is this website (and a few more that say the same way). But the problem is I cannot find SDI/MOSI or SDD/MISO on the TFT above.


texts: Compiling error:passing as 'this' argument

texts:
I am trying to make a small keyboard class to handle two buttons(in the future >2)  that are connected to my arduino UNO. The buttons being pressed are detected using interrupts. Here is the code:

Timer

class Timer{
  private:
    uint32_t start_time;
  public:
    Timer(){
      start_time=millis();
    }
    void mark(){
      start_time=millis();
    }
    uint32_t lapsed(){
      return millis()-start_time;
    }
};

Keyboard

class KeyboardBtn{
  private:
    const static byte clicksDelay=255;      //255 ms max
    struct btn{
      byte state=0;   //0->nothing;1-click;2-dblClick
      Timer clickDelay;
    };
    volatile static btn buttons[2];         //only two buttons for now

  public:
    KeyboardBtn(){
      attachInterrupt(digitalPinToInterrupt(2),this->int_handler_btn0,FALLING);       //Initially the pins are set to HIGH(pullup behaviour)
      attachInterrupt(digitalPinToInterrupt(3),this->int_handler_btn1,FALLING);
    }

    static void int_handler_btn0(){
      btns_handler(0);
    }
    static void int_handler_btn1(){
      btns_handler(1);
    }
    static void btns_handler(byte key){
        if(buttons[key].state==1 && buttons[key].clickDelay.lapsed()<=clicksDelay){
          buttons[key].state=2;
        }else{
          buttons[key].state=1;
          buttons[key].clickDelay.mark(); //Pressed one time? mark this and wait for second press
        }
    }
    byte stateChanged(byte key){
      //Function called to get key status
      byte temp_state=buttons[key].state;
      if(temp_state==1 && buttons[key].clickDelay.lapsed()<clicksDelay){
        return 0; //We still wait:don't know if it's a dblClick or single
      }else{
        buttons[key].state=0;
        return temp_state;
      }
    }
};
volatile KeyboardBtn::btn KeyboardBtn::buttons[2];

But the compiler gives me headaches(of course my code is wrong somewhere but he could just have kept quite about it):

  C:\Users....\Humidity.ino:
  In static member function 'static void
  KeyboardBtn::btns_handler(byte)':

  C:\Users...\Humidity\Humidity.ino:74:68: warning: passing 'volatile Timer' as
  'this' argument of 'uint32_t Timer::lapsed()' discards qualifiers
  [-fpermissive]

     if(buttons[key].state==1 && buttons[key].clickDelay.lapsed()<=clicksDelay){

                                                                ^

  C:\Users...\Humidity\Humidity.ino:78:40: warning: passing 'volatile Timer' as
  'this' argument of 'void Timer::mark()' discards qualifiers
  [-fpermissive]

       buttons[key].clickDelay.mark();

                                    ^

  C:\Users....\Humidity\Humidity.ino:
  In member function 'byte KeyboardBtn::stateChanged(byte)':

  C:\Users....\Humidity\Humidity.ino:83:58: warning: passing 'volatile Timer' as
  'this' argument of 'uint32_t Timer::lapsed()' discards qualifiers
  [-fpermissive]

   if(temp_state==1 && buttons[key].clickDelay.lapsed()<clicksDelay){

                                                      ^

What is the problem?
Note:It does allow me to upload the code but I am almost certain it will generate some errors while running...


texts: The Ticker library for the ESP chips is quite useful, which wraps a os_timer_t object. I'd like to be able to see the time remaining on the timer, is it possible to do that witha os_timer_t object?


texts: Arduino works bad when powered by 9V battery

texts:
At first I am sorry for my bad English.

I am making robot which can do a lot of things...

If I connect arduino on my robot with PC via USB, the robot works properly. If I use external power supply (9V battery) the robot is doing almost nothing.. The diodes are little bit blinking and sometimes dc motors make motion... And thats all. Batteries are charged. Where's the problem?

Everything I want is make into motion dc motors.. With 5V USB it works. With external power supply not (9V battery).


texts: Arduino LCD is displaying gibberish, sometimes

texts:
Below is my code and a picture of the gibberish.  It's different every time.  If i pull out the temp sensor, i still get gibberish, sometimes.  I'm at a loss as to what to even be looking at now. Any ideas?

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//set capacities
int keg1_volume = 19;
int keg2_volume = 19;
const int temperaturePin = 0;

void setup() {
  //initial delay
  delay(1000);

  //set contrast
  pinMode(9, OUTPUT);
  analogWrite(9, 100);

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  // Print header to the LCD
  lcd.setCursor(6, 0);
  lcd.print("BeerView");
  lcd.setCursor(0,1);
  lcd.print("Keg (C)");
  lcd.setCursor(10,1);
  lcd.print("Keg (F)");

  //initialize serial for debugging
  Serial.begin(9600);

  //get voltage and calculate temp
  float voltage, degreesC, degreesF;
  voltage = getVoltage(temperaturePin);
  degreesC = (voltage - 0.5) * 100.0;
  degreesF = degreesC * (9.0/5.0) + 32.0;

  //display temp
  lcd.setCursor(0,2);
  lcd.print(degreesC);
  Serial.println(degreesC);
  lcd.setCursor(10,2);
  lcd.print(degreesF);
  Serial.println(degreesF);

}

void loop() {
}

float getVoltage(int pin)
{
  return (analogRead(pin) * 0.004882814);
}


texts:
I'm working on a program composed by several classes.
I reduced the size of a single class of (more or less) one hundred lines (4kb of stuff)
I expected a smaller sketch but surprisingly it is increased in size (few bytes).

How is it possible?It's something about the compiler?


texts: How to send data from arduino to Temp Controller for setting temp?

texts:
I send data from arduino by method following.
Configure the value : byte message[ ];

#include <SoftwareSerial.h>
#define RX 2
#define TX 3
int incomingByte = 0;

SoftwareSerial mySerial(RX, TX);

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

  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop()
{
  incomingByte = Serial.read();

  if (incomingByte == 's')
  {
    digitalWrite(5, HIGH);
    byte message[] = {0x01, 0x06, 0x00, 0x01, 0x02, 0x58, 0xD8, 0x90} ;
    mySerial.write(message1, sizeof(message1));
  }
}

It works. But I want to input from "Serial monitor" to set the temperature.
It does not work when input from "Serial monitor".


texts: What is the Maximum Current an Arduino can Supply?

texts:
I was wondering how much my Arduino I/O pin can output when it is set at Output and is at High.

I am using an Arduino Uno R3.

Thanks in Advanced.


texts: How can I attach sensors without a shield for a wearable project?

texts:
I am looking for a solution regarding the gsr, accelerometer, heart rate, skin temperature. From this other question seems that Grove isn't clear enough with their documentation. So I am looking for other ideas. I already know cooking hacks and I am afraid that with their hardware I can't make my Arduino wearable and comfortable enough, because at the end I'd like to attach a lithium battery with a case (that's why I don't want the extra bulk of a shield).

More details of what I am looking for.

Accelerometer:
Range: +/- 1.0g
Minimum resolution: 0.01g

Galvanic Skin Response
Range: 56k Ohms to 20M Ohms
Two-standard-deviation error of +/- 4.0% otherwise

Skin Temperature
Range: 20.0°C to 40.0°C
Resolution: 0.05°C
Error: +/- 0.8°C


texts: Driving high current through an LED using PWM

texts: We are trying to use an LED as a high frequency light source using PWM implemented through an Arduino. We use an NPN transistor to boost the voltage drop (and current flow) through the LED per the figure below. The TTL pulse is supplied at Vin and an external voltage (5V) is applied at Vcc. Our application requires that the LED is on for a very short duration (4 microseconds). We find that when we set the PWM for such short pulse durations there is a very low voltage drop across the LED(~1V) and hence not much light from the LED. Is this to be expected? And is there any way to boost the light output?


texts:
Are there any MQTT libraries that do not block while connecting?

I'm currently using PubSubClient, and the connection part contains this code:
https://github.com/knolleary/pubsubclient/blob/master/src/PubSubClient.cpp

        while (!_client->available()) {
            unsigned long t = millis();
            if (t-lastInActivity >= ((int32_t) MQTT_SOCKET_TIMEOUT*1000UL)) {
                _state = MQTT_CONNECTION_TIMEOUT;
                _client->stop();
                return false;
            }
        }

I'd like my main loop to continue, or a callback to be called, while the MQTT connection is established, rather than waiting for ages if the MQTT server is unavailable.

Update:

I wrote a modification to take a callback function, and called it in an else clause added to that if statement, and discovered that the blocking delay is not this while loop. I think it's in the _client->connect at the start of the method.


texts: HMC5883L - Tilt compensation without Accelerometer

texts:
Trying to get an HMC5883L to compensate for being installed in 90 degrees. Doesn't seem to me that it'll need too complex math or accelerometer. But I have no idea how to do the compensation for it. Any idea?

Using the Adafruit HMC5883L and its library.


texts: My button stays on high if I press it once, what did I do wrong?

texts:
If I press my button once, I get characters on all of the 32 character places and I get an infinite tone with my piezo. Can someone help me with this?

#include <LiquidCrystal.h>

const int buttonPin = A0;
int buttonState = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte run1c[8] = {
  B00000,
  B01100,
  B01100,
  B00000,
  B01110,
  B11100,
  B01110,
  B10010,
};

byte run2c[8] = {
  B00000,
  B01100,
  B01100,
  B00000,
  B11100,
  B01110,
  B11100,
  B10010,
};

byte jumpc[8] = {
  B01100,
  B01100,
  B00000,
  B11110,
  B01101,
  B11111,
  B10000,
  B00000,
};

byte jumpLowerc[8] = {
  B01110,
  B11100,
  B01110,
  B10000,
  B00000,
  B00000,
  B00000,
  B00000,
};

byte groundc[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};

byte rightGroundc[8] = {
  B00011,
  B00011,
  B00011,
  B00011,
  B00011,
  B00011,
  B00011,
  B00011,
};

byte leftGroundc[8] = {
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
};

void setup() {
  lcd.createChar(0, run1c);
  lcd.createChar(1, run2c);
  lcd.createChar(2, jumpc);
  lcd.createChar(3, jumpLowerc);
  lcd.createChar(4, groundc);
  lcd.createChar(5, rightGroundc);
  lcd.createChar(6, leftGroundc);
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if(buttonState == HIGH){
    tone(8, 400);
    lcd.setCursor(1,0);
    lcd.write(byte(2));
    digitalWrite(buttonState, LOW);
  } else {
    lcd.setCursor(1,1);
    lcd.write(byte(0));
  }
}


texts: How do you make a stepper motor move in accordance to earthquake data using arduino?

texts:
I am new to arduino. I can import the acceleration data from a text file into arduino and I can also make the motor run at that acceleration with a distance calculated from an equation. I use the AccelStepper library but I notice that per acceleration data, the motor stops abruptly and moves  again in a very short delay, causing a lot of vibrations. Is there any easier way to make a stepper motor run with acceleration values from a text file?

The text file is also placed on an SD card, and I use the function Serial.parseFloat() to get the data from the file.

Here is my code:

#include <SPI.h>
#include <SD.h>
#include <AccelStepper.h>
int STP = 4;
int DIR = 3;
const int chipSelect = 53;
double Acceleration = 0;
double Previous_Acceleration = 0;
double Velocity = 0;
double Previous_Velocity = 0;
double Distance = 0;
double Previous_Distance;
AccelStepper stepper(AccelStepper::DRIVER,STP,DIR);
void setup(){
  pinMode(STP,OUTPUT);
  pinMode(DIR,OUTPUT);
  Serial.begin(38400);
  Serial.println("Starting Program");
  delay(1000);
  while (!Serial){
    ;
  }
  Serial.println("Initializing SD Card...");
  if (!SD.begin(chipSelect)){
    Serial.println("SD Card Error");
    while(1);
  }
  Serial.println("Card Initialized");

  File dataFile = SD.open("sinx.txt");

  if (dataFile){
    while (dataFile.available()){
      Acceleration = dataFile.parseFloat();
      Velocity = ((Previous_Acceleration + Acceleration)/2) + Previous_Velocity;
      Distance = ((Previous_Velocity + Velocity)/2) + Previous_Distance;
      stepper.setSpeed(Velocity);
      stepper.setAcceleration(Acceleration);
      stepper.runToNewPosition(Distance - Previous_Distance);

    }
  }
  else{
    Serial.println("Error");
  }
}

void loop(){

}


texts: How to read a timer's value once stopped?

texts:
I've downloaded the Timer1 library but unfortunately it seems that the read() method has been removed from it. I tried also SimpleTimer library from the arduino website but the program didn't compile because of undefined reference to `SimpleTimer::SimpleTimer()' error. Anybody knows how to solve this error or just another timer library which has a read function?

To be more specific I need to start a timer as I press a button and to stop it as it is released.


texts:
I have a project that I am putting an Arduino Nano in an enclosed box that will light LEDs in a pattern. I am planning to power it with a 5 V power brick but I would like to build a way a update the code to the Arduino without needing to disassemble the box.

Could I use an OTG cable with power (OTG Y cable)  to accomplish this? or is there a better way to do this?


texts: Can I drive an LM334(Z) from an Arduino with AnalogWrite()?

texts:
I need programmable current control, fading from zero to 2 milliAmps.  I was hoping to use Arduino's AnalogWrite(), which uses Phase Width Modulation (PWM) to simulate analog output with a sawtooth wave on a duty-cycle; to control an LM334Z to deliver a slowly ramped low current delivery.
[The application is a TransCranial Direct Current Stimulation (TDCS) micro-current delivery to the human scalp. Jumping straight to 2 milliAmps is uncomfortable].
Will PWM work? Or, do I need some sort of smoothing circuitry to soften the PMW before it is applied to the LM334Z's Rset pin to accomplish the above?


texts: Porting ATMega8 AVR based program to Intel Curie Processor

texts:
I'm currently trying to port a program called 'ArduinoUSBLinker' to work on my Arduino 101 (which has an Intel Curie CPU instead of the standard ATMega CPU).

The program is used to flash ESCs without the need of additional hardware.
Arduino USB Linker

Unfortunately the code is mainly based on the ATMega's built in AVR timers,
which uses several different predefined variables such as TCCR0,TCCR1,TCTN2…

These are not available (or are they?) in the Curie Module. Since the Arduino 101 has timer functionality, I was wondering if there is a way to translate those into the Curie Timer library.


texts: Arduino + motor driver (L293D) power consumption

texts:
Please help me on this question.

Original question :
My chip consists of 1 arduino nano and  3 L293D motor driver. This chip is for controlling motors and other equipments. My question is about how to calculate power consumption of my chip. I searched for about voltage settings of arduiono nano and L293D motor driver, but there are many phusical thinks that i cannot understand. How many hours 2000 mah battery enough for.

Note :
Motors and other equipments will have own power supply. That i say it is just for Arduino Nano, Bluetoot adapter for arduino (HC-05) and 3 motor driver (L293D).


texts: I have a PIR motion sensor and would like some ultra bright UV led lights to fade in when this is triggered. It is one unit, consisting of 225 led lights connected to 240v mains (Australia). I bought a relay for the basic on/off function but was wondering if fading on and off can be done relatively easily - this is my first arduino project. I would value any suggestions.


texts: How to rotate a servo motor on a specific angle?

texts:
I am trying to rotate a top on a specific angle after every 1 second. For example: 1 degree/second. I have two question:

Can I achieve this with servo motors?
If not, what motor should I use?

I know this question has very little description. I am mainly a programming guy. I don't much about arduino stuff. It's actually a hobby project for me.

Thanks in advance.


texts: I need help in designing a circuit to connect an Arduino MEGA and a CD-Pickup Reader/Writer

texts: I'm trying to use the IR source and detector of the CD Pickup reader/writer (KSS-213C) along with the lens focussing/tracking system. I want to control them using an Arduino MEGA. So since I will be needing one constant source for the diode, I will connect it separately to a source, not to the Arduino. Since this is a sensitive device, I read that you need to have constant current sources and so on. Now, I'm new to designing circuits of my own, I found this picture in an article, but it is for a DVD writer. Could someone tell me if I could use the same circuit with some modifications or should I try something else. Now note that my main output is that of the IR sensor that my Arduino would read.


texts:
I'm trying to get a XBEE shield to operate on an Arduino Leonardo. Usually i use the AltSerialLibrary to emulate an extra serial for the xbee. However since the Leonardo comes with two sets of serial, i figured I use that instead.

//#include <AltSoftSerial.h>

//AltSoftSerial XBee(5,13); // RX, TX

void setup() {

  Serial1.begin(9600);
  Serial.begin(9600);

}

void loop() {

  Serial.println("Odds");
  Serial1.println("Ends");

  delay(1000);

}

The code above aims to write values to both the serial monitor (serial) and xbee (serial1). However in the Xbee's XCTU program, the remote xbee does not recieve any data.

Any feedback on how I might fix this will be appreciated.


texts: Can I make the Arduino ignore serial print

texts:
I like having serial communication for debugging and testing purposes but after a while it takes away too much speed from the sketch.

Is it possible to have the Arduino ignore serial.print and serial.println throughout my code, without turning it into a comment or placing every serial printing inside for example "if(debug == true)" statements?

Thanks in advance.


texts:
I have GPRS(GPRS_Shield_V1.0), weather shield and arduino uno R3. When I use Arduino and GPRS it works perfectly and when I used Weather Shield it also worked perfectly. But weather shield needs wire library, to use sensors. And when I use GPRS library with wire library, my program prints the same string many times. How I can use these two shields together?

These are some pics of my connected shields:

http://puu.sh/gcvk3/85595c38c7.jpg

http://puu.sh/gcvpc/22185212d3.jpg

As you can see, I'm not using A0,A1,A2,A3,A4,A5 pins for GPRS Shield. Thank you!


texts: Bit Bang I2C with port manipulation on AtTiny84: new pinout doesn't work

texts:
So I am trying to understand bit banging and port operations. I'm developing a breakout board with an ADXL343 IMU read by an AtTiny44 via i2c. I adapted this code from MIT's How To Make Almost Anything which I also explained a bit here in this thread. Like I mentioned there, I got it working with the MIT code, and now have a basic sketch that works for my original board, where I define the pins like this.

#define SCL_pin (1 << PB0)
#define SCL_pins PINB
#define SCL_port PORTB
#define SCL_direction DDRB
#define SDA_pin (1 << PB1)
#define SDA_pins PINB
#define SDA_port PORTB
#define SDA_direction DDRB

UNFORTUNATELY, I designed and fabricated a new board where the SCL and SDA pins are now PA3 and PA2 respectively. I tried to adjust the sketch by changing the defines to all be PORTA, DDRA, etc like this:

#define SCL_pin (1 << PA3)
#define SCL_pins PINA
#define SCL_port PORTA
#define SCL_direction DDRA
#define SDA_pin (1 << PA2)
#define SDA_pins PINA
#define SDA_port PORTA
#define SDA_direction DDRA

Problem is, the tiny44 ceases to read from the IMU with the new pinout. The input/output functions in the program look like this:

#define output(directions,pin) (directions |= pin) // set port direction for output
#define input(directions,pin) (directions &= (~pin)) // set port direction for input
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin

The pi I am using is getting the initial values of data[], so I know it is communicating fine with the tiny44

I realize the pin mapping changes depending on the core I'm using. I don't think that impacts the way the SDA_pin and SCL_pin are defined, because defining them PB0 and PB1 worked... Plus I tried about every pin name possible.

I have also tried the Damellis and Drazzy cores, and neither is working for me.

I tried using a few BitBang libraries like SoftWire, but with no luck.

I have tried a few boards as well, so I don't think it's hardware related.

I don't know what else to try. Any help would be much appreciated! Thanks!!


texts:
I have my Arduino uno setup with RC522 reader. I am able to dump the data that is held on my test card supplied with the reader but I wish to read the data blocks held within another card I have. The reader shows this as a Mifare classic but Does not dump the blocks.
This is with miguelbalboa library

Card UID: EE 67 29 8D
Card SAK: 08
PICC type: MIFARE 1KB
Sector Block   0  1  2  3   4  5  6  7   8  9 10 11  12 13 14 15  AccessBits
  15     63  PCD_Authenticate() failed: Timeout in communication.
  14     59  PCD_Authenticate() failed: Timeout in communication.
  13     55  PCD_Authenticate() failed: Timeout in communication.
  12     51  PCD_Authenticate() failed: Timeout in communication.
  11     47  PCD_Authenticate() failed: Timeout in communication.
  10     43  PCD_Authenticate() failed: Timeout in communication.
   9     39  PCD_Authenticate() failed: Timeout in communication.
   8     35  PCD_Authenticate() failed: Timeout in communication.
   7     31  PCD_Authenticate() failed: Timeout in communication.
   6     27  PCD_Authenticate() failed: Timeout in communication.
   5     23  PCD_Authenticate() failed: Timeout in communication.
   4     19  PCD_Authenticate() failed: Timeout in communication.
   3     15  PCD_Authenticate() failed: Timeout in communication.
   2     11  PCD_Authenticate() failed: Timeout in communication.
   1      7  PCD_Authenticate() failed: Timeout in communication.
   0      3  PCD_Authenticate() failed: Timeout in communication.

I have also tried using these examples https://github.com/BoolLi/RC522_RFID_NFC_Utilities

But they fail to compile for me. All I want to do is dump the data blocks from a university card I have for a project, I don't need to be able to write to the card yet.


texts:
I am coding my arduino for an upcoming robot competition. I have managed to upload my code and run it on my arduino once or twice, however now I am unable to upload code. I now receive the following message:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

I have unplugged USB, pushed the reset button, checked all the settings (ports, programmer, etc), unplugged the arduino and even tried running basic code such as Blink. I've been searching for hours and now I'm not sure what to do. I am getting no response and I'm finding this really frustrating. Does anyone have any advice as to how to resolve this issue?


texts: Constant ADC sampling rate on ESP8266 or ESP32

texts:
I want to sample Sound input with either an ESP8266 (preferred) or ESP32. As I'm using a low pass filter anyway, a sample rate of 1000-2000hz would be totally ok. What is more important, is that it is constant. Can I use DMA for that? If so: how? Or should i go via Timer interrupts?
I know about the wifi issue on the ESP8266, but I intend to just turn Wifi off as I don't need it for this project.


texts:
Hello i've try to decode JPG image from FS so, i create and upload spiffs image (using /data directory and Arduino Ide Plugin )

On every jpg i've same error: "pjpeg_decode_init() failed with status 19"

here is my same code:

#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#include "GfxUi.h"

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

#define DEBUG
#define LOAD_SPIFFS

GfxUi ui = GfxUi(&tft);

void writeFile(fs::FS &fs, const char * path, const char * message);
void readFile(fs::FS &fs, const char * path);
void listDir(fs::FS &fs, const char * dirname, uint8_t levels);

void setup(void)
{
  Serial.begin(115200);
  Serial.print("Start");
  SPIFFS.begin(true);
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK);

  listDir(SPIFFS, "/", 0);
  fs::File jpeg = SPIFFS.open("/star.jpg", "r");
  //readFile(SPIFFS, "/star.jpg");
  boolean decoded = JpegDec.decodeFsFile(jpeg);
  Serial.println("===============");
  Serial.println("JPEG image info");
  Serial.println("===============");
  Serial.print  ("Width      :"); Serial.println(JpegDec.width);
  Serial.print  ("Height     :"); Serial.println(JpegDec.height);
  Serial.print  ("Components :"); Serial.println(JpegDec.comps);
  Serial.print  ("MCU / row  :"); Serial.println(JpegDec.MCUSPerRow);
  Serial.print  ("MCU / col  :"); Serial.println(JpegDec.MCUSPerCol);
  Serial.print  ("Scan type  :"); Serial.println(JpegDec.scanType);
  Serial.print  ("MCU width  :"); Serial.println(JpegDec.MCUWidth);
  Serial.print  ("MCU height :"); Serial.println(JpegDec.MCUHeight);
  Serial.println("===============");
  Serial.println("");
}

void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    Serial.printf("Listing directory: %s\r\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("- failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println(" - not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            Serial.print("  DIR : ");
            Serial.println(file.name());
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            Serial.print("  FILE: ");
            Serial.print(file.name());
            Serial.print("\tSIZE: ");
            Serial.println(file.size());
        }
        file = root.openNextFile();
    }
}

void readFile(fs::FS &fs, const char * path){
    Serial.printf("Reading file: %s\r\n", path);

    File file = fs.open(path);
    if(!file || file.isDirectory()){
        Serial.println("- failed to open file for reading");
        return;
    }

    Serial.println("- read from file:");
    while(file.available()){
        Serial.write(file.read());
    }
}

void writeFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Writing file: %s\r\n", path);

    File file = fs.open(path, FILE_WRITE);
    if(!file){
        Serial.println("- failed to open file for writing");
        return;
    }
    if(file.print(message)){
        Serial.println("- file written");
    } else {
        Serial.println("- frite failed");
    }
}

void loop() {

}

Output from serial:

Listing directory: /
  FILE: /logo.jpg       SIZE: 16346
  FILE: /arduino.jpg    SIZE: 8426
  FILE: /star.jpg       SIZE: 3853
pjpeg_decode_init() failed with status 19 <--- here is
===============
JPEG image info
===============
Width      :0
Height     :0
Components :0
MCU / row  :0
MCU / col  :0
Scan type  :0
MCU width  :0
MCU height :0
===============


texts: I have a problem with connecting my NodeMcu to gsm. I have bought GSM module but I have sim code on card which I can't and that is the problem because I've found some libraries but there are no examples how to connect with pin code. I have found one but not compatible with NodeMcu. How can I do It?


texts:
I have shift register 74HC595. I added 7 push buttons from Q1-7 and the 8th to ground. On the other side which pin of the register will go to Arduino pin 2? And wich one to the 5v pin?

How can I read one button at a time in the code because on the Arduino it is just 1 pin?


texts:
My project is battery powered and it has it's own usb port for charging. Can I snip off the HUGE DC barrel jack which is making it hard for me to fit this into an enclosure.

Or could that cause problems?


texts:
I am trying to learn and understand the COSA Library using a 12864ZW (ST7920) 128X64 LCD Display. Right now I am able to use the LCD using the u8glib but also found that COSA has a library for the ST7920 Display, I originally used this tutorial to get things working.

The main problem that I have now is in the ST7920 Documentation there is a schematic that shows how to hook up a ST7920 Compatible LCD. The first tutorial only uses 3 lines from the Mega and the Cosa is using what looks like 6 lines.

Looking at the header file, it looks like it is derived from the HD44780 Class and what I can gather is pins 16 and 4 are hard coded for something? I am not quite clear on how to use the Cosa version of the library. Can someone please give me a explanation and perhaps a explanation on how to get this working using Cosa?


texts: Bluetooth data: how to handle these data?


texts:
I have a LED attached to my Arduino wifi shield that I want to control from my PHP web server.  In terms of communication, should I

Make my Arduino a web server and then communicate with PHP web server via HTTP
Make my Arduino a web client and receive commands from my PHP web service.  I would parse the JSON response

Also my other question is should I communicate with JSON between my PHP web server or is there a better way to send commands to my LED light?


texts: How to Create a reference to an External Print object

texts:
Right now I have an object:

class Dog
{
  public:
    Dog(uint8_t I2c, Stream& feedback);
    void Speak();
  private:
    uint8_t _I2c;
    Stream& _output;
};

Dog::Dog(uint8_t I2c, Stream& feedback):_output(feedback),_I2c(I2c){}

Dog::Speak(){
_output.println("Hi There.");
}

That is currently constructed in my sketch via:

Dog Dug([I2cPort], Serial);

How can I modify my class so that to be compatible with taking either a Serial object or an LCD display (using Adafruit's RGB LCD library )?

Eg:

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
Dog Dug([I2cPort], Serial);
Dog Sam([I2cPort], lcd);

Additional info:

The LCD in question is mostly used as a UI display in its own library this library refreshes the display every 1.5 sec. As information from speak(); and the UI have similar priority, it is acceptable if one instantly overwrites the other.

I am open to solutions that involve modifying the construction of Dog the only requirement is that I need to be able to indicate print("[something]"); in the Dog.cpp

I'm interested in asking this question on the Arduino SE as I believe there are differences in how you would approach this if the problem was on a traditional computer.


texts: Can I make the BT module disconnect with a BT module and connect with another in the code?

texts:
I am working on a project that requires a connection between two BT modules (HC-05) and a mobile phone. Later on, I encountered a problem: I can't connect two BT modules to one at the same time, So I thought about the possibility of ending a connection and starting the other one when needed. If that was possible, how can I do that in an arduino code?

One of the BT modules is a master which means it can't connect to the phone and it has to be a master because it must be connected to the other slave BT module.


texts: Control arduino with keybaord via computer

texts:
I'm brand new to arduino but I'm trying to figure out how to set up a WASD steering system for my robot I made.

I have the physical setup all ready but I don't know the code to use that would allow me to use my computers keyboard. I would like to still have my keyboard attached to my computer while I do this. I.E. I don't want to manually plug the keyboard into arduino.

I asked this on Robotics stack exchange but they said to ask here.

A list of functions/blocks Iof code that is applicable would be the best answer, but I'll take anything that'll get my bot moving :)

Edit I'm using a wireless keyboard, but my arduino is connected via USB.


texts: What is the worst time case for Arduino Mega?

texts: I'm going to implement home automation using an Arduino Mega with 8*6=48 channels relay in my new home. I have prepared an Android app for an HC-05 Bluetooth controller. How much time can I keep running an Arduino Mega with all the appliances in a home? Can I keep it working 24/7 for a while?


texts:
I have an elegoo car model and am trying to make it turn 90 degrees whenever it gets to a 90 degree turn. This model has line tracing and it works fine on curved surfaces but doesn't work so on 90 degree turns.
    /Line Tracking IO define
#define LT_R !digitalRead(10)//connected to pin 10. Value is inverted
#define LT_M !digitalRead(4)
#define LT_L !digitalRead(2)

#define ENA 5//input to enable motor A. Controls speed
#define ENB 6//input to enable motor B
#define IN1 7//Control spinning direction of motor A. If one of them is high motor spin(an OR gate)
#define IN2 8//Same motor A
#define IN3 9//3 and 4 are for motor B
#define IN4 11

#define carSpeed 100

void forward(){ //car goes forward
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("go forward!");
}

void back(){ //car goes backwards
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("go back!");
}

void left(){ //goes left
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("go left!");
}

void right(){ //goes right
  analogWrite(ENA, carSpeed);
  analogWrite(ENB, carSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("go right!");
}

void stop(){ //power is shut off
   digitalWrite(ENA, LOW);
   digitalWrite(ENB, LOW);
   Serial.println("Stop!");
}

void setup(){
  Serial.begin(9600);
  pinMode(LT_R,INPUT);//takes input from all the sensors
  pinMode(LT_M,INPUT);
  pinMode(LT_L,INPUT);
}

void loop() {

  if(LT_M){
    forward();
    while(LT_M);
  }
  else if(LT_R) {
    right();
    while(LT_R);
  }
  else if(LT_L) {
    left();
    while(LT_L);
  }

  else if (LT_M && LT_R && !LT_L) {
  delay(500);
  right();
  }

  else if (LT_L && LT_R && !LT_R) {
   delay(500);
   left();
    }


texts:
I'm trying to write to and read from an AT93C46D eeprom using an Arduino UNO but for some reason the output I'm getting is not what I expect.

The eeprom has a data structure of 128 words of 8 bits each and I'm trying to write 10000010 to each word. When reading back the data however I get 11000001.
When I write 00000000 to all words I get 10000000 for all words when reading. I tested my code on 2 AT93C46D eeproms and both gave the same result.

It looks like the MSB is always 1 (when reading) for some reason.

I'm probably making a stupid mistake but I can't seem to find it, any help is greatly appreciated!

Datasheet: http://www.atmel.com/images/atmel-5193-seeprom-at93c46d-datasheet.pdf

#include<SPI.h>
#define DATAOUT 11//MOSI
#define DATAIN  12//MISO
#define SPICLOCK  13//sck
#define SS 10//ss

void setup()
{
  pinMode(SS,OUTPUT);
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  digitalWrite(SS,LOW);

  Serial.begin(9600);

  SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));

  fill();

  dump();
}

void loop()
{

}

void fill()
{
  Serial.println("Send EWEN opcode");
  digitalWrite(SS,HIGH);
  SPI.transfer(B10011); //EWEN
  SPI.transfer(B0000000);
  digitalWrite(SS,LOW);

  delay(100);

  for (int i=0; i < 128; i++) {
    digitalWrite(SS,HIGH);
    SPI.transfer(B101);
    SPI.transfer(i);
    SPI.transfer(B10000010);
    delay(10);
    digitalWrite(SS,LOW);
  }

  delay(100);

  Serial.println("Send EWDS opcode");
  digitalWrite(SS,HIGH);
  SPI.transfer(B1000); //EWDS
  SPI.transfer(B00000000);
  digitalWrite(SS,LOW);

  delay(10);
}

void dump(){
  Serial.println("Dumping AT93C46D");

  byte b;

  for (int i=0; i < 128; i++) {
    digitalWrite(SS,HIGH);
    SPI.transfer(B110); //read opcode
    SPI.transfer(i);
    b = SPI.transfer(B00000000); //clock data out
    digitalWrite(SS,LOW);
    Serial.println(b, BIN);
  }
}


texts: How to use ESP8266-12E with PCF8574 as an I/O extender

texts:
I am using ESP8266-12E with a PCF8574 as an I/O Pins Extender.
There are videos on youtube to use the PCF8574 with an ESP8266-01, but my problem is that I'm unable to analyze the pin connections with an ESP8266-12E.
In the youtube tutorial it is said that the GPIO0 AND GPIO2 will go to the SDA and SLC pins of the PCF8574, but then, in the case of ESP8266-12E, the pins will go to the PCF8547.

Thanks in advance.


texts:
My question is simple. Is the following possible?

I am using one Arduino Mega 2560 board and its SPI functionality to adjust voltages (0-4.096V) through a 12-bit DAC (MCP4822).

I would like to measure the output voltages from the DAC by feeding them through a 12-bit ADC and back to the Arduino. The DAC's output voltages that will be directly measured by the ADC will be displayed on an LCD and on LabVIEW.

Is this possible, given that both the DAC and the ADC have to be connected to the same SDI and SCK pins on the Arduino for SPI to work?


texts: Digispark ATtiny 85 erases flash after power loss

texts:
I have some issues with my Digispark ATtiny85 board.
If I upload the blink sketch for example the LED starts blinking and everything looks fine. But as soon as I unplug the Digispark from the USB port and plug it back in nothing happens. I know that the programm starts with a delay of 5 seconds so programming via USB becomes possible, but still nothing. Its seems like the flash-memory (where the programm is stored) of the ATtiny 85 is empty.

Here is the example blink sketch:

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A
}

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

I also tried uploading the sketch from a Laptop running on Windows but without success.

I am using Linux Mint and Arduino IDE 1.8.10.

Since I am new to Microcontrollers, I would be grateful for explainations, tipps or useful links.
Thank you!


texts: How to switch a low-voltage (1.5V) toy motor with an arduino?

texts:
I would like to add an Arduino to control a toy with a 1.5V battery and motor in it.  The toy is currently controlled by a SPST switch in series with a single 1.5V AA battery and a cheap motor.

I could put in a transistor like How to switch an external circuit with Arduino? or To connect a simple toy circuit and trigger with an arduino?  but I would think the voltage drop of the transistor would be significant in the 1.5V circuit.

What would you recommend for switching a 1.5V circuit?


texts:
I'm new to this kind of thing. My code works on my Uno without problem with two separate servos. I've ensured that it's not any faulty leads, having tried a few other circuits with LEDs, buttons and potentiometers as well, simply switching between my Uno (which works fine) and the Nano.

I've chosen the correct port, chipset and board each time and the code uploads fine to the Nano. The Nano simply refuses to do anything I tell it.

Digital PIN of servo goes to designated D5 pin.
Ground goes to the GND near the Analog pins (shouldn't matter which I imagine).
Power goes to 5V.

The code above simply tells the servo to go to a certain degree when uploaded. Could anybody tell me why the servo will not move at all with the Nano? I just bought it and I haven't hooked up any power to it other than the USB, surely it isn't fried. It lights up and flashes as well.

#include <Servo.h>
Servo my_servo;

void setup() {
  my_servo.attach(5);
  // Pin definition
}

void loop() {
  my_servo.write(60);
  // No. of degrees
}


texts: I have used sim900 in my project but it isn't fast, I don't know if it is because it is on 2G or what, I wanna know if I can get something good that can send SMS messages immediately and doesn't take time to send multiple messages, if I switch to something that supports 3g can that solve my problem?


texts: Bluetooth module(HC05) works with Arduino Uno but not with breadboard (ATmega328)

texts:
I am currently working on a project that requires communication between an android phone(galaxy s4) and an ATmega328 microprocessor. To connect these devices wirelessly I'm using an HC05 bluetooth module and to understand the connection I'm using pre-built arduino codes(turn LEDs on and off) and an android app called blueterm.

This connection is established and able to transmit data when connected to the Arduino uno, but as soon as this chip is removed and connected to a standalone breadboard the connection fails. The standalone breadboard works fine and has been tested with many other projects and I have attached the breadboard connection below. The HC05 when connected to the breadboard changes the blinking pattern to notify the user it is connected but the serial connection is never made. Any help would be greatly appreciated, if any other information is needed feel free to ask.


texts: What happens if you write >10000 times to the flash memory of an ATmega?

texts:
I realized that I'm uploading code every 5 minutes and doing relatively intensive trial-and-error development, and that this habit could cause problems down the road, especially if I'm working on a custom board (non-Arduino) where the chip isn't readily replaceable.

What will happen?

I noticed that avrdude verifies the written flash. So will it simply start noticing errors and possibly be unable to write without failing?

Or will it work sometimes, sometimes not?

Example of heavy use: A custom PCB where easy replacement of the MCU is not possible. 10,000 writes would equal 100 days, each 8 hours of development, with flash write every 5 minutes.

I have several habits that drive frequent flash writing: I inject benchmarks into my code, test speed improvements of small optimizations, program size optimizations, and so on.

I now try to restrain myself from flashing too frequently and doing more code revisions before testing, rather than testing immediately.

In conclusion: Yes, it's unlikely, and arguably, if you're working full-time on a board, less intensively, for, say, a year, you can probably afford to buy another board when the first one starts failing the flash-verification.


texts: What is the right way to query an I2C device from an interrupt service routine?

texts:
The ADXL345, for example, requires that interrupts are responded to by querying the INT_SOURCE (interrupt source) register. In example code for the SparkFun ADXL345 Arduino Library, there is code that looks like:

void ADXL_ISR() {
  // getInterruptSource clears all triggered actions after returning value
  // Do not call again until you need to recheck for triggered actions
  byte interrupts = adxl.getInterruptSource();

  // Free Fall Detection
  if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){

However, under the covers adxl.getInterruptSource() is sending an I2C message and receiving a response. This seems to be a bad idea in an interrupt service routine (ISR).

A possible option seems to be to turn on interrupts prior to calling adxl.getInterruptSource(), however there is much advice about not doing this (such as, Nick Gammon's informative post). I've managed to get it to work with something of the form:

void setup() {
  attachInterrupt(digitalPinToInterrupt(INT_PIN), isr, LOW);
  ...
}
void isr() {
  detachInterrupt(digitalPinToInterrupt(INT_PIN));
  interrupts();
  byte interrupts = adxl.getInterruptSource();
  ...
  attachInterrupt(digitalPinToInterrupt(INT_PIN), isr, LOW);
}

This seems to work but I'm worried I'm missing something. Any suggestions?

EDIT: Thanks for the answers that suggest polling, however I am using a MKR1400 and wish to minimise power consumption by putting the processor into a sleep state - only waking up to process the relatively rare "activity" or "free fall" events. As pointed out by @Majenko, a combination of sleeping and polling might be used. So this really just leaves the question of why is the above a bad idea.


texts: Understanding flow of current with pull-up and pull-down circuits

texts:
I am new to all of this and was trying to figure out what was happening with pull-up/pull-down circuits.  I think I understand what happens when the board handles the pull-up/pull-down but I wanted to try to build the circuits.  I got help from another forum.  Once I made the circuits, I found that I don't understand the path that the voltage is traveling.  I have 2 examples with multimeters attached.

Pull Up

I understand the press of the button connect circuit to ground.  But why does the voltage everywhere go down to zero when it is connected to ground?  Does it have something to do with the multimeter can't read the voltage because the current is taking the path of least resistance - which I have read is a myth?

Pull Down

When compared to the Pull Up, why does the voltage go to 5 before the yellow wire when the button is pushed?  Isn't it connected to the ground again which seems like it should cause the same scenario as the Pull Up where they all read zero.  Or does the resistor before ground have something to do with this.

I know nothing about electronics.  Some information and links where I could find more information would be great.  Thanks.

All the gifs are screen recordings from circuits I built with circuits.io.  I want to get into making somethings but wanted to practice first before I spent any money.


texts: To calculate an operation execution time, I was saving the millis() result before and after the operation to calculate the interval time. Is there an alternative on the Arduino Uno like the RDTSC found on x86 architectures?


texts: How do I find out what my esp3286 core version using Arduino IDE?


texts: Is there a way to upload precompiled code to an arduino?

texts:
My company is developing a programmable remote control car which is driven by an Arduino Nano. We would like a way for the user to install software updates to the Arduino, but we don't want to give the user access to the code.

Is there a way to compile Arduino code without automatically uploading it, so that I can put the pre-compiled binary up for download on a website?

Then after this how would I go about manually uploading it (to the Arduino)?


texts:
I found a library for the Speck cipher here: https://github.com/Chien-Ning/ArduinoCrypto

And I'm trying to use but haven't had much luck. My code is the following:

#include <SPECK_AVR.h>
#include <SPECK_spec.h>

#include "SPECK_AVR.h"

void setup() {
  // put your setup code here, to run once:

  SpeckTxtLen = 32;
  SpeckKeyLen = 64;
  speckTxtKey[]= 0x65, 0x74, 0x69, 0x4c, 0x19, 0x18, 0x11, 0x10, 0x09, 0x08, 0x01, 0x00;

  speckKey();
  speckEnc();

  Serial.println("");
  for (int i = 0; i < SpeckTxtLen/8; i++){
  Serial.print(speckTxtKey[i], HEX);
  Serial.print(", ");
  }
}

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

}

And I'm getting this error:

error: lvalue required as left operand of assignment

and

error: expected primary-expression before ']' token

Do you think I'm missing something in the usage of this library?

Thanks in advance


texts: connect arduino to battery with 12V motor

texts:
I am looking  at this(instructable with circuit picture) tutorial for making a self-balancing robot. However, I am confused about how the battery connects to the arduino. I know the 12 V must go to the motors to power them yet the diagram shows wires connecting to the Arduino through some kind of green device. I assume this connects to the power supply . However I do not have this green device and I don't know how to connect to the power supply. How should I get a charger cable and solder on the battery wires to the charger? If so are there any tutorials? Is the connection to the Arduino necessary?

(please look at the Firizing diagram in the instructable)
Thanks


texts: ESP-01 wakes up from deep sleep and then hangs

texts:
I have found a number of other posts from people with the same problem but I can't find an answer.
I have a small batch of ESP-01 boards, sold by Inland, and I wish to use deep sleep mode on them.
I soldered a small copper wire from pin 8 (i.e. GPIO 16) to RST.  On one board I soldered it directly, on another I soldered pin 8 and RST to two sides of a 2 pin header so I could use  jumper in case I wanted to disconnet GPIO 16 from RST.
I am flashing the following simple code (using Arduino IDE 1.8.12), which is about the simplest test of the deep sleep mode that I can think of.
void setup()
{
   Serial.begin(74880);
   Serial.setTimeout(2000);

   while(!Serial) { }

   Serial.println(
     "I'm awake, but I'm going into deep sleep mode for 15 seconds");

   ESP.deepSleep(15e6);
}

void loop() {
}

On starting the serial monitor shows
ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3664, room 16
tail 0
chksum 0xee
csum 0xee
v39c79d9b
~ld
I'm awake, but I'm going into deep sleep mode for 15 seconds

After 15 seconds the serial monitor shows
ets Jan  8 2013,rst cause:2, boot mode:(3,6)

and nothing else. After that the thing hangs and nothing further happens.
So,  it appears that the setup runs, the serial monitor prints the message, the mc goes into deep sleep, after 15 seconds it wakes up by a reset, but doesn't go through set up again, hence doesn't print the message or go back sleep.
Here are some comments.    The problem has nothing to do with Wifi, MQTT etc, I have tried many fancy sketches using all of these, I have same problem no matter what, the above sketched is my distillation to the simplest demonstration of the deep sleep problem.
I have flashed the program with Arduino IDE, Platform IO, and esptool.py from a command line.  It doesn't make a difference.
There may be a problem with my soldering job, but I'm pretty good at soldering and SMD rework, and I have repeated the job on a number of these ESP-01 modules, inspected and tested with multimeter, etc.  all with the same outcome.
I don't see a problem with my code or IDE, I have a batch of Lolin Nodemcu boards, and this sketch works perfectly on all of those.  In that case I simply connect GPIO 16 to RST with a jumper wire, the program prints the message, sleeps for 15s, wakes up, prints it again, goes back to sleep for 15s more, etc. etc.
Are these just bad boards?  I have read some things that say the flash chips might be lousy, and if I replace those it might help? I'm tempted to trash these boards and buy some D1 mini's, but I've seen a number of posts from people who say they've had the same problem with D1 minis.   If the board is the problem, are there any recommendations for manufacturers or vendors that sell better quality?


texts: I have a hex file of a sketch i.e. sketchname.ino.hex. Can I find out anything from that hex file ?  Can I see the output or anything ? Can I upload it on arduino ?


texts: Is setting clock divider worth changing on delay() to save power?

texts:
Along all the "advanced" methods described in this article, does simple method as downscaling processor while delay makes a difference on power consumption? How much time does the clock alternation takes itself?

Is below example valid?

#include <avr/power.h>

void setup() {}

void loop {

    /*
       here some jobs to do...
    */

    clock_prescale_set(clock_div_256); // downscale clock
    delay(200); // wait
    clock_prescale_set(clock_div_1); // restore clock
}


texts:
I'm working on a project using a set of different Arduino Nano connected to a Raspberry Pi through USB.
Now my question is: "how can I, from the Pi's point of view, differentiate all of those Arduino and associate them with their respective tty?"

I found some part of my answer in this question. The answering guy proposes to manually change the Arduino MODEL_ID when compiling and to use it afterwork to identify the device. The problem is that I don't know how to achieve that.

I tried to edit the boards.txt file to add a new board configuration with custom vid.x and pid.x (why all those 4 different values?) but after selecting my board and uploading, the MODEL_ID still stays the same:

ID_MODEL_FROM_DATABASE=HL-340 USB-Serial adapter
ID_MODEL_ID=7523

Can't I just specify somehow the USB_PID macro to the compiler command line?


texts: Where are the Arduino Function Unit Tests kept? I want to submit a fix for a faulty Arduino function

texts:
I have coded a fix for a major problem with the Arduino map function (in Arduino.h & arduino/avr/cores/arduino/WMath.cpp).
I submitted it as a comment to map function causes huge errors when mapping to small intervals due to integer truncation #10382 but heard nothing so far.
I thought it might be handled quicker if I can submit it as a Pull Request with Unit Tests to A) expose how and why map is faulty and B) show how my solution fixes the problem.


texts:
Help please

I am trying to connect an Arduino Due via a SPI bus to a MAXIM31855 thermocouple sensing chip. I am using Arduino IDE version 1.6.11.
The problem I am having is that the code will only read the SPI bus once, it will not loop, regardless of how many times I call the function to read the SPI bus.

I have connected the clock and the MISO to the pin header just below the SAM processor chip its labeled SPI and I have connected the CS to pin 4.

Each time I press the reset button on the Due, the SPI will read once. I have confirmed this by using a Salae logic analyser. The Due doesn't lock up as other functions continue normally, it simply will not repeat the SPI read.

The 4 bytes that are returned from the Max are consistent with the specification for the chip as are the timing of the clk (4kHz) and the MISO logic levels (there is no MOSI in this MAX chip).

If anyone has a clue as to why this will not loop I would appreciate their input.

Cheers

#include <SPI.h>
//Give convenient names to the control pins

#define slaveAPin 10
// set up the speed, data order and data mode
SPISettings settingsA(4000000, MSBFIRST, SPI_MODE1);

void setup() {

  Serial.begin(9600);
  pinMode(slaveAPin,OUTPUT);
  SPI.begin(slaveAPin);

}

uint8_t  val1, val2, val3, val4;

void loop() {
// read four bytes from device A
 Serial.println(ReadTemp());
 delay(1000);

 }

uint8_t ReadTemp(void)
{
  SPI.beginTransaction(settingsA);
  digitalWrite (slaveAPin, LOW);
  // reading only, so data sent does not matter
  val1 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val2 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val3 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val4 = SPI.transfer(slaveAPin,0x00,SPI_LAST);
  digitalWrite (slaveAPin, HIGH);
  SPI.endTransaction();

  return val2;

}


texts: Setting Up a JavaEE app on an Arduino Yun Board

texts:
I'm looking for some reference material to start on a project I'd like to do.

I have an Open House at my school. My group project has been to create a little timesheet app using JavaEE. I just started looking for how to do this and if I can. But I would like to wow people a bit by setting this up using an Arduino Yun board. I know it has WiFi and I'm pretty sure I can run Linux on the little guy.

Any help would be greatly appreciated.


texts: Using the Broadcom AFBR-S50 with Arduino

texts:
I'm trying to interface with a Broadcom AFBR-S50MV85G ToF sensor over SPI using an Arduino, which is complicated by the fact that the provided library and reference application is written for Cortex M0-based NXP microcontrollers. The documentation says that implementing the SPI, IRQ, Debug and Timer interfaces would allow use with other platforms, but it doesn't explicitly state which functions require implementations, or if all of them do, and it's not demarcated within the source code either.

The documentation lists the available command words, but no register addresses, which I believe are used by the platform-independent compiled libraries that come with it. This leaves me with no way to interface manually over SPI, meaning that my only choice appears to be to attempt to implement the platform drivers myself, which will probably take me a significant amount of time.

Is there something else I should try before sinking time into something that may not give me results? Has anyone here used this sensor before, and if so, could you point me in the right direction?

P.S.: The documentation I'm referring to is included in the SDK provided in the downloads section of the product page, and I'm not sure I'd be allowed to rehost it somewhere else in order to link it here.


texts: Is this a USBasp I can use with Arduino?

texts:
I bought the following USBasp off of Aliexpress.

The Arduino UDE doesn't recognize it. When I try to run avrdude with it, it says:

avrdude -cusbasp -Pusb -patmega328p
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor='www.fischl.de' product='USBasp'

Looking at the USB enumeration, it says:

USBHID:

  Product ID:   0xc8b4
  Vendor ID:    0x03eb  (Atmel Corporation)
  Version:  1.00
  Speed:    Up to 1.5 Mb/sec
  Manufacturer: zhifengsoft
  Location ID:  0x14200000 / 8
  Current Available (mA):   1000
  Current Required (mA):    100
  Extra Operating Current (mA): 0

Looking online, I see one blog post (http://www.sciencetronics.com/greenphotons/?p=938) about a device with the same VID/PID, and it says it can be reprogrammed but is not clear how to do it.

In particular, I know there is a jumper that I need to set to put it in self-programming mode but I can't figure out where to put this jumper. Once the jumper is in, I understand I just match the SPI pins and program it using the firmware.

Can someone help?


texts: Windows driver installer not detecting arduino

texts: I'm trying to program my Arduino Uno with my Windows PC. I followed all the instructions on the site. I mistakenly downloaded the .zip file and didn't unzip it, before plugging in my Arduino Uno. So naturally, no message came up. I then followed the correct procedure, but Windows driver installer does not detect the Arduino Uno. What can I do to fix this?


texts: What pins to use to externally power an Arduino Fio (without battery)

texts:
I need to power an enclosed Arduino Fio project with 12V. The intention is not to attach a battery because there is no need as this is a fixed installation with a 12V DC available (for a pair of relays which will be controlled by the Fio).

My question is what Pins should I use. The Fio page (https://www.arduino.cc/en/Main/ArduinoBoardFio) on the Arduino web site says...

Input Voltage   3.35 -12 V
Input Voltage for Charge    3.7 - 7 V

Unfortunately, there is no indication what pins these specs refer to. I assume that the "Input Voltage for Charge" refers to the mini-USB port and unlike other Arduino boards, there is no Vin pin to supply the board externally. Looking at the board layout on the same web page, I think the only possible option is via the two pins in parallel to the battery port which I suppose are then going into the voltage regulator on the board.

Any comments or suggestions? Has anyone done something similar?


texts: Minimum number of Pins to use for multiplexing LEDs

texts:
whats the minimum number of pins to use when multiplexing 6 LEDs?

is there some kind of formula that can be applied to n LEDs?

Or in other words, how many LEDs can an Arduino Uno control without the help of a separate IC?


texts: Use Female USB Type A as Power Supply for external device

texts: I bought a female USB Type A Breakout, like this (https://www.sparkfun.com/products/12700). I thought I could use this one to simply power a USB 5v water pump. Therefore I use an external USB power supply that is regulated by a relay, that I regulate with my Arduino. But I'm wondering if it is possible to get that USB Breakout to "give out" power to my water pump.


texts:
I am trying to understand the following code snippet from the Espressif OTABasic example for the ESP32 wireless/BT module (see this repository for the full code).

 ArduinoOTA
.onStart([]() {
  String type;
  if (ArduinoOTA.getCommand() == U_FLASH)
    type = "sketch";
  else // U_SPIFFS
    type = "filesystem";

  // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
  Serial.println("Start updating " + type);
})
.onEnd([]() {
  Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
  Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
  Serial.printf("Error[%u]: ", error);
  if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  else if (error == OTA_END_ERROR) Serial.println("End Failed");
});

The initial 'ArduinoOTA' looks kinda like an implied 'with ArduinoOTA' statement, but I can't find anything like that in the reference documents.  I know it has something to do with the way the function templates in 'ArduinoOTA.h', but it's beyond me to untangle the syntax.

May I buy a clue, please?

TIA,

Frank

Thanks to all for the clues; I'm an old-time c/c++ programmer, but must have slept through the 'lambda function' class ;-).

To help my somewhat calcified brain, is it functionally equivalent (if more clunky) to write the above snippet as shown below with the handler functions 'unchained'?

    ArduinoOTA.onStart
([]() //lambda function
    {
        String type;
        if (ArduinoOTA.getCommand() == U_FLASH)
            type = "sketch";
        else // U_SPIFFS
            type = "filesystem";

        // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
        Serial.println("Start updating " + type);
    }
);

ArduinoOTA.onEnd
([]() //lambda function
    {
        Serial.println("\nEnd");
    }
);

ArduinoOTA.onProgress
([](unsigned int progress, unsigned int total) //lambda func with arguments
    {
        Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    }
);

ArduinoOTA.onError
([](ota_error_t error) //lambda func with arguments
    {
        Serial.printf("Error[%u]: ", error);
        if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
        else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
        else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
        else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
        else if (error == OTA_END_ERROR) Serial.println("End Failed");
    }
);

TIA,

Frank


texts: Clion Arduino plugin: Error:Could not find Arduino SDK (set ARDUINO_SDK_PATH)

texts:
I am trying to setup CLion as my workspace for my arduino. I have installed the two Arduino plugins for CLion, generated a new sketch project, but I am getting cmake errors on opening the project.

CMake Error at /cygdrive/c/Users/user/project/cmake/ArduinoToolchain.cmake:86 (message):
  Could not find Arduino SDK (set ARDUINO_SDK_PATH)!
Call Stack (most recent call first):
  /cygdrive/c/Users/user/project/CMakeFiles/3.9.4/CMakeSystem.cmake:6 (include)
  /cygdrive/c/Users/user/project/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)

The issue is similar to this logged issue here:
https://github.com/francoiscampbell/CLionArduinoPlugin/issues/11

As a Windows 10 user, I have the Arduino SDK installed here: C:\Program Files (x86)\Arduino

What's interesting is that the cmake file is calling the UNIX commands when it's running in this if statement:

    if(UNIX)
        file(GLOB SDK_PATH_HINTS /usr/share/arduino*
            /opt/local/arduino*
            /opt/arduino*
            /usr/local/share/arduino*

                )
    elseif(WIN32)
        set(SDK_PATH_HINTS "C:\\Program Files\\Arduino"
            "C:\\Program Files (x86)\\Arduino\\libraries"
            )
    endif()


texts:
Background
I'm trying to write code to read signals from a six-channel RC receiver on an Arduino Mega 2560. Currently I am keeping the code to just read one channel to make things easy to troubleshoot. The problem is my shared variable is not updating, leading me to believe that my interrupt service routine is not detecting any rising edges.
I thought my receiver was broken, so I tested it using the standard Arduino attach interrupt function. It worked perfectly, so my receiver is fine.
I used Serial.print() to see if my volatile channel variable was updating (that is, change its value to the channel 1 flag value). It was not updating, so my ISR must be wrong. You can find the original code in the blog post.
What's wrong? I'm out of ideas.
#include <PinChangeInt.h>

//Pin assignment
#define channel1PIN 10

//Bit flags
#define Channel1FLAG 1

//Flag holder
volatile uint8_t bFLAGUPDATESHARED;

//Shared variables: Accessed by the interrupt service routine and read in 'void loop'.
volatile uint16_t unCHANNEL1SHARED;

//Start time variables: These are used to set the start time of the rising edge of
//a pulse. They are only accessed by the ISR, and thus they are unsigned integers and
//not volatiles.

uint32_t ulCHANNEL1START;

void setup()
{
  Serial.begin(9600);
  Serial.print("RC Channel PWM Read Interrupt Test");

  //PinChangInt library function. Used to set attach interrupts.
  PCintPort::attachInterrupt(channel1PIN, calcCHANNEL1, CHANGE);
}

void loop()
{
  //In-loop variables to hold local copies of channel inputs.
  //This is static so it retains values between call loops.
  static uint16_t unCHANNEL1IN;

  //The in-loop copy of the bSHAREDFLAGUPDATE volatile flag holder
  static uint8_t bFLAGUPDATELOCAL;

  //Check to see if any channels have received signals. If so, copy
  //shared variables to local in loop variables.
  if (bFLAGUPDATESHARED)
  {
    //Switch off interrupts when I copy shared variables to local variables
    noInterrupts();

    bFLAGUPDATELOCAL = bFLAGUPDATESHARED;

    if (bFLAGUPDATELOCAL & Channel1FLAG)
    {
      unCHANNEL1IN = unCHANNEL1SHARED;
    }

    bFLAGUPDATESHARED = 0;
    interrupts();
  }

  Serial.println(unCHANNEL1IN);

  //Clear local update flags copy as all values have been copied to local variables
  bFLAGUPDATELOCAL = 0;
}

void calcCHANNEL1()
{
  if (digitalRead(channel1PIN) == HIGH)
  {
    //If pin goes high, start timer and set ulCHANNEL1START to timer start
    ulCHANNEL1START = micros();
  }
  else
  {
    //If it is not rising, it must be falling so set shared
    //variable to current time-start time
    unCHANNEL1SHARED = (uint16_t)(micros() - ulCHANNEL1START);

    //Tell that channel 1 has received a signal
    bFLAGUPDATESHARED |= Channel1FLAG;
  }
}


texts:
I am attempting to increase the volume of a Max9744 20 watt amplifier from Adafruit using an Arduino sketch. I am just a very beginner and working with my grandson, this may be more than I am capable of doing.

Our project is to have music play when a sensor determines a door is opened.

I wonder if someone can help with this compile error.  I stripped the code of any code not related to issue - basically the sensor code.

Thanks in advance for any help you can provide.

exit status 1
'VS1053_CONTROL_SPI_SETTING' was not declared in this scope

Here is the code

#include <SPI.h>[code][/code]
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <Wire.h> // Amp Code

#define BREAKOUT_RESET 9 // VS1053 reset pin (output)
#define BREAKOUT_CS 10 // VS1053 chip select pin (output)
#define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin

#define MAX9744_I2CADDR 0x4B

int8_t thevol = 63; // I want Max Volume Always

Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

void setup() {
SD.begin(CARDCS);

Wire.begin();
if (! setvolume(thevol)) {
Serial.println("Failed to set volume, MAX9744 not found!");
while (1);
}
}

boolean setvolume(int8_t v) {
// cant be higher than 63 or lower than 0
if (v > 63) v = 63;
if (v < 0) v = 0;

Serial.print("Setting volume to ");
Serial.println(v);
Wire.beginTransmission(MAX9744_I2CADDR);
Wire.write(v);
if (Wire.endTransmission() == 0)
return true;
else
return false;
}
void Adafruit_VS1053::setVolume(uint8_t left, uint8_t right) {
uint16_t v;
v = left;
v <<= 8;
v |= right;

noInterrupts(); //cli();
sciWrite(VS1053_REG_VOLUME, v);
interrupts(); //sei();
}

void Adafruit_VS1053::sciWrite(uint8_t addr, uint16_t data) {
#ifdef SPI_HAS_TRANSACTION
if (useHardwareSPI) SPI.beginTransaction(VS1053_CONTROL_SPI_SETTING);
#endif
digitalWrite(_cs, LOW);
spiwrite(VS1053_SCI_WRITE);
spiwrite(addr);
spiwrite(data >> 8);
spiwrite(data & 0xFF);
digitalWrite(_cs, HIGH);
#ifdef SPI_HAS_TRANSACTION
if (useHardwareSPI) SPI.endTransaction();
#endif
}
void loop() {

while (counter < 3) {
musicPlayer.begin();
Serial.println(F("Playing track 001"));
musicPlayer.playFullFile("track001.mp3");
delay (100);
}

delay(1000);

musicPlayer.stopped();
}


texts: Issue with simple timer based on millis()

texts:
Sorry to bother but I am at my wits end. I'm experimenting with timers, and starting very simple. The following code is supposed to print the content of a variable each time an interval of time has passed, then update that variable. But for some reason I'm getting no output on the serial monitor.
I have used the serial monitor before on other projects without issue, so I'm not sure what the problem could be.
Is there any error in my code?
unsigned long previousMillis = 0;
unsigned long currentMillis = millis();
const long interval = 1000;

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

void loop() {
  if (currentMillis - previousMillis >= interval) {
    Serial.println(previousMillis);
    previousMillis = currentMillis;
  }
  else {
    ;
  }
}

//  previousMillis += interval;


texts: Help with school project (Arduino GSM and Thermal printer)

texts:
I'm with some friends from my school and we have started to do a project where we send an SMS text message to our Arduino UNO (with GSM module), which then print the text message on a thermal printer(tx, rx). we've got huge problems, and now we can not figure it out anymore.

We started making a machine that will print out a message that is sent from any mobile.So I send an SMS message with my mobile to Arduino connected to a GSM shield (SIM800L). Then sends the Arduino the message to the thermal printer via TX RX, and then the message should be printed out.

We have spent two examples, GSM shield from Arduino itself, and thermal printer example from SparkFun.

These two files work fine separately, but when we try to merge them together, there is a compilation error.

The printer model from Sparkfun.

code:

#include <GSM.h>
#include <SoftwareSerial.h>

#define PINNUMBER ""

//Printer
SoftwareSerial Thermal(6, 7);
//GSM modul
//SoftwareSerial GSM(4, 5);

int heatTime = 10;
int heatInterval = 2;
char printDensity = 15;
char printBreakTime = 15;

// initialize the library instances

GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];

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.println("SMS Messages Receiver");

// connection state
boolean notConnected = true;

 Thermal.println("GSM initialized");
 Thermal.println("Waiting for messages");
 }
 /*{
 Thermal.begin(19200); // to write to our new printer
 initPrinter();
 }
 */
void initPrinter()
{
 //Modify the print speed and heat
 Thermal.write(27);
 Thermal.write(55);
 Thermal.write(7); //Default 64 dots = 8*('7'+1)
 Thermal.write(heatTime); //Default 80 or 800us
 Thermal.write(heatInterval); //Default 2 or 20us
 //Modify the print density and timeout
 Thermal.write(18);
 Thermal.write(35);
 int printSetting = (printDensity<<4) | printBreakTime;
 Thermal.write(printSetting); //Combination of printDensity and     printBreakTime

 }
 void loop() {
 char c;

 // If there are any SMSs available()
  if (sms.available()) {
  Thermal.println("Message received from:");

// Get remote number
sms.remoteNumber(senderNumber, 20);
Thermal.println(senderNumber);

// An example of message disposal
// Any messages starting with # should be discarded
if (sms.peek() == '#') {
  Thermal.println("Discarded SMS");
  sms.flush();
}

// Read message bytes and print them
while (c = sms.read()) {
  Thermal.print(c);
}

}

delay(1000);

}


texts:
I am trying to program mBot using Arduino IDE. I am connected to the mBot using USB on COM7, I am able to upload a code created in mBlock 3.4.11 fine, using "Arduino Mode" as the editing mode. I would like to proceed to more complex coding now and for this I want to be able to edit the source code directly. The source code seen in the MBlock application seems to be read only, there is a button which should allow editing the code, called "Edit with Arduino". When I press this button, the Arduino IDE opens and I am able to edit the code. The trouble is I seem to be unable to send the code edited this way into the mBot.

When I use the Arduino IDE Sketch/Upload menu item, the code is compiled, but when sending it, I always get following error:

  avrdude: stk500v2_ReceiveMessage(): timeout

Note: I was editing and uploading Arduino code before with both Ardino IDE and VisualStudio visualMicro (now Arduino IDE for Visual Studio) without any issues.

I do not know exactly how is the mBlock application handling the upload, but while doing so a folder with the project is created, which contains the following buildprefs.txt - perhaps this could help to understand what it is doing:

build.arch = AVR
build.board = AVR_UNO
build.core = arduino
build.core.path = X:\Users\UserName\mblockExe\Arduino\hardware\arduino\avr\cores\arduino
build.extra_flags =
build.f_cpu = 16000000L
build.mcu = atmega328p
build.path = X:\Users\UserName\AppData\Local\Temp\build3998294614124133332.tmp
build.project_name = project_followLineAuto0_0.cpp
build.source.path = X:\Users\UserName\AppData\Roaming\com.makeblock.Scratch3.4.11\Local Store\scratchTemp\project_followLineAuto0_0
build.system.path = X:\Users\UserName\mblockExe\Arduino\hardware\arduino\avr\system
build.usb_flags = -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
build.usb_manufacturer = "Unknown"
build.variant = standard
build.variant.path = X:\Users\UserName\mblockExe\Arduino\hardware\arduino\avr\variants\standard
build.verbose = true
build.warn_data_percentage = 75
compiler.S.extra_flags =
compiler.S.flags = -c -g -x assembler-with-cpp
compiler.ar.cmd = avr-ar
compiler.ar.extra_flags =
compiler.ar.flags = rcs
compiler.c.cmd = avr-gcc
compiler.c.elf.cmd = avr-gcc
compiler.c.elf.extra_flags =
compiler.c.elf.flags = {compiler.warning_flags} -Os -Wl,--gc-sections
compiler.c.extra_flags =
compiler.c.flags = -c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD
compiler.cpp.cmd = avr-g++
compiler.cpp.extra_flags =
compiler.cpp.flags = -c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
compiler.elf2hex.cmd = avr-objcopy
compiler.elf2hex.extra_flags =
compiler.elf2hex.flags = -O ihex -R .eeprom
compiler.ldflags =
compiler.objcopy.cmd = avr-objcopy
compiler.objcopy.eep.extra_flags =
compiler.objcopy.eep.flags = -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.path = {runtime.tools.avr-gcc.path}/bin/
compiler.size.cmd = avr-size
compiler.warning_flags = -w
compiler.warning_flags.all = -Wall -Wextra
compiler.warning_flags.default =
compiler.warning_flags.more = -Wall
compiler.warning_flags.none = -w


texts: How to convert array of chars to array of ints?

texts:
I have a rather newbie question but I can't figure it out.

Lets say I have this char array:

char array[] = "10,11,12,1,0,1,0";

How can I convert it to an array of int like this?

int arrayINT[] = {10,11,12,1,0,1,0};


texts:
This is a part of my program which reads data from file stored in SD card and displays that on an LCD screen.

  File dataFile = SD.open("1165.txt");

  if (dataFile) {
    Serial.println("File Opened");
    lcd.clear();
       delay( 5 );  //LCD-specific M
       lcd.setCursor( 0,0 );

  while (dataFile.available()) {
      Serial.write(dataFile.read());
      lcd.write(dataFile.read());
      lcd.print(dataFile.read());
    }
  dataFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error");
  }

When I look at the serial monitor it prints the contents of that file but none of these commands print what is printed in the serial monitor,

lcd.write(dataFile.read());
lcd.print(dataFile.read());

Any ideas?


texts:
I'm trying to make a menu through serial monitor, but it always on a infinite loop... My question is where i call this function? On Setup or on Loop?

The menu:

  int controle_opera = 0;

  void menu() {

  int i = -1;
  do {
    char opcao = '\0';
    Serial.println("\nQual operação deseja realizar?");
    Serial.println("\n1 - Cadastro");
    Serial.println("\n2 - Validação");
    Serial.println("\n3 - Deletar");
    Serial.println("\n4 - Apagar database");
    if (Serial.available()) {opcao = Serial.read();}
    switch (opcao) {
      case '1': controle_opera++;
      i++;
      break;
      case '2': controle_opera += 2;
      i++;
      break;
      case '3': controle_opera += 3;
      i++;
      break;
      case '4': controle_opera += 4;
      i++;
      break;
      default: Serial.println("Opção desconhecida, tente novamente!");
              delay(100);
              break;
    }
  } while(i != 0);
}