texts: Are there any signal smoothing libraries for Arduino?

texts:
I am working on a mobile robot controlled via a wireless 2.4 GHz link.The receiver is connected to the Arduino Uno which serves onboard as the main controller. The most critical (and main) input channel coming from the receiver produces a very noisy signal, which leads to lots of minor changes in the output of the actuators, even though these are not needed.

                    Plot of the input of the Arduino in a 30 second interval.

I am looking for libraries that can perform efficient smoothing. Are there any signal smoothing libraries available for the Arduino (Uno)?


texts:
Does anybody know if there is any documentation available online on basic information about using displays with Arduino Uno? I've never used displays before and would very much appreciate some basic information on the different types etc..

Any information that can help me choose what display I want to buy for my next project will be helpful.

for ex: Right now I don't even know what a shield is in context to a display and whether or not I should look for one in my purchasing my display.


texts: Arduino Serial Monitor works but not on PySerial and PuTTY

texts:
I made simple custom arduino board using an atmega328p and the PL2303 serial to USB chip.

In my arduino program, I am in a loop that sends out a string continuously. I can read this in the Arduino serial monitor with a baudrate of 9600. However, in my python program using the pySerial library, the readline function doesn't return anything. I checked using PuTTY but it still doesn't do anything.

Now I tried messing with the serial settings and found out that these lines of code work (the readline returns the string) if I call it in the exact same order.

ser = serial.Serial(comm_port)
ser.xonxoff = True
ser.rtscts = True
ser.dsrdtr = True
ser.readline()

However, the code below doesn't work

ser = serial.Serial(comm_port, xonxoff=True, rtscts=True, dsrdtr=True)
ser.readline()

What could be causing this? My guess is somehow I've switched the datalines in my USB cable and that the arduino serial monitor handles this somehow.

Another thing to note is that I couldn't program the Arduino the normal way via USB. I always have to program it using the ICSP port and a USBasp programmer.


texts: Count RISING edges of a wave form by using ARDUINO

texts:
I have realised an electrical circuit that gives 5V in output. When I press a button, it gives 0V.
So I have in output a square wave (5V - 0V).
I would like to count how many times I press the button, by using an Arduino MEGA AT2560.
I have written this code below, but it doesn't work, because when I press the button, it increase the counter three or four times.
For example: I press the button 5 times, but the counter has arrived to 30!

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

unsigned int count_hall_f = 0;

void setup()
{
  Serial.begin(9600);
  attachInterrupt(0, interrFront, RISING); //18
}

void loop(){

}

void interrFront() {
  count_hall_f++;
  Serial.println(count_hall_f);
}

An example of the result is:

1 <- I pressed here
2
3 <- I pressed here
4
5
6
7
8
9
10
11
12 <- I pressed here
13
14
15
16


texts: H-bridge with 2N2222 transistors - input voltage is chopped

texts:
The H-bridge I put together works but not as expected unfortunately because the output voltage is limited to about 2.6V, regardless of the input voltage or resistors values.

I've already tried with 5V and 7.5V power supplies and nothing changed.

According to 2N2222's datasheet, Base-emitter Saturation Voltage (Vbe) is 2.6V and i have no idea if this is the problem or something with my setup.

Here's the 2N2222 datasheet: http://pdf.datasheetcatalog.com/datasheets/90/490358_DS.pdf


texts: Arduino String: use a non-null-terminated char array?

texts:
I'm using a library that takes a String as it's parameter (https://github.com/gmag11/painlessMesh)

I want to pass char arrays that is binary (UTF-8) data that also contains null-bytes (0x00). Right now, the resulting String is cut off at the first null-byte as expected. I know the full length of the char array, is it possible to construct an Arduino String while passing the arbitrary length, so that the full String also contains the null-bytes including the data that follows after, up until the pre-set length?

I had this problem before and then I solved it by converting the UTF-8 data to hex and then add a null-byte. I was hoping there is a more elegant way, since this forces me to double the data-size.

Thanks!


texts: Send HTTP request from Arduino Ethernet to server on PC

texts:
I am simply trying to send a simple HTTP request from an Arduino Uno with w5500 Ethernet Shield to a local server running on my PC.

The two are connected via a crossover ethernet cable and I am able to host a server on the Arduino that is accessible from my PC browser. Now I am trying to use the PC as a server and the Arduino as the client.

Using the simple WebClient example, I can send a successful GET request to google.com from the Arduino.

Here is what I am trying that is failing:

1 - Start a local server via running http-server in my command prompt. That successfully starts a server at 192.168.56.1:8080 that I can access via my browser

2 - Change the Web Client example to use

IPAddress server(192,168,56,1);

and change the port to

if (client.connect(server, 8080))

3 - Run this Arduino sketch. The connection fails and I don't know why. I have allowed port 8080 full input access through the Windows firewall.

Any ideas?


texts: Arduino emulator to create virtual 3d printer farm

texts:
I'm building a system to monitor several 3d printers, but I just have 1 printer. I'm thinking if there is any opensource tool to launch several virtual Arduino based boards running with Marlin firmware to accomplish my task. I'm planning to use Ocoprint for monitoring every board, so I need one serial port to communicate with the virtual printer.

I already modified the firmware in such a way that it runs on a clean ArduinoMEGA (without any shield) and it worked as I need.

I check the suggestions on this related thread but I'm not sure if any of them will work as I need.


texts:
I want to implement a function in another micro-controller which works like serial.available(). I don't know how it works. I read about Serial.available() in this link.

Whenever I write a string on the terminal, it prints the length of the string. Can anyone tell me how it works?


texts: how to calculate correct resistor value to use with LEDs Potentiometer and other devices?

texts:
I have been following http://arduino.cc/en/Tutorial/Fade to fade and LED. But I don't know why they are using a 220 Ohm resistor.
According to Ohms law if LED is of 2.2 V and it runs on 0.025Amps and is connected to 5V pin of Arduino then the resistor should be of 120 Ohms but why we are using 120 Ohm resistor ?
One more thing. How can I collect value of resistor to be used with different output and input devices ?

Thanks in advance


texts: Interfacing ESP8266 with Wi-Fi enabled GSM/GPRS Module

texts: I need to send Data over the internet from a location where there is no internet hot spot, but there is a mobile network coverage. I need a to interface my ESP8266 with some GPRS/GSM board, that has a Wi-Fi. Now generally I use my mobile, turn on the Mobile Hot spot, put the ssid and password in the ESP8266 code, compile and flash the code and the work starts. How can I achieve this with a GPRS/GSm board and which? SIM 800L does not support 3G or 4G. Any Help? Thanks


texts: 4 RFID with Arduino Uno / add or remove card with master card /

texts:
i am new in coding for arduino. I need some help with the project i'm working on. my project is a object tracking by using the rfid rc522 for inventory system. so i need to have multi reader in this project. i would like to have 4 reder that will work at the same time.
this is how i want my project to work:
1. there is going to be 3 or 4 reader rc522, 1 i2s lec and leds.
2. one rfid tag will be use as the master card. the master card have the ability to add or remove card.
3. when 1 tag is tapped on 1 reader, the card quantity at the reader that it tapped will increase. example when we tap the tag at reader1, reader1 will add 1 card into its memory.

https://github.com/TasmanianDevilYouTube/Arduino/blob/master/RFID_master_slave_cards/RFID_master_slave_cards.ino


texts: Is it possible to program an Attiny85 with a USB-to-TTL converter?

texts:
I currently use my Arduino to program Attiny85. As I have one of these USB-to-TTL adapters I am wondering if it is possible to program Attiny85 with it, to free up my Arduino. I know it is possible to program Atmega's with such a thing.

If it is in fact possible to use the converter as a simple programmer for Attiny's, how should I connect the converter to the Attiny?


texts:
I have an Arduino Uno and the I/O Shield wired up and I'm trying to switch (i.e. engage) a relay on the I/O Shield, but nothing seems to be working.

I've identified the input pins correctly and am able to send digital signals to it and it responds correctly. I also see the LED next to the relay light up when I do a digital write on the Arduino to a specific relay pin.

I'm starting to think that I might need to use an alternative power source or that I am not using the Arduino API correctly to switch the relay. At the moment I do a digitalWrite(13, HIGH), delay, and then do a digitalWrite(13, LOW) - pretty simple.

The shield is just powered by the Arduino at the moment, and I haven't been able to find where I might be able to plug in power, so I'm assuming the Arduino supplies it with all of the power it needs.

#include <Arduino.h>

int relayPin = 13;

void setup() {
    pinMode(relayPin, OUTPUT);
}

void loop() {
            digitalWrite(relayPin, HIGH);
        delay(5000);
        digitalWrite(relayPin, LOW);
        delay(5000);
}


texts: Choosing a proper power source for for basic RC car with 4 motors

texts:
Help me to choose a power source for the below project:

4x DC Motors (3V~6V DC each with ~170mA),
1x Micro Servo Motor (4.8V~6V),
1x Ultrasonic sensor
1x Bluetooth sensor

It is basically an RC car. The project runs on Arduino UNO and it uses Motor Shield (1.2) to power up those five motors. The motor shield does support external power supply. Shall I go for that, or Arduino can power up the entire system altogether?


texts: Software Serial and multiple shields for Arduino Uno

texts:
I have a SIM900 GPRS/GSM Shield (details here) and I am looking to stack a GPS shield (such as this one here).

My question is: I believe that they both require software serial, also it says to use software serial on D7 and D8 for both. Is this possible on an Uno?

I am a bit confused at if software serial has to have these two specific pins, or if these are just what is chosen on schematics?

What would be the most effective way to stack these two shields so they don't interfere with each other?

EDIT: Using a gps shield such as this gives the option  of

  If you need to move the software serial port pins, they can be custom-routed to any other pin by cutting the solder jumpers between pins GPS-RX and D8 and/or GPS-TX and D9.

This isn't entirely clear to me, but am I right in thinking it means I can have multiple software serials on my Uno, just using different pins?


texts: Can I make delayMicroseconds more accurate?

texts:
I'm trying to bit bang DMX data and that requires 4us pulses. Not having much luck with the results I'm checking to see how good the Arduino is at delaying... Seems to be pretty terrible at it.

Here's a quick little test I did:

unsigned long ptime;

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

void loop() {
  ptime = micros();
  delayMicroseconds(4);
  Serial.println(micros() - ptime);

  delay(1000); //just to keep the serial monitor from going nuts
}

And the results:

  8 4 8 4 4 4 4 4 8 8 8 8 4 8 8 4 4 8 4 4 4 8 8 8 4 8 4

I was kinda shocked at just how bad it's accuracy is. It's double the time I wanted to delay, but it's not even consistent to where I could just divide by 2!

Is there anything I can do to get correct, consistent results?


texts: Why do I get "invalid operands of types 'const char*'" error?

texts:
I am making an Arduino alarm. This is the error:

exit status 1
invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'

Here is the code that triggers it:

lcd.print("0"+hours+":"+minutes);

This code is similar, but worked before:

String none="00";
lcd.print(none+":"+none+":"+minutes);

I can post the full code if you need it. How can this be fixed?


texts: util/delay.h from arduino _delay_ms not delaying in accurate time with my hardware configuration

texts:
I have configured my arduino as a flash programmer and i'm sending data to an atmega328P. It is actually working and the data is send to my atmega328. But what is strange that the _delay_ms from  from the Arduino library is not delaying in accurate seconds.

_delay_ms(1000) who should wait from 1s, is actually more 8 seconds from my atmega328P hardware point of view.

My question is what could possibly turn the program wrong. I'm strongly assuming that this a misconfigured clock cycle from my Atmega, but this is my newbie guess,  it can be something else, that's why I'm posting my question here. Can someone can hint me what's wrong with my configuration?

Here's the sample code, a dumb toggle pin on / off:

#include <util/delay.h> // from arduino library

/*
*/

 DDRB |= 0b0000001;

  while (1) {
    PORTB = 0b00000001;
    _delay_ms(1000); // it should be 1 second, but on my hardware it is more ~8 seconds

    PORTB = 0b00000000;
    _delay_ms(1000);
  }

And my configuration is (from arduino IDE)

Arduino Pro / pro Mini (3,3v 8 Mhz) / Atmega 328

I have tried with

Arduino Pro / pro Mini (5v 16 Mhz) / Atmega 328

expecting that more power will affect speed, but the result is actually the same.


texts: The working of a MFRC522 and its Interface protocols?

texts:
I've actually messed up and posted into the stackoverflow site, even though I'm probably not meant to. I've been given this datasheet, but even though it does explain somewhat how each host interfaces works, it does not fully answer the questions I have at the moment and I probably don't even know what I'm doing in the first place, hence I'm giving this question another shot in the right place.

I've enrolled recently into a programming course, and one of the subject seems to be embedded software development revolving around an Arduino. Now, I'm tasked with explaining to the class how the MFRC522 works and where it might be applicable, but before all that, I probably am lacking the basic knowledge before I can proceed with my work.

I have here the image of the pinout from a MFRC522 and I have the following questions:

Theres UART, I2C and SPI. Are they all separate communication protocols or are they all involved somehow with each other on this device? If I plan to use only UART for example, is it possible that I just only use the RX and TX?
Are there restrictions as to which pins on the Arduino or the MFRC522 I could possibly use, depending on the protocol or circumstances? I can see in the datasheet the pins D1 to D7 being referenced, but I cannot find it anywhere on the MFRC522 itself.
In case they are separate protocols, I would like to know how each protocol is applicable for this specific device? Like a general idea as to why a protocol is suited for a certain every day device we have been using.
The device itself uses only 3.3V, but is it also 5V resistant? Like, will plugging it into a 5V fry the circuit board or will it work just as fine?

Thanks everyone for your time.


texts:
I'm building  an application that uses 20 servo motors, and i control then with an Arduino Mega. The servos are having some instability, to the point where they make small random swings. Im powering then from a 7.4V LiPo battery and I drop the voltage to around 6V with 2 series diodes. I've made some research and found 4 things that may help stabilize the servos.

Put a 1000uF eletrolitic capacitor between the battery VCC and GND pins.
Put a 470uF eletrolitic capacitor between each servo VCC and GND pins.
Put a 100nF ceramic capacitor between each servo SIGNAL and GND pins.
Put a 10k pull-up resistor on each servo SIGNAL pin.

My question is, how to make the right decision here. It is better for the project if I take all this designs into account, or I shouldn't be making some combination of this, or one in particular?


texts: How can I assign a variable to a function output in Arduino?

texts:
I'm trying to assign the output of my function (which adjusts a DAC output) to a variable so I can print and display it in my serial monitor. Here's the code

#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

int volza;

void setup() {
  Serial.begin(38400);
  Serial.println("Hello!");
  dac.begin(0x60);
}

void loop() {
    volza = dac.setVoltage(1095, 1); // THIS IS THE PROBLEM
    Serial.println(volza);
}

I am receiving an error because of the commented line. I think it's because I am trying to return a value while inside a void loop. How do you fix this?


texts:
I am trying to setup waveshare 7.5 display (Waveshare_7_5) with esp32 e-paper driver using ESP32-e-Paper-Weather-Display
My code is here https://pastebin.com/raw/2zQDe9a9, have corresponding owm_credentials.h, installed GxEPD2 & U8g2_for_Adafruit_GFX
Code gets uploaded to esp32 driver board using Arduino IDE, but Getting following in serial monitor & no display on e-paper
Busy Timeout!
Busy Timeout!
Busy Timeout!
Busy Timeout!
Entering 1675-secs of sleep time
Awake for : 44.518-secs
Starting deep-sleep period...

What is wrong here ?


texts: Is this example for playing music without delay correct?

texts:
I've followed the directions from this answer, to try and play music without delay. This is my code so far:

#include "pitches.h"

int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

const int tonePin = 4;
unsigned long previousMillis = 0;
int counter = 0;
int numberOfNotes = sizeof(melody)/sizeof(int);
boolean outputTone = false;

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

void loop() {
  unsigned long currentMillis = millis();
  unsigned long noteDuration = 1000 / noteDurations[counter];
  unsigned long pauseBetweenNotes = noteDuration * 1.30;

  if (counter < numberOfNotes) {
    if (outputTone && ((currentMillis - previousMillis) >= noteDuration)) {
        previousMillis = currentMillis;
        noTone(tonePin);
        outputTone = false;
        counter++;
    }
    else {
        if ((currentMillis - previousMillis) >= pauseBetweenNotes) {
        previousMillis = currentMillis;
        Serial.println(melody[counter]);

        if (melody[counter] == 0) {
          noTone(tonePin);
        } else {
          tone(tonePin, melody[counter]);
        }

        outputTone = true;
      }
    }
  }
}

pitches.h can be found here.

So with this code, the music plays, but slower. The pauses between notes seem longer, and I can't figure out why.

Also, I'm not sure where should I increment my notes counter.


texts:
I am new to coding and this website so I apologize if I make any mistakes. I am trying to get servos to move when a random number is generated. Like if I roll a 2 I want servos 1, 2 and 3 to open and then if I roll a 3 after I want servos 4, 5 and 6 to open. I am able to hold the previous values in the code now but can't get the servos to go with it. Any help is great! Thanks!

#include <Servo.h>

Servo myservo;

int pos = 0;    // variable to store the servo     position
int x = 0;
int button = 8;
int BUTTON;
int randomNumber;
int xPrevious = 0;
int oldNumber;

void setup() {
pinMode(button, INPUT);
Serial.begin(9600);
}

void loop() {

BUTTON = digitalRead(button);
Serial.println(BUTTON);
 if(BUTTON == LOW){
  randomNumber = random(1,4);
  delay(275);
  Serial.print("Random Number ");
 Serial.println(randomNumber);
 if( xPrevious == 0) {
   randomNumber = randomNumber + 1;
 }

  // Only want it to do this on the first roll.
     xPrevious = randomNumber + xPrevious;
     Serial.print("xPrevious ");
     Serial.println(xPrevious);
    oldNumber = xPrevious;

 for (x = randomNumber; x <= xPrevious; x += 1) {
  myservo.attach(x);
  Serial.println(x);

  for (pos = 0; pos <= 180; pos += 1) { // goes     from 0 degrees to 180     degrees
 //in steps of 1 degree
    myservo.write(pos);              // tell servo to go   to position in variable 'pos'
    delay(15);                       // waits 15ms for the     servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes  from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go    to position in variable 'pos'
    delay(15);                       // waits 15ms for the  servo to reach the position
  }

 }
 }
 }


texts: activate a relay with two esp8266 -12e pins

texts:
I have an esp8266-12e that I want to activate the reset side of a latching relay.  The problem is that the 12e only puts out 12mA/pin and the relay needs more than that.  I am using a transistor on the set side from a rf antenna signal.  I only have one 3.3v power source.  Is there a way to have two pins go HIGH at the exact same time and be connected to the reset side of the relay so there is enough current?  Would this work, would it hurt anything, and how would I write the code for it and how would I wire it up?

I have tried the code where one pin is written HIGH right after the other like this

digitalWrite (5,HIGH);
digital Write (6,HIGH);

but I think pin 5 goes of before pin 6.
Any way to get them to go off at the same time?

Thanks for the help


texts: sprintf() to assemble String and float pieces locks up

texts:
I'm trying to parse many variables into a URL so that I can update a website through a simple HTTP API with sensor data. After talking to a buddy of mine, he suggested going with the code below.

When I put this in, the Arduino Yun boots up. I see the L13 red LED turn on, but then it hoses. When I comment out the sprintf(); line, everything works fine — except no URL is parsed.

I've tried to debug to the best of my ability and am looking for thoughts on what may be happening.

I'm not sure how much code to post without posting the whole 130 line sketch, so I'm just dumping the parts from the loop that is trying to piece together the URL.

  // Get update time
  Process date;
  date.runShellCommand("date --utc \"+%Y-%m-%d%%20%H:%M:%S\"");
  String utcDateString = "";
  while (date.available()) {
    char d = date.read();
    utcDateString += d;
  }

      char url[512];
      url[0]='\0';
      float humid, baro, windspeed, raingauge;
      int winddir;
      Serial.print("humid: ");
      Serial.println(humid);
        Serial.print("baro: ");
      Serial.println(baro);
        Serial.print("windspeed: ");
      Serial.println(windspeed);
        Serial.print("raingauge: ");
      Serial.println(raingauge);
        Serial.print("winddir: ");
      Serial.println(winddir);
 //sprintf(url,"http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID=123456&PASSWORD=xxxxxx&dateutc=%s&temp=%2.2f&humidity=%2.2f&baromin=%f&winddir=%d&windspeedmph=%3.2f&rainin=%3.2f&softwaretype=Custom%%20Arduino&action=updateraw",
//         utcDateString,Thermistor(analogRead(0)),humid,baro,winddir,windspeed,raingauge);
        Serial.print("url: ");
      Serial.println(url);

double Thermistor(int RawADC) {
  double Temp;
  Temp = log(11100.0/((1024.0/RawADC-1)));  // Was 10000... Manually dialed down to increase accuracy. 9400 is a good value. Changing again to match wunderground
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius
  Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  return Temp;
}

Here's the output from those Serial.print() calls:

humid: 0.00
baro: 0.00
windspeed: 0.00
raingauge: 0.00
winddir: 0
url:

I'm not sure how else to debug this because when I uncomment sprintf(); the Yun locks up and I have to press the 32U4 Reset button and power cycle the Arduino to get it to work again.


texts: Can an accelerometer be used to detect heart sound?

texts: I've recently come across accelerometer and how it can detect electrical mechanical response. I was wondering can it be used to detect heart sound? Lets say you attach the device close to your chest (where heat lies) and detect sounds and send it over bluetooth? LPMS-B2 OEM


texts:
I plan to buy these 2 products to begin to play with arduino to learn.

Board with LCD touch
Yun board expansion

I have a mega 2560 which i bought with a starter kit and i love to play with. I have not played with the shield yet. I understand some shields can be used together, some not. and some with modification on the board and in the code.

I can't find pins specification for the touch screen and the support on the website doesn't respond.

If some one can help me find specifications for the touch screen, or help me choose some shields that will allow me to use a USB host, wifi, and a touchscreen it will be nice.

Thanks all.


texts: Extracting a substring from original string

texts:
I am trying to extract a substring out of another string, but it doesn't seem to be working. I am new to programming in arduino and c++ in general. Here is my code:

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

char rfid;

void loop()
{
  while (Serial.available() > 0)
  {
    rfid = Serial.read();
    String cardnum(rfid);
    cardnum.replace("", "");
    cardnum.replace("", "");
    String id = cardnum.substring(0,2);
    Serial.print(id);
  }
}

The first argument in cardnum.replace("", ""); and cardnum.replace("", ""); replaces the start and end bit with nothing, but it somehow doesn't display it correctly here.
Now on to the problem at hand. The output for cardnum is 1F006B471F2C which it should be, but the ouput for id is the same, when i want it to be only the first two characters of cardnum. How would i go about achieving that.
Thanks in advance for any answers you can provide.


texts: Lighted geofenced dog collar project help needed

texts:
I have a project that I would like to make for Christmas and while I have never worked with Arduino before I am hoping people here can point me in the right direction.

I currently have two dogs that like to go out at night a lot. Currently I clip a small LED to their collars when they go out so I can see where they are.

I would like to automate this process by setting up an Arduino system to turn the dog collar lights on and off based on some type of geofencing (either connecting/disconnecting from wifi or bluetooth etc).

I was thinking I would do the following:

Get the smallest Arduino with Wifi.
Write a program that triggers a relay for onConnect? and onDisconnect? events.
Buy a lighted dog collar like this, sew the Arduino into it and hook the relay into the circuit.

What would be really helpful from the group is to know what to buy, and any reference projects that might be helpful on my way. I am a software engineer so I would prefer to stay away from as much custom hardware as possible and get the smallest setup possible for the project pre-made so I can just focus on software.

I am hoping to spend less than $25 per device, but I would pay more for smaller devices.

Thanks all!


texts: How do I properly receive MIDI with Arduino, with 6n138?

texts:
UPDATE : I still can't receive MIDI as of 2019/07/01.

Here goes so far : I'm trying to follow this schematics from instructables, using 6N138. To make it easier, I'm going to copy his schematics.

===================================

I'm using Arduino Mega. I tried to find specific topic about this and can't find any.

The target is actually send and receive MIDI, then replace the whole Arduino Mega to ESP8266 (probably the ESP-01, or Wemos D1), but I'm afraid it is too specific.

Here's the code so far on PasteBin

Here's my work so far.

The diodes were replaced with LED, because I don't have one Original guide here.
But that schematics on that thread also didn't work for some reason.


texts: Lowest latency triggering multiple Arduinos using NRF24L01+

texts:
I'm building a rig with multiple DSLR cameras.  I need to synchronize the cameras to take a photos with lowest possible latency.  The only constraint is we want the ability to address each camera individually if needed.

I've seen in other posts:
Choosing wireless tech for lowest possible lag

NRF24L01+ seems to be a good choice.  An answer on that post states:
sending a 32 byte payload...283µs on 2Mbps mode.

Given the  esp8266 has a clock speed of 80MHz/160MHz I'm not too concerned about the lag involved in processing the signals.

Most multi-cast information out there is for sensor arrays, so multiple out single in.  I'm after resources on single out multiple in for NRF24L01+ networks.

Added bonus of esp8266 is that non timing critical tasks such as logging and error checking could be performed over wifi so NRF24L01+ would be purely for one -way triggering.

If each camera had it's own esp8266 based board with attached NRF24L01+ hardware and was given an address in software from 0-255, is it possible to broadcast a single 32 byte packet of data where each bit would represent a camera address and have all receiver devices receive the same signal, do an AND against it's address and trigger if needed?


texts: I need a simple, low power, low cost wireless switch to transmit to Arduino

texts: I'm looking for a very simple wireless, low-power, low-cost switch that can transmit a signal to an Arduino. Ideally, each transmitter would have a signature. For instance, let's say I had 4 different transmitters that are attached to a sensor. When the sensor is tripped, I want to wirelessly send a signal to the Arduino. I've looked at these 433 MHz modules, but it seems like they would also need a microcontroller to send the data, while that's a possible solution, I'm wondering if there is a even smaller, simpler solution.


texts: MPU6050/DMP Intermittent bad data output?

texts:
I have a DFRobots MPU6050 module wired to SCL/SDA/Pin 2 on a Mega 2560 board, using Jeff Rowberg's I2CDev/MPU6050_6Axis_MotionApps libraries.  I have 2.2K pullups on the MPU6050 module, tied to +5V, as shown in the following photo.

I used a modified version of the code from Jeff's example to retrieve heading values from the MPU6050, as shown below

bool GetIMUHeadingDeg() //08/28/18 chg to bool return

{

//Purpose:  Encapsulate everything needed to acquire a yaw value
//Inputs:
//  global_yawval = float variable defined at global scope
//  fifocount = uint8_t variable defined at global scope
//  packetsize = uint8_t variable defined at global scope
//  mpuIntStatus = uint8_t variable defined at global scope
//  whilecount = long variable defined at global scope
//  resetcount = int variable defined at global scope
//Outputs:
//  global_yawval filled with latest yaw value from sensor
//  true = success, false = failure
//Notes:
//  08/13/18 now returns global_yawval to calling routine
//  08/28/18 chg return to bool so can return success/failure

// if programming failed, don't try to do anything
//if (!dmpReady) return;
//if (!dmpReady) false;

bool result = false; //added 01/16/19 to supress warnings

// wait for MPU interrupt or extra packet(s) available
while (!mpuInterrupt && fifoCount < DMPpacketSize)
{
    whilecount++;
    delay(10);
    delay(10);

    if (mpuInterrupt)
    {
        fifoCount = mpu.getFIFOCount();
        mySerial.printf("%ld\t%d\n", whilecount, fifoCount);
        whilecount = 0;
        break;
    }
}

// reset interrupt flag and get INT_STATUS byte
mpuIntStatus = mpu.getIntStatus();
mpuInterrupt = false;

// get current FIFO count
fifoCount = mpu.getFIFOCount();

// check for overflow (this should never happen unless our code is too inefficient)
if ((mpuIntStatus & 0x10) || fifoCount == 1024)//0x10 is mask for MPU6050_INTERRUPT_FIFO_OFLOW_BIT
{
    // reset so we can continue cleanly
    mpu.resetFIFO();
    Serial.println(F("FIFO overflow!"));
    result = false; //added 01/16/19 to supress warnings

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
}
else if (mpuIntStatus & 0x02)//0x02 is mask for MPU6050_INTERRUPT_DMP_INT_BIT
{
    // wait for correct available data length, should be a VERY short wait
    while (fifoCount < DMPpacketSize)
    {
        fifoCount = mpu.getFIFOCount();
        //mySerial.printf("fifo count = %d\n", fifoCount);
    }

    //07/08/18 added to watch for non-modulo FIFO counts
    if (fifoCount == 0 || fifoCount % DMPpacketSize != 0)
    {
        mpu.resetFIFO();
        FIFO_resetcount++;
    }
    else
    {
        //07/07/18 modified to read all outstanding packets
        // read a packet from FIFO
        while (fifoCount >= DMPpacketSize)
        {
            //mySerial.printf("fifo count = %d\n", fifoCount);
            mpu.getFIFOBytes(fifoBuffer, DMPpacketSize);
            fifoCount -= DMPpacketSize;
        }

        // display Euler angles in degrees
        mpu.dmpGetQuaternion(&q, fifoBuffer);
        mpu.dmpGetGravity(&gravity, &q);
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

        global_yawval = ypr[0] * 180 / M_PI;
        result = true; //added 01/16/19 to supress warnings
    }

    ////DEBUG!!
    //      mySerial.printf("yawdeg = %4.2f\n", global_yawval);
    //      mySerial.printf("time = %ld\tyawdeg = %6.2f\n", millis(), global_yawval);
    ////DEBUG!!
}

return result; //added 01/16/19 to surpress warnings

}

I have noticed occasional bad data points in the computed Heading values retrieved from the MPU6050, as shown in the attached plot. Any ideas what I can do about this?  Is bad value detection/removal an expected issue when dealing with IMU products like the MPU6050?

As an experiment, I excluded all points for which the rotation rate was unrealistically high, resulting in the 'Adj Hdg' line (gray line) in the plot below.  This (mostly) works, except for one instance where there were two bad values in a row.

TIA,

Frank


texts: Why does opening the Tools menu take so long?

texts:
Every time I open the Tools menu, the IDE freezes for a few seconds. Why is that? It happens on both of my computers, and nothing I do makes a difference in how long it takes. I've tried restarting the IDE, unplugging my Uno, and many other things, but nothing helps.

I'm on windows, running IDE version 1.0.2.


texts: Is there any way to connect my old phone camera with an arduino?

texts:
I have an esp8266 wifi module, arduino uno and an old mobile. I was wondering if there is any way by which i could remove the camera from the mobile and connect it with my arduino in order to view video captured by the camera.
Is this possible by the hardware which i currently have? Or i will have to buy more hardware?
Please let me know if more information is required also give the link of helpful articles.


texts: Will enabling parity bit actually decrease corruption?

texts:
I have an Arduino Mega communicating with a Bluetooth adapter through one of the auxiliary hardware serial ports. It works, but there appears to be a corruption rate of approximately 1 in 200 small packets. In other words, about 0.5% of the packets are being corrupted, it seems. I have the option of configuring the serial mode on both ends. While I cannot decrease the baud rate for bandwidth reasons, I do have enough room to enable parity or a larger stop bit if that would help.

Granted the corruption is on the serial line and not on the Bluetooth, if I enable parity, will this actually decrease the corruption rate? Or will the corrupt bytes simply be dropped without being re-sent? In other words, what happens when the hardware detects a bad byte?


texts: BLE Mate 2 bluetooth module to Arduino Uno without FTDI SmartBasic

texts:
So I'm trying to hook up this BLE breakout board to an Arduino Uno. SparkFun has a hookup guide which seems to be great for someone who has an FTDI SmartBasic that is mentioned in the article. I don't have the SmartBasic board, and would like to see if this is possible without it.

I have hooked up the board to my Uno with the following pinouts:

GRN -> Reset
RXI -> RX (tried with TX as well)
TXI -> TX (tried with RX as well)
VIN -> Tried 5V and 3.3V
CTS -> GND
BLK -> (No Connection)

I use their example code they have provided, uploaded without the RX and TX pins hooked up because, from what I notice, you cannot upload a program through the USB serial when these ports are in use. So after I upload the program through USB, I power the board with a battery and connect the RX and TX pins to the BLE board.

Has anyone either successfully hooked these up without the use of a SmartBasic? I'm a programmer by trade so I do my best to understand this side of the spectrum.


texts: digital input pins on arduino nano with standard firmata and pyfirmata are always 'None'

texts:
I have connected pin D2 on my arduino nano to high, and tried it out with an arduino c program and it works.  However, when I load standard firmata onto the the controller from the arduino IDE and try the following python program:
import pyfirmata

board = pyfirmata.Arduino('/dev/ttyUSB0')

for x in range(2,14):
    print("%s %s" % (x, board.get_pin("d:%s:i" % x).read()))

I get this:
$ venv/bin/python test.py
2 None
3 None
4 None
5 None
6 None
7 None
8 None
9 None
10 None
11 None
12 None
13 None

I can write digital pins with fermata and pyfirmata, but I can't read.
I have also tried this:
import pyfirmata

board.digital[2].mode = pyfirmata.INPUT
board.digital[3].mode = pyfirmata.INPUT

for x in range(2,14):
    print("%s %s" % (x, board.digital[x].read()))

and other combinations, and always get None
(disconnecting the wire in the picture doesn't change anything either)

I have also just repeated the experiment with an arduino uno and get the same result

so I guess my questions are:

Can anybody spot anything obvious that I am doing wrong?
Can anybody confirm that pyfirmata input ever works?
What did you do that I am not doing?


texts: Connect three android to one arduino mega

texts:
Android Arduino Mega SerialPort1 SerialPort2 SerialPort3

Is it possible to connect three Android tablets to the Arduino mega through three SerialPort? Rx1 Tx1; Rx2 Tx2; Rx3 Tx3

I managed to connect only one device directly through the cable, but this is only one device.


texts: Why Arduino Severino (S3V3) sometimes needs reseting when uploading a sketch?

texts:
I have an original Arduino UNO R3 that I bought and an Arduino Severino (S3V3) that I've built.

I have no problems uploading sketches to the UNO, but sometimes, when uploading to the Severino board, I have to hard reset it at a specific time during the upload process, when the IDE says something like this below:

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM1
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]

If I don't reset it when one of the Send messages are being displayed, I get the not in sync message, as below:

avrdude: Recv:
avrdude: stk500_getsync(): not in sync: resp=0x00

Other times, if I'm lucky, I can upload to the Severino board without having to reset it.

So, my questions are:

Why does that happen? Why Severino needs a hard reset during upload?
Why is the problem intermitent? Why does it happen sometimes and others it doesn't?
How can I fix that problem? Is there a simple change to the Severino design that would fix that?


texts: Connecting two analog multiplexers (CD4051b)

texts: Is it possible to connect two CD4051b analog multiplexers together so that I can receive 14 analog inputs through  them? Just by using one analog pin and three digital pins on the Arduino UNO.


texts: Printing the messages having problem in SIM 900A to Arduino

texts:
I have added my Arduino code for reading messages from GSM SIM900A using Arduino. But the output is showing something different. Please help me.

#define SERIAL_BUFFER_SIZE 256

char msg;
void setup() {
  Serial.begin(9600);   // Setting the baud rate of GSM Module
  delay(60000);
  Serial.println("AT");
  delay(1000);
  Serial.println("AT+CREG=1");
  delay(1000);
  Serial.println("AT+CMGF=1"); // set SMS mode to text
  delay(1000);
  Serial.println("AT+CMGR=\"ALL\"");
  delay(1000);
  Serial.println("AT+CMGR=\"ALL\"");
  delay(1000);
  while ( Serial.available() > 0) Serial.read();  // removing serial buffer values
  Serial.println("AT+CMGR=1");
  delay(2000);
}

void loop() {
  while (Serial.available() > 0) {
    msg = serial.read()
    Serial.print(msg);
  }
}

This is the output:

+CMGR: "REC READ","+91xxxxxxxxxx","","16/07


texts: How can I make a garage door laser sensor?

texts:
I would like to make a sensor that detects when my car is clear of a certain point. So, when backing in my car to my garage, I would have a beam and sensor. When the beam is broken, an LED light would turn on and then when the beam gets through, the light turns off and I know that the car will clear the garage door.

I am pretty sure I have to use either an Arduino or Raspberry Pi, but I'm completely new to home automation. There are a few other things I'd like to do but this is a good starter.

I don't know where to start.


texts: How to map integer values and round to a count of tens/thousands?

texts:
I'm mapping a potentiometer from 0-1023 to 1000-120000 (1 sec to 2 minutes) for a timer, like:

maxDelay = map (pot2, 0, 1023, 1000, 120000);

Both variables are integers. Now I would like to convert/round values to counts of 10 seconds (a count of thousands), so if I have anything from 1001-5000 this would be rounded to 1000 (1sec), and if I have 5001-10000 it would be rounded to 10000 (10 secs), then 20sec, 30sec, etc...until it reaches 120secs. I know I could have a few "if" statements but I'm trying to figure out the right way of doing these maths. Thanks.


texts: Why the MPU6050 gyroscope read write register value is 0x08 for a full scale of 500 degrees per second?

texts:
I am trying to connect a gyroscope MPU6050 to arduino ATmega2560 and read its raw values from its 6DOF (gyro and acc).

I found the following code:

//Activate the MPU-6050
  Wire.beginTransmission(0x68);                                        //Start communicating with the MPU-6050
  Wire.write(0x6B);                                                    //Send the requested starting register
  Wire.write(0x00);                                                    //Set the requested starting register
  Wire.endTransmission();                                              //End the transmission
  //Configure the accelerometer (+/-8g)
  Wire.beginTransmission(0x68);                                        //Start communicating with the MPU-6050
  Wire.write(0x1C);                                                    //Send the requested starting register
  Wire.write(0x10);                                                    //Set the requested starting register
  Wire.endTransmission();                                              //End the transmission
  //Configure the gyro (500dps full scale)
  Wire.beginTransmission(0x68);                                        //Start communicating with the MPU-6050
  Wire.write(0x1B);                                                    //Send the requested starting register
  Wire.write(0x08);                                                    //Set the requested starting register
  Wire.endTransmission();                                              //End the transmission

I am trying to break it line by line, to understand what is going on during the setup of the gyroscope.

According to MPU6050 datasheet, the I2C is at the register 0x68. The I2C helps us to access all registers and communicate with the master connected to. Which gives the following 3 lines:

Wire.beginTransmission(0x68);
Wire.write(0x6B);
Wire.write(0x00);

According the the sheet, the 0x6B is the register designed to enable and disable the gyroscope:

  This register allows the user to configure the power mode and clock
  source. It also provides a bit for resetting the entire device, and a
  bit for disabling the temperature sensor. By setting SLEEP to 1, the
  MPU-60X0 can be put into low power sleep mode. When CYCLE is set to 1
  while SLEEP is disabled, the MPU-60X0 will be put into Cycle Mode. In
  Cycle Mode, the device cycles between sleep mode and waking up to take
  a single sample of data from accelerometer at a rate determined by
  LP_WAKE_CTRL (register 108). To configure the wake frequency, use
  LP_WAKE_CTRL within the Power Management 2 register (Register 108). An
  internal 8MHz oscillator, gyroscope based clock, or external sources
  can be selected as the MPU-60X0 clock source. When the internal 8 MHz
  oscillator or an external source is chosen as the clock source, the
  MPU-60X0 can operate in low power modes with the gyroscopes disabled.
  Upon power up, the MPU-60X0 clock source defaults to the internal
  oscillator. However, it is highly recommended that the device be
  configured to use one of the gyroscopes (or an external clock source)
  as the clock reference for improved stability. The clock source can be
  selected according to the following table.

So why we set its value to 0x00 ?

And the same for setting up the gyroscope at register 0x1B where datasheets specify the full scale ranges as:

The code is setting the range of 500 dps, so why the coder set the register to 0x08 and not 0x01 where the FS_SEL[1:0] should contain decimals from 0 to 3 right ?


texts: I2C communication between arduino and raspberry pi breaks under stress for unclear reasons. Why?

texts:
I am having a behavior I cannot explain while using arduino mega as a I2C slave for a raspberry pi master.

I am showing here an idealised program that shows the issue. I experience pretty much the same behavior in the real application (a keyboard firmware). What I am doing is the following:

the arduino issues an interrupt on pin 23 at evert loop to inform the raspi that there's some data to be read.
the raspi sends a request as master to the arduino.
arduino receives the request in the Wire handler, and issues a reply of 32 bytes. I fill these 32 bytes with a uint8 counter just as a check.
the cycle starts again.

This is the code for the raspi

import time
import RPi.GPIO as GPIO
import smbus

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

bus = smbus.SMBus(1)
address = 0x42

def callback(channel):
    data = bus.read_i2c_block_data(address, 0x00, 32)
    print(data)

GPIO.add_event_detect(4, GPIO.RISING, callback=callback)

while True:
    time.sleep(1)

GPIO.cleanup()

and this is the code of the arduino

#include <Wire.h>

byte IRQ_PIN = 23;

volatile unsigned int counter;

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

    pinMode(IRQ_PIN, OUTPUT);
    digitalWrite(IRQ_PIN, LOW);
    Wire.begin(0x42);
    Wire.onRequest(requestEvent);
    Wire.onReceive(receiveData);

}

void signalMaster() {
  noInterrupts();
  irq();
  interrupts();
}

void irq() {
  digitalWrite(IRQ_PIN, HIGH);
  digitalWrite(IRQ_PIN, LOW);
}

void requestEvent() {
  byte buf[32];
  counter++;
  memset(buf, counter, 32*sizeof(byte));
  Wire.write(buf, 32);
}

void receiveData(int byteCount){
  while(Wire.available()) {
    Wire.read();
  }
}

void loop() {
  signalMaster();
  delay(1);
}

As you can see, the point is that I am banging the I2C really, really fast, and the loop is very tight and fast. This is the point of the exercise and the problem to solve arises from this.

Now, once in a while I get an occasional IO error with the raspi python code. This code occasionally fails once, and then everything resumes to normal, but once in a while, it completely breaks down and never recover.

I attached a logic analyser to it, and this is what I found. D3 is the interrupt pin. The others the I2C bus. In a normal transaction, I can see everything working properly (disregard the different content of the response, it was an earlier run)

and a zoom in to the master request and the reply:

When I have a permanent failure, however, the picture is very different

Zoom in:

This makes little sense to me. Why would it perform a data write, and who is writing 0x85FF... in my buffer?

Thanks


texts:
I'm trying to get data from a heat counter via the serial, the format of the response is:

t1=ХХХ.ХХ   t2=ХХХ.ХХ   t3=ХХХ.ХХ   t4=ХХХ.ХХ
P1=ХХ.ХХ    P2=ХХ.ХХ
VolSpd1=ХХ.ХХХ  VolSpd2=ХХ.ХХХ
MassSpd1=ХХ.ХХХ MassSpd2=ХХ.ХХХ
HeatSpd1=Х.ХХХ  HeatSpd2=Х.ХХХ
SumVolume1=Х.ХХХХХХХ    SumVolume2=Х.ХХХХХХХ
SumMass1=Х.ХХХХХХХ  SumMass2=Х.ХХХХХХХ
SumHeat1=Х.ХХХХХХХ  SumHeat2=Х.ХХХХХХХ
PowTime=Х.ХХХХХХХ   PowOffTime=Х.ХХХХХХХ
MeasTime1=Х.ХХХХХХХ MeasTime2=Х.ХХХХХХХ
UnMeasTime1=Х.ХХХХХХХ   UnMeasTime2=Х.ХХХХХХХ

I managed to get the data and parce it on arduino but only from the first line. I do not know how to get all other data.


texts: Controlling Protoneer CNC shield without PC

texts:
I'm building an small CNC using Protoneer CNC shield, GRBL and Arduino UNO.
With this I need to connect the board to PC and send G-Code from there.
My question is, is it possible to use the arduino itself to control the CNC shield?
If yes how?
If not is there any other way to send commands other than USB (as Arduino's USB port is not a host)

Thanks


texts: Issue in long ON OFF timer using millis()

texts:
I have 3 components: a relay and two LEDs...I want two timers using Arduino... In timer one, relay should be off on; one LED is off; and other is on...In second timer, relay is off; one led is on; other is off...
This is my Code:

//const unsigned long onTime = (2 *3600000); // 2 Hours in miliseconds;
const unsigned long onTime = (3 *1000); // 3 seconds;
//const unsigned long onTime = (5 *60000); // 15 minutes;

//const unsigned long offTime = (0.5 *3600000); // 1/2 Hours in miliseconds;
const unsigned long offTime = (2 *1000); // 1 seconds;
//const unsigned long offTime = (5 *60000); // 5 minutes;

const unsigned long start_delay = (5 *60000);  // 5 minute in miliseconds

// Tracks the last time event fired
unsigned long previousMillis=0;

// Interval is how long we wait
int interval = onTime;

// Used to track if relay should be on or off
boolean relayState = true;

void setup()
{
  pinMode(13, OUTPUT); //Relay
  pinMode(3, OUTPUT); //LED Green for ON
  pinMode(4, OUTPUT); //LED Red for OFF

  digitalWrite(13, LOW);   // Relay Off
  digitalWrite(3, LOW);    // Green LED off
  digitalWrite(4, LOW);    // Red LED OFF

  //delay (start_delay);  // wait for 5 minute
}
void loop()
{
  if (relayState == true)
  {
    // Relay ON
    digitalWrite(13, HIGH);   // Relay ON
    digitalWrite(3, HIGH);    // Green LED ON
    digitalWrite(4, LOW);    // Red LED OFF
  }
  if (relayState == false)
  {
    // Relay OFF
    digitalWrite(13, LOW);   // Relay Off
    digitalWrite(3, LOW);    // Green LED Off
    digitalWrite(4, HIGH);    // Red LED On
  }

  // Grab snapshot of current time, this keeps all timing
  long currentMillis = millis();

  // Compare to previous capture to see if enough time has passed
  if ((unsigned long)(currentMillis - previousMillis) >= interval)
  {
    // Change wait interval, based on current relay state
    if (relayState)
    {
      // Relay is currently on, set time to stay off
      interval = offTime;
    }
    else
    {
      // Relay is currently off, set time to stay on
      interval = onTime;
    }
    // Toggle the relay's state
    relayState = !(relayState);
    // Save the current time to compare "later"
    previousMillis = currentMillis;
  }
}

Now issue is; when I make timer for seconds like OnTime is 3 second and offTime is 1 second... It works perfect... But timer for hours or minutes does not simply works... it does not switch state from on to off... It constantly remains on... What could be  the problem... Thanks!


texts: Millis () funtion fails to perform for extended period of time

texts:
I'm using millis () function to control the timer of my LED. It is a very basic code that I used from the example libraries. The code worked well for 6 hours (On for 6 h, Off for the following 6 h and continues), however, when I set it up for 12 hours, the light failed to turn off when I checked on it. The designed time should have fit into the 2^32 bits for unsigned long which I have defined beforehand.
Can someone please help on this issue? Thank you!

/*
  Blink without Delay

  Turns on and off a light emitting diode (LED) connected to a digital pin,
  without using the delay() function. This means that other code can run at the
  same time without being interrupted by the LED code.

  The circuit:
  - Use the onboard LED.
  - Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA
    and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN
    is set to the correct LED pin independent of which board is used.
    If you want to know what pin the on-board LED is connected to on your
    Arduino model, check the Technical Specs of your board at:
    https://www.arduino.cc/en/Main/Products

  created 2005
  by David A. Mellis
  modified 8 Feb 2010
  by Paul Stoffregen
  modified 11 Nov 2013
  by Scott Fitzgerald
  modified 9 Jan 2017
  by Arturo Guadalupi

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/

// constants won't change. Used here to set a pin number:
const int ledPin =  7;// the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
unsigned long interval = 12*60*60*1000UL;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}


texts:
I'm using the TC3 interrupt on my Arduino Due to run some code periodically, like this:

void TC3_Handler() {
  TC_GetStatus(TC1, 0); // Remove interrupt flag
  // My code...
}

However, as I've found out, the CPU will not service the same interrupt a second time while the interrupt is running. By editing the priorities of each interrupt source, it's possible for a higher priority interrupt to preempt and run over this interrupt (so nested interrupts are possible), but priority manipulation alone does not allow reentrant interrupts.

I'd like to know if there is any way to make this interrupt reentrant.


texts: How frequently do you need to poll UI buttons before they are perceived as laggy?

texts:
Whilst it is possible, and sometimes desirable, to use pin change interrupts to read the state of buttons, it is simpler to poll the state of buttons in loop(). This is a commonly used technique.

If you loop() executes quickly enough, then button presses are always going to be caught and the user will not be able to perceive any delay or lag.

It is possible that your loop would take so long as to cause a delay or lag to be perceived.

The question is, how long would it be, in general, before a user would see this?


texts: Can any Arduino Due pin be used for PWM?

texts:
Arduino Due has 54 pins. It says that it has 12 PWM pins. I know it uses a more powerful chip than other Arduinos.

Can the number of PWM be increased?

Can any of its pin be used for PWM?


texts: Adding external power supply to any arduino connected component

texts:
I have an Arduino Pro Mini 3.3v and the voltage is too small for my buzzer to ring loudly. I want to add a 9v battery to power the buzzer.

This is my current circuit:
Arduino (pin 9) => Buzzer +ve
Arduino Gnd => Buzzer -ve

I want to power the buzzer using an external 9v battery but I have no idea how to implement it in the circuit. All I know is that the ground should be common.

What next?


texts: How to connect both MicroSD module and MPU9235 power in an arduino

texts:
I'm really new at electronics and wiring, so please be kind. Coding is my stuff, but I'm trying to learn something here.

I'm working with a project to store the movements of a skateboard through a MPU 9235 and the idea is to save the output of the sensor to a MicroSD.

I have both components and acquired a LiPO 3.7v 400mAh to take everything off the protoboard and attach at the bottom of the skateboard.

The code is working, everything code wise is working ok, but I'm strugging to understand how to power both MicroSD module and MPU9235, since both have the VCC pin (VDD in some versions).

The current connections are replicated in Fritzing. Only replacing Arduino Uno for an Arduino Nano, and the MPU 6050 from the picture for a MPU9235.

My first thought was to connect the LiPo battery into VIN and GND pins of Nano. From there I believe that I can wire up the 3V3 output directly to VCC from MPU9235.

But what about the MicroSD module?

How would I power its VCC pin since I have no 3V3 pin left? I read that it's not right to use a digital pin as power output.

How can I connect two components that needs power from external source?


texts:
I would like to make this code using the Arduino Uno. I am using three on/off switches and based on the truth table would like to turn on one of 8 LEDs. When I use digitalWrite(), I get an error code saying that there are too few arguments.

Here is the code

int x = A3;    // select the input pin for the switch
int y = A4;
int z = A5;

int ledPin1 = 2;      // select the pin for the LED
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 7;
int ledPin5 = 8;
int ledPin6 = 9;
int ledPin7 = 12;
int ledPin8 = 13;

void setup(){

  // declare the ledPin as an OUTPUT:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);

  pinMode(x, INPUT);
  pinMode(y, INPUT);
  pinMode(z, INPUT);
}

void loop() {

  if ( (x = LOW) && (y = LOW) && (z = LOW))              //condition 1
  {
    digitalWrite (ledPin1 = HIGH);
    digitalWrite (ledPin2 = LOW);
    digitalWrite (ledPin3 = LOW);
    digitalWrite (ledPin4 = LOW);
    digitalWrite (ledPin5 = LOW);
    digitalWrite (ledPin6 = LOW);
    digitalWrite (ledPin7 = LOW);
    digitalWrite (ledPin8 = LOW);
  }

  if ( (x = LOW) && (y = LOW) && (z = HIGH))             //condition 2
  {
    ledPin1 = LOW;
    ledPin2 = HIGH;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = LOW) && (y = HIGH) && (z = LOW))             //condition 3
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = HIGH;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = LOW) && (y = HIGH) && (z = HIGH))              //condition 4
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = HIGH;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = LOW) && (z = LOW))               //condition 5
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = HIGH;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = LOW) && (z = HIGH))               //condition 6
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = HIGH;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = HIGH) && (z = LOW))                //condition 7
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = HIGH;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = HIGH) && (z = HIGH))                //condition 8
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = HIGH;
  }
}


texts: Time delay without using delay() and millis()

texts: I am designing an industrial control panel using arduino. I have to use time delays as long as 10 seconds and since using delay() makes a halt in the controller I tried using millis(). But it is complicated and it will work only for 50 days. I want the system to work continuously without any maintenance and I need to control as many as 6 relays. So, I need a better solution (hardware or software based) to tackle this problem. How can I do this?


texts: Sending data over two independently powered arduinos

texts: I have multiple arduinos that are each powered by a 12v battery through a 5v regulator.  All arduinos share a common ground.  Can I simply connect the digital output from one arduino into the digital input of another?  I'm worried the (small) voltage differences between each regulator could cause a problem.


texts: Receiving garbage value when sending a Json object from Arduino Uno to NodeMCU using SoftwareSerial

texts:
I am trying to send a Json Object from Arduino UNO to NodeMCU using SoftwareSerial. I am using Arduino IDE. I am getting garbage value on Serial monitor of NodeMCU. Tried it with different garbage values, couldn't receive data from Arduino UNO. Below is the code. PLease help. Thank you in advance. I haven't made a common ground. I have referred this webpage here.

Arduino UNO code:

    #include <SoftwareSerial.h>
    #include <ArduinoJson.h>
    SoftwareSerial s(5,6);

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

    void loop() {
     StaticJsonBuffer<1000> jsonBuffer;
     JsonObject& root = jsonBuffer.createObject();
      root["data1"] = 100;
      root["data2"] = 200;
      if(s.available()>0)
      {
       root.printTo(s);
      }
    }

NodeMCU code:

    #include <SoftwareSerial.h>
    SoftwareSerial s(D6,D5);
    #include <ArduinoJson.h>

    void setup() {
      // Initialize Serial port
      Serial.begin(9600);
      s.begin(9600);
      while (!Serial) continue;

    }

    void loop() {
      StaticJsonBuffer<1000> jsonBuffer;
      JsonObject& root = jsonBuffer.parseObject(s);
      if (root == JsonObject::invalid())
        return;

      Serial.println("JSON received and parsed");
      root.prettyPrintTo(Serial);
      Serial.print("Data 1 ");
      Serial.println("");
      int data1=root["data1"];
      Serial.print(data1);
      Serial.print("   Data 2 ");
      int data2=root["data2"];
      Serial.print(data2);
      Serial.println("");
      Serial.println("---------------------xxxxx--------------------");

    }


texts: Nano: All digital pins do not output anything

texts:
New user here. Using the examples provided on the Arduino IDE software I could produce melodies with a piezo buzzer, or have a blinking LED.
Not anymore. No digital pin is giving anything. I can see the embedded LED blink if I program the Pin 13, but no impact outside of it.
So I tried connecting an output digital pin (13) to an Analog input pin, or any one that can be put as input (A7, D5, etc.) (with a resistor so not to destroy the little thing).
const char out=13;
const char  in=8;
char         i=0;
void setup() {
  Serial.begin(9600);
  pinMode(out, OUTPUT);
  pinMode(in,  INPUT);
  digitalWrite(out, LOW);
}
void loop() {
  if(i&1){
    digitalWrite(out,i&2?HIGH:LOW);
  }else{
    Serial.println(analogRead(in));
  }
  i++;
  delay(50);
}

The output has been 0, whichever digital pin it is connected to.
How can I actually find out if, by any chance, I successfully (!) damaged all my digital pins?

I currently use a breadboard
The ground is connected correctly (to GND)
It stopped working between uses, last time I was trying a Tone(out,val) melody
I'm measuring the out-pin value by connecting it to an analog in-pin with a resistor in series
I did set the out-pin as such during setup. (pinMode(out, OUTPUT);)

So! Looks like I didn't understand the codes for the digital pins. I thought we had to use the pin number, but the digital pin number (say 10 for D10) is what it takes to address it. And I was always referring myself back to the schematic for each pin -_-.
As well with the accepted answer, I needed to pull down (or up? still can't figure it out!) the input pin with a resistor to ground.
Thanks everyone!


texts: about receiving float on matlab from ATmega32 Avr

texts:
****i am using ATmega32 to send float and want to receive it on matlab,i send 4.85 from ATmega32 but on matlab i receive 4.260233679216239e-31...can any one help me..thanks in advance**
**

    //Atmel studio code++++code for sending float from Atmega32
    union abc{ float fo; unsigned long lo; };
 union abc data;
int main(void)
 { usart_init();
 data.fo=4.85;
 while(1) {
for(int i=0; i<=24; i+=8)
{
    uart_send(data.lo>>i); }}}

 //Matlab code for receiving float
s=serial('COM1','BaudRate',9600);
fopen(s);
out=fread(s,1,'single');
 fclose(s);


texts: Corrupted files generated by Arduino with SdFat library. How to avoid that?

texts:
I got:

https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove
http://wiki.iteadstudio.com/Stackable_SD_Card_shield_V3.0 (set to 5V logic)

with this sketch using SPI/SdFat+OneWire/DallasTemperature+EmonLib and no matter what I try I got corrupted files like this.

I even haven't attached my sensors yet :(
I have tried with 3 SD cards so far, each formatted with SD Memory Card Formatter and each one has this problem.

There is a separate question like that (Corrupted files generated by Arduino with SD library. How to avoid that?) but it concerns SPI confict but here SD is my only SPI device on the bus.

Any ideas?


texts: Long term stability of bluetooth connections

texts:
I have two Arduino Megas with HC-05 on Serial1 connected to a Raspberry Pi 3b+ via bluetooth, using the HC-05 and the RPi's built-in bluetooth, and python's pySerialTransfer library to make the connections.

For reasons I am still trying to root cause, the bluetooth connection gets severed a few times an hour. Ideally, I'd get hours to perhaps a day between severed connections; is this a realistic goal?

Over a course of a few days, my testing has shown:

Mega#1 median connection duration is 10 minutes & 88 minute max duration; 25 bytes sent by RPi->Arduino, and by Arduino->RPi every 0.2sec
Mega#2 median connection duration is 38 minutes & 153 minute max duration; 4 bytes sent by RPi->Arduino, and by Arduino->RPi every 0.2sec

During this testing, they're completely stationary within about 12" of each other, so range should not be an issue.

My RPi code detects a lost connection by virtue of failure to receive a message within 5 seconds, and attempts to reestablish the connection, and that is successful about 80% of the time.  I have a second-tier of lost-connection recovery - resetting the HC-05 via an Arduino-triggered MOSFET - if a message isn't received by the Arduino in ~20 seconds, that works in the remainder of the cases, so I'm ultimately able to systematically recover within a max of about 30 seconds.  However, this lost connection for ~10-30 seconds every 10-60 minutes causes a poor user experience for my remote controls.

The Python errors given for about 95% of the failures are a lack of a receipt of a heartbeat message from the Arduino to the RPi python; about 5% give a unspecific [Errno 5] Input/output error error.

While I'm running down multiple theories via day-long stability tests (longer byte transmissions are more error prone? there's some bug in my Arduino code causing crashes, so remove all logic except the send/receive code to test?), I've read a few posts about how finicky & fragile bluetooth can be, and so I'm curious for some thoughts about the general goal / attempt to get a longer-term (hours to a day or more) connection.

Have folks been able to achieve this with the HC-05 on Arduino?  Or is a dropped connection every 10-60 minutes just something one needs to deal with through robust code?  Thank you.


texts: If I put a shield on an Arduino, can I use the Arduino for anything else?

texts:
I did some basic Arduino examples in the recent past, but I have never actually seen a shield for Arduino firsthand.

So I wonder: If I put a shield on an Arduino (for example, the Adafruit Motor Shield), does it "block" the entire Arduino, including all input and output pins?

Is it possible to use a shield, and still connect additional components that would usually connect directly to the Arduino (say, a potentiometer, or anything similar)? Does this depend on the type of Arduino, or on the type of the shield, or is it not possible at all?


texts: How to emulate an analog potentiometer with PWM

texts:
I have a piece of electronic that controls a motor. It takes power from AC power.

Now there is a 10KOhm Potentiometer. The data sheet of this controller says that the control signal is 10Vcc.

Here's the connections diagram (in Italian):

I'd like to emulate the Potentiometer with Arduino. I'm not sure if PWM will do the job.

Any hints?


texts: Can't upload arduino code on the board due to some programmer issues

texts:
As I connected my arduino-uno board and made sure of the "Board" selected, and the "Port" selected as well. There is a problem while uploading, I tried updating the arduino IDE, reinstalling all the arduino drivers, I tried to borrow a new arduino board from a friend and I am 100% sure it is working.

The message I get from the IDE:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

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

avrdude done.  Thank you.

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

Thanks in advance!


texts: Arduino onboard LED pin number as a constant

texts:
To use the onboard LED on an Arduino one usually has to know the pin number (13 in most cases), but is there a constant in the Arduino IDE one can use as well?

So is it possible to use something like int LED = ONBOARDLED; instead of using int LED = 13;?


texts: Hi i am new to Arduino and I want to know if it is possible to read the data from a sensor that it is connected to the Arduino, I am using the Arduino mega 2560, which is already working, as I have a LED which change color depending on the detection of the object and then store it in a file as txt or another normal extension.


texts: displaying a 3 digit clock time on a 4 digit 7 segment display

texts:
I purchased one of these 4 digit 7 segment displays using a TM1637.

I installed the TM1637 display library from the libraries manager and included it:

(#include <TM1637Display.h>).

I am trying to display the time, and I would like, preferably, to display 3 digit times with a colon, but without the leading zero.

I found this great reference online for using the library., and saw the usage for numbers with colons:

showNumberDecEx(number, dots, leading_zeros, length, position)

according to the guide, to have the colon in the center, you would pass 0b01000000 as the dots parameter.

And I figured that if I then want to display, for example, the time 1:36, then my number parameter would be 136, my leading_zeros parameter would be 0 (false), my length would be 3 for a 3 digit number, and my position would by 1 to start the number in the zero-indexed second position:

display.showNumberDecEx(136, 0b01000000, false, 3, 1); //displays 5136

But this displayed 5136 with no colon.

I tried a number of other things, including:

display.showNumberDecEx(136, 0b01000000, true, 3, 0); //displays 13:66
display.showNumberDecEx(136, 0b01000000, false, 3, 0); //displays 13:6A

I finally found code from this site, which works to display the time (albeit with a leading zero), but I don't fully understand it:

display.showNumberDecEx(1*100+36, 0x80 >> 1, 1, 4, 0);

I get that 1*100+36 represents number of hours plus minutes, but I don't get the 0x80 >> 1 bit. I'm assuming the rest of it is just saying make it a 4 digit number and add a leading zero.

Can anyone possibly:
* help me understand the above working code
* tell me an easier way to construct a time so that I can ideally just pass a 3 or 4 digit number and have it automatically render out a clock time with separating colon
* tell me why my previous attempts were incorrect


texts: Path relater errors on compilation in Arduino IDE 1.8.5 under Windows XP

texts:
For the XP under the Russian locale I'm getting the strange output when trying to compile Marlin project for Anycoubic 3d printer according to instruction https://3dtoday.ru/blogs/trialon/marlin119-for-anycubic-kossel-linear-plus

avr-g++: error: C:\DOCUME~1\ИЖИ: No such file or directory

avr-g++: error: Ь~1\LOCALS~1\Temp\arduino_build_153827\sketch\Marlin.ino.cpp: No such file or directory

avr-g++: error: Ь~1\LOCALS~1\Temp\arduino_build_153827\preproc\ctags_target_for_gcc_minus_e.cpp: No such file or directory

avr-g++: warning: '-x c++' after last input file has no effect

avr-g++: fatal error: no input files

compilation terminated.

exit status 1
Ошибка компиляции для платы Arduino/Genuino Mega or Mega 2560.


texts: Client or WiFiClient wrapper for adafruit CC3000 wifi

texts:
I have a CC3000 wifi module from adafruit that is working OK. Now, I am trying to use it together with an external service, which code requires me to pass a Client (from Arduino SDK) reference, but the Adafruit_CC3000_Client does not inherit from Client nor WifiClient.

I am looking for an appropiate wrapper, but unable to find one. Does anyone know about such wrapper?


texts: Overwrite image buffer (inside Adafruit SSD1306)

texts:
I'd like to add a method that replaces the entire image buffer into the Adafruit_SSD1306 library. I haven't worked with dynamic memory handling for ages and I'm not sure how to just simply overwrite its pointer to point to a different memory address where my newBuffer is.

static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {}

void Adafruit_SSD1306::setBuffer(uint8_t * newBuffer) {
  buffer = newBuffer; // not sure which operator to use
}

Update: Passing by reference wouldn't work. The question is: how to overwrite by copying? Would it work well with memcpy?

void Adafruit_SSD1306::setBuffer(uint8_t * newBuffer) {
  memcpy(newBuffer, buffer, (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8));
}

Update: The code above doesn't seem to making anything. This one neither:

void Adafruit_SSD1306::setBuffer(uint8_t * newBuffer) {
  for(int16_t i = 0; i < SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8; i++) {
    buffer[i] = 255; // experimenting
  }
}

Update: setPixel doesn't work either. - Needed display.display(); :)


texts:
Good day

I'm playing with Arduino and shift register chip 74HC595N and already tried many different ways to solve my problem, but still to luck :(

So that is my current simple scheme:

Arduino 2,3,4 ports connected to data, clock and latch pins of 74HC595N. I've connected only first two output pins of chip to make minimum power consumption and to simplify this example as much as possible.

That is my sketch:

const int latchPin = 4; //Pin connected to ST_CP of 74HC595
const int clockPin = 3; //Pin connected to SH_CP of 74HC595
const int dataPin = 2;  //Pin connected to DS of 74HC595

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

void loop() {
  Serial.println("ON");
  digitalWrite(13, HIGH);
  send(B10000001);
  Serial.println("OFF");
  digitalWrite(13, LOW);
  send(B01000010);
}

void send(byte d) {
  Serial.println(d);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, d);
  delay(1000);
  digitalWrite(latchPin, HIGH);
}

And the problem is: sometimes leds are blinking but very unstable. Sometimes it's not working at all, sometimes only first led is blinking, but second one is not. Sometimes opposite - second led is blinking, first one is not. Sometimes one of led is blink very fast (just flash instead of 1 second delay).
If I touch wires and elements on breadboard - something changing. Even without touching anything - situation changing. It seems like problem is somewhere in connection or power supply and I've already tried to except it: tried few different breadboard, two different 595 chips, different wires and resistors, tried Arduino Uno, Mega and nano. Even tried atmega328p standalone, tried power it from USB, from 9v battery, old mobile charger (5.4V, 650 mA), tried to power arduino with external source (12V, 1A). In all cases the problem still exists.

I've already read a lot about power supply for Arduino, but I think at least few of the ways I've already tried to supply power is good enough for 595 chip and two LEDs - isn't it?

Please, advice me what else can I try?


texts: Which Timer can I use on the Arduino/Genuino Micro?

texts:
I'm trying to implement charlieplexing with bit angle modulation on my Arduino Micro, and for that I need to use the internal timers.

Which timers of the Atmega32u4 are unused by the standard firmware? Ideally I'd like to use either Timer1 or Timer3 as they have the highest resolution.


texts: Function not successfully reading sensor registers

texts:
I'm trying to write a library for an accelerometer/magnetometer sensor.  The sensor is a LSM303D chip (https://www.pololu.com/file/0J703/LSM303D.pdf).

I've written a function, readRegister() (below) that's supposed to get the data from the sensor.  However, I put in many different registers into the function into the function, but it always returns the same number.  That number changes every time I unplug my Arduino from my computer.

byte fp::readRegister(byte register_address, int numBytes) {
  Wire.requestFrom(register_address, numBytes);
  byte c;
  Serial.println(Wire.read());
  while (Wire.available()) {
    c = Wire.read();
  }
  Serial.print("0x");
  Serial.print(register_address, HEX);
  Serial.print("\t");
  Serial.print(c);
  Serial.print("\t");
  Serial.println(millis());
  return c;
}

Here's an example of the problem output:

0x8 190 2
0x9 190 3
0xA 190 11

And here is something more like what I'd expect:

0x8 193 [time]
0x9 189 [time]
0xA 195 [time]

Here is the Git repo with the rest of the code: https://github.com/fpdotmonkey/fp_accel

Thank you in advance for your help.


texts: I've been trying to make a wattmeter using arduino but cannot find the shield I need to buy to put onto my arduino to make it. There are no such parts in the Arduino Store and online the best I could find is this. This measures the arduino's energy consumption, however, not other things. I am really new at this and thoroughly lost. I would be really glad if someone could help me with this problem :)


texts:
I have problem with WDT reset. After reset the device goes on for a boot loop. from the following link https://code.google.com/p/arduino/issues/detail?id=181
It has been mentioned that there is problem with Bootloader because some of them does not support wdt properly.How can i find which version of bootloader is running in my arduino mega 2560 . Which version of bootloader support wdt properly? where these bootloaders can be found?


texts: in the datasheet, it's stated that I should apply 32 serial clocks to get the 32 bits of data. How can I program this is Arduino?


texts:
I'm having trouble with flashing amforth on my Arduino UNO.
I'm using an Arduino as ISP to write amforth.

Here's what I do:

Upload the code on the Arduino programmer and set Baudrate to 19200
Wire the Arduinos this way -> Wiring
Run avrdude -P /dev/ttyUSB* -c avrisp -b 19200 -p m328p -e -U flash:w:uno.hex:i -U eeprom:w:uno.eep.hex:i -U efuse:w:0x05:m -U hfuse:w:0xD9:m -U lfuse:w:0xFF:m

Sometimes it fails to set efuse,  but if I give the command just for it, even if it says "efuse changed, it was 5, not is 0xfd, do you want to change it back?" and I say no, I get the message with the correct fuses.

I log onto the amforth Arduino with the python shell, but my stack is constantly ??? -13 and different numbers. I found out -13 is error code for not found, but... not found what?

What does it mean? What am I missing?

I have to say that I'm new at this things, I recently studied Forth and discovered that I can use it on my Arduino, and I wanted to try.

By the way, the Arduino is not original.
 The chip is ATmega 328p

EDIT:
I downloaded amforth from here
Initially I followed [first guide] (different wiring but I've read around it's the same) and then "clarified my doubts" with another one from sparkfun.
(no link used because maximum for me is 2 links per post at the moment, I'll write it in the comments)

I tried with versions 6.1 and 6.0, then I decided to try with 5.9 (the one from the first guide) and now I'm running that (at least it allows me to pop elements from the stack).


texts: Is there any option to connect XDTouch IrTouchScreen to Arduino?

texts:
Is there any option to connect XDTouch IrTouchScreen with USB interface or RS232 to Arduino board?

At the cable of this touchscreen i have something like at the photo.
At the top of the photo pins (+, t, r, -) from touchscreen to SP232EEN, and at the bottom of photo pins (+, D-, D+, -) from CY7C63803-SXC module to USB output.


texts: Using Two Arduino to Lower Power Consumption

texts:
I am planning to build a water quality sensor with ph, temperature, and dissolved oxygen, conductivity. The power consumption looks like it will be very high especially due to the signal isolator, I'm estimating about 250mA. I'm going to place it in a remote area so I need it to be as power-efficient as possible.
I was thinking would this work?
What if I use two Arduino to control the power? The first Arduino will control the power supply to second Arduino, which has the sensor installed, using a timer(RTC) to turn off the power for 30 minutes and on for 30 seconds for it to read the sensor data.
Can this work? What would the circuit look like?
For the isolator, I was thinking to use Tentacle Shield and in the documentation, it says that the isolator itself uses about 150mA plus the sensor circuit.
https://www.whiteboxes.ch/docs/tentacle/t1/#/
Thanks for the help.


texts: I2C FRAM read/write is very slow. Taking over 500 microseconds per read, almost 500 per write

texts:
I've used the example code for the Adafruit I2C FRAM breakout board, but I've made it even simpler by just writing the same thing to each byte location and then reading them all off, doing nothing with the data.

I can tell it works because I can read off any byte and get the expected value, but the problem is that it works way too slowly. writing and reading 512 bytes takes almost a full half a second. This just won't work for my application, but I suspect there's something fundamentally wrong with what I'm doing.

I tried calling Wire.setClock(400000);, which supposedly is the maximum speed my Nano can drive an I2c slave at, but no matter what argument I input, the operation takes the same amount of time (498616 microseconds, within about +/- 20 microseconds).

I also tried calling Wire.begin(); TWBR = 10;, because I read that somewhere. But again, I get no difference. Here's my whole code- It's pretty simple

#include <Wire.h>
#include "Adafruit_FRAM_I2C.h"

/* Example code for the Adafruit I2C FRAM breakout */

/* Connect SCL    to analog 5
Connect SDA    to analog 4
Connect VDD    to 5.0V DC
Connect GROUND to common ground */

Adafruit_FRAM_I2C fram = Adafruit_FRAM_I2C();
uint16_t          framAddr = 0;

byte p = 55;   //any old value- just write the same thing into all locations

void setup(void) {
    Serial.begin(153600);
    //Wire.begin();
    //TWBR = 10;
    //Wire.setClock(400000);

    if (fram.begin()) {
        Serial.println("Found I2C FRAM");
    }
    else {
        Serial.println("I2C FRAM not identified ... check your connections?\r\n");
    }

}

void loop(void) {

    int i = 0;

    long a = micros();

    for (i ; i < 512; i++){  //write 512 bytes to the FRAM board
        fram.write8(i, p);

    }

    for (i = 0 ; i < 512; i++) {  //read 512 bytes from the FRAM board
        fram.read8(i);

    }

    long b = micros();

    Serial.println(b - a);
    Serial.println("");
}


texts: Code example SPI multiple slaves Arduino DUE

texts:
I'm trying to get 2 devices (camera and sd card)to work on the SPI interface with an Arduino DUE.  I'm having trouble finding example code online showing how to communicate with multiple slaves on the DUE as I know it is slightly different than with the UNO.
Questions I have include:
How do you indicate you want to talk to a slave on pin 4? Instead of digitalWrite(4,LOW) do you call SPI.begin(4)? etc..

Can someone post some example code?


texts:
I'm working on using my Raspberry Pi (Raspbian) to upload sketches. However, I'm not sure which package is appropriate for command line usage (like described here on Github).

It seems like sudo apt-get install arduino would install the whole IDE, not just the command line. It seems like arduino-core would be more fitted for this purpose. However, the repository has a note online to use a package called arduino-mk for a CLI, which is what I want. However, this concerns me in the repository's page:

  This package will install a Makefile to allow for CLI programming of the Arduino platform.

(Emphasis mine)

What exactly does this mean? What are the differences between the three packages available?


texts: ESP-12F responds only to a few basic AT commands

texts:
I previously read a few guides and tutorials about the ESP8266 and i just started using the ESP-12F module as i think that it is a terrific replacement for Arduino with the added benefit of Wi-Fi. I only have the module itself which is basically a metal casing so, i wired up the ESP-12F module according to this schematic.

My USB-TTL board is operating at 3 V for its VCC and also for the TX and RX logic levels. I use Arduino IDE 1.8.9 (i made sure that i am using the latest stable version) and then set the COM port to the USB-TTL RS232 connected to the ESP12F and typed "AT" and got a response "OK". Then, i tried, "AT+RST" and got a big bunch of text which proved that there is successful communication with the ESP module. But then, i tried to connect the ESP-12F to my Wi-Fi network, so i entered: AT+CWJAP_CUR="SSID","password" replacing the SSID and password with my own and it gave the response "ERROR", so i tried the old format AT+CWJAP="SSID","password" and again i got "ERROR". So, what am i doing wrong? How to fix this? I was thinking that maybe the firmware on my ESP is old and needs to be updated, so i entered "AT+GMR" and i got this info:

19:07:27.560 -> ready
19:07:27.560 -> AT+GMR
19:07:27.560 -> AT version:1.2.0.0(Jul  1 2016 20:04:45)
19:07:27.560 -> SDK version:1.5.4.1(39cb9a32)
19:07:27.560 -> Ai-Thinker Technology Co. Ltd.
19:07:27.560 -> Dec  2 2016 14:21:16
19:07:27.560 -> OK

Do i need to update my module to be able to connect it to my Wi-Fi? If yes, how? I want to update it as safely as possible as this is my only ESP module and i don't want to inadvertently damage it.


texts: What happens when you call malloc()/free()/new/delete?

texts:
So I understand that generally speaking, dynamic allocation should be avoided. My question isn't how or why, but what happens when you call a function that allocates memory?
On Windows or Linux, when a program allocates memory, a whole bunch of stuff happens, things like virtualisation and security related features that have no relevance to arduino, and the bit that I'm interested in, memory management:
There will be some code, that will look at the alignment and size requirements of the allocation request, look at the pool of memory it has access to, find a space big enough, make a note of the allocation (which also uses some amount of memory) and then return a pointer to the allocated space back to the calling function.
Is there a custom malloc implementation for each device, or does it come with the arduino toolchain (and does that mean Arduino has a different implementation from Teensy, or avr from sam?), or is there some magical default implementation supplied by the compiler? What kind of memory overhead is incurred with every allocation? How easy is it to override this functionality and implement your own (out of morbid curiosity or tendency towards masochistic endeavours)?


texts: default in switch doesn't appear to execute

texts:
I have a situation where the default case in my switch statement doesn't appear to execute as expected. I wonder if there is some subtlety I'm missing here?

Given the following enum:

enum HomingPhase
    {
    Idle = 0,
    Detecting,
    Stopping,
    Reversing,
    AtHome,
    };

and the following methods:

void HomeSensor::setPhase(HomingPhase newPhase)
    {
    phase = newPhase;
    Serial.print("Phase ");
    Serial.println(phase);
    }

void HomeSensor::onMotorStopped() const
    {
    std::cout << "Hstop " << phase << std::endl;
    switch (phase)
        {
        case Reversing:
            setPhase(AtHome);
            break;
        case Stopping:
            setPhase(Reversing);
            const auto target = commandProcessor.targetStepPosition(homeSettings->position);
            motor->moveToPosition(target);
            break;
        default:
            setPhase(Idle);
            return;
        }
    }

At runtime, onMotorStopped() is called and I see the following output, which indicates that phase is AtHome (4) on entry to the method.

  Hstop 4

I expect the default case to execute, setting the phase to Idle but I do not see the output from setPhase(), which suggests that the default case isn't executing. Subsequent output from elsewhere in the code confirms that phase in fact remains set to AtHome (4) and isn't being set to Idle as expected.

I think I may have gone code blind. Can anyone see the issue?


texts: How to test the sleep / enable function of Stepper Driver?

texts:
I am currently using an Arduino Mega 2560 to run this stepper motor driver (Big Easy Driver, ROB-11876 from sparkfun) https://www.sparkfun.com/products/11876.

I am trying to use the sleep or enable function on this chip to decrease the power consumption when I am not using the motor. I have all the rest of the driver working properly (steps, direction etc.) but when I hook up a wire to either the sleep or enable section and send a respective high or low it doesn't appear to do anything. (Chip works as normal, power consumption stays the same).

I have tested to see that the Arduino is outputting correctly and it seems to be. But other than this I'm kinda at a loss on what might be wrong.

Does anyone have any suggestions on why this might be or other things to test to try to narrow down the problem?

Found my answer from Sparkfun - see below


texts: How to webClient.write() an image stored on a String?

texts:
My application runs on an ESP32-CAM.
It takes pictures and stores to SPIFFS.
Periodically SPIFFS is checked and if images are found:
1- The image is saved to a FTP server
2- The image is summited to a Web Service that returns some informations about the image
3- Values are saved to mySQL
4- The image is deleted from SPIFFS
To read the image from SPIFFS I use the following fragment of code:
String imageName   = file.name();
imageBuffer = "";
while (file.available()){
   imageBuffer += char(file.read());
}

The FTP transfer works perfectly with the following command:
ftp.WriteData((uint8_t*)imageBuffer.c_str(),imageBuffer.length());

The service the image is submited for analizes works OK if I use the command:
webClient.write(fb->buf,fb->len);

But as it is not usable in the current implementation of my project I am trying to work with:
webClient.write((uint8_t*) imageBuffer.c_str(), imageBuffer.length());

I get no errors in return but it just does not work and the web service at the destination returns nothing.
What Am I doing wrong?


texts:
I have a folder of mostly .h and .cpp files for the Marlin firmware (3D Printing) from here.

How do I compile that so I can upload it to my Arduino Mega with Ramps?


texts: Why is the output on the MOSI line shifted 1 bit over from what I commanded?

texts:
I've been trying to work with an AD5685R DAC. Per that datasheet, to get DAC1 to output max voltage (5V), I would perform:

SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE3); // DAC uses CPHA=1, CPOL=1

digitalWrite(CS, LOW);
SPI.transfer(0x31); // upper nibble sends a "write and update" command, lower nibble says "DAC1"
SPI.transfer(0xFF);
SPI.transfer(0xFC); // 14-bit DAC, last 2 bits are dontcares, make them 0
digitalWrite(CS, HIGH);

Replace 0xFFFC with 0x0000 to get 0 volts out.

Sending this command as written somehow writes to DAC4 instead of DAC1! and while 5V will come out when I write 0xFFFC, I get to 2.5V when writing 0x0000 instead of 0V.

If I command this with a Bus Pirate and directly write the bytes out, it works exactly as desired.

I used the Bus Pirate to sniff the SPI traffic and it turns out I'm not getting what I've commanded. Rather than 0x31 0x00 0x00 for instance, I get 0x18 0x80 0x00.

If we break this out into bits:

0x310000: 0011 0001 0000 0000 0000 0000 // commanded
0x188000: 0001 1000 1000 0000 0000 0000 // actually sent

So the command actually sent out is shifted by 1 bit!

Here's the bit pattern for 16383 counts (i.e., 2^14-1):

0x31FFFC: 0011 0001 1111 1111 1111 1100 // commanded
0x18FFFE: 0001 1000 1111 1111 1111 1110 // actually sent

The opcode corresponding to 0x18 is "write to input register 4" (the output occurs because I've pulled the /LDAC pin permanently low, see the datasheet), which explains why I'm getting an output on DAC4 instead of DAC1.

This occurs with both a Sparkfun Pro Micro and an Arduino Mega 2560.

What is going on here? Why is the Arduino not sending out what I've actually commanded? Again, writing the hex codes directly to the DAC using a Bus Pirate works perfectly.


texts:
Is it possible to emit data from an arduino connected to a hc-05 Bluetooth module without pairing it to another device?
i.e. imagine that I want to send a Bluetooth signal as if it was a information spot. Then whoever who gets the signal can read it.


texts:
I am trying to implement a toggle switch to turn blinking ON & OFF. However, the code only turns the led ON or OFF and that too unreliably. Can you help me understand why it isn't working?

   const int redLed = 10;
const int buttonPin = 2;
unsigned long newTime;
unsigned long oldTime = 0;
byte newButtonState;
byte oldButtonState = 0;
boolean ledState = false;
boolean blinkState = false;
boolean state = LOW;

void setup() {
  pinMode(redLed, OUTPUT);
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
}

void loop() {

  newButtonState = digitalRead(buttonPin);
  delay(100);

  // check if button state has changed
  if (newButtonState != oldButtonState) {
    // if button was pushed
    if (newButtonState == HIGH) {
      // check led state
      if (ledState == false) {
        ledState = true;
        blinkState = true;
      } else {
        ledState = false;
        blinkState = false;
      }
      if (ledState == true && blinkState == true) {
        newTime = millis();
        if (newTime - oldTime >= 250) {
          state = !state;
          oldTime = newTime;
        }
        digitalWrite(redLed, state);
      }
    }
  }
  oldButtonState = newButtonState;
}