Getting incorrect output from ADC over SPI in Arduino Uno

I am leaving this answer in case anyone stumbles across this question in the future

In a super frustrating, anti-climactic end, it turns out that the ADC chip itself was not working properly. I tested the (faulty) chip using the code above and observed the output of data pin on the oscilloscope and the output was the same square wave irrespective of the input. I managed to find a new ADC and I tested it and it was working correctly. But this raises a new issue for me, this is the third ADC chip I tested that was working correctly, the first two were faulty. It is very unlikely that it is a manufacturing issue and I used the same connections and the same code to test all three of them. Maybe it has to something to do with soldering, because AFAIK that's the only thing that's different.  If anyone knows anything else that might have gone wrong, I'm all ears.


"Number detection" sounds like you're trying to interpret a 7-segment digital display - is that correct? One way would be to place 7 photo-detectors (times the number of digits), one per segment, on or at the face of the display. Sample the photo-detectors and create a 7-bit code representing the lit segments, into a byte. You could start with a simple lookup table that translates from code to the digit it represents. You might need to get clever about interpreting codes that shouldn't appear, but do, due, perhaps to light leakage, ambient lighting, or noise. The "lit" segments may only be lit for a fraction of second at a time, and only one at a time, if the display is multiplexed, so your sampling algorithm will have to take that into account. Must the display remain visible? You might need optics or optical fibers to view the segments without obstructing them.


In file ServoTimers.hin standard Arduino Servo library change the timer

#elif defined(__AVR_ATmega32U4__)
#define _useTimer3
typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t;

on Windows the file ServoTimers.h is located in C:\Program Files (x86)\Arduino\libraries\Servo\src\avr


Communication via IP adress with Arduino IDE and ESP8266

You have the esp8266 talking.  Now you need to come up with a method of passing data from the arduinos to the esp.

You can use serial, you can use i2c, spi? Or something of your own design.  The problem wit using serial is the you are already using serial to communicate with the board from your PC.  You can use SoftSerial on the Arduino, but not sure how you'd do it on the ESP.
There are ways of making both boards work as master and slave i2c and spi, but it's probably overkill.
You could use two pins, one pin sends a binary bit and the other to clock the data, set high when new data has been written and set low when it has been read.
Then just use the same sort of algorithm as you did between you eps.

I have assumed that one Arduino is connected to one esp.  Let the ESPs worry about ip addresses.  If you want the Arduino to specify the destination then use a simpler addressing system than IP and let the ESPs translate that.


You'll see that I've used 10k resistors on each devices's SDA and SCL lines, but is this necessary? I've seen it mentioned on a few online documents for certain breakout boards etc...

You should have just two 3.3K resistors - one on the SDA and one on the SCL lines.  However all your 10K resistors in parallel will equate to about the same thing - just taking up 3x the space.

  Also, are the devices just connected in parallel?

Yes, it's a simple multi-drop bus.

  Are there any considerations I need to make when using 3 I2C devices like this?

Not really, no.  The frequencies in use are generally too low to require any specific layout considerations. Just try to keep vias to a minimum and don't snake the traces around the board too far.


Here's a tutorial from Sparkfun that shows how to drive an LED using a transistor to switch the LED. Where the transistor is connected to +5v, that should be to your external 5v supply. The pin labeled "Control" is connected to one of your Arduino pins. Connect the external supply's ground to the Arduino's ground.

Done this way, the Arduino's pin driver only needs to supply enough current to switch the transistor; the current to power the LED is provided by your external power supply.


How to wire a three-pin on-off-on switch for reading input?

I suggest this simple circuit:

simulate this circuit – Schematic created using CircuitLab
Set both inputs to INPUT_PULLUP. If the input reads LOW, that means it has been grounded by the switch.

Edit: Per Duncan’s request, here is the alternative circuit with the polarities inverted. With the switch’s common connected to Vcc, the inputs should be set to INPUT_PULLDOWN. However, most Arduinos do not support this mode, for lack of internal pull-downs. Then one has to use external pull-downs instead, and set the pins to INPUT.

simulate this circuit
With this circuit, a pin reads HIGH when it is connected to +5V by the switch.


Cannot program two arduinos at the same time because they both use the same COM port

I did not knew I could change the port on windows. This is how I did it thanks to @Majenko's comment.


Error while uploading code to ESP8266 through Arduino Mega 2560

After googling for several hours, I was able to figure out the reason. Thanks to this link. Transferring data to ESP8266 with Arduino acting as USB to Serial converter did not work. Using a USB to TTL converter, and following this link you can easily transfer data to ESP8266.


upload real time ultrasonic sensor data to pubnub using arduino and esp8266

The PubNub website has a link to an Arduino library:

https://github.com/pubnub/arduino

Although it doesn't have specific support for the ESP8266 per se, it does support the Arduino Ethernet Shield, Arduino Wifi Shield and Arduino Wifi101 Shield, so I would imagine it wouldn't be hard to adapt the code.

Be aware that for the Arduino Uno, the SRAM will be fairly limited, where as the  ESP8266 contains 96 KB of DRAM.


FlexyStepper: set current position leads to reach the old target

The point of setCurrentPosition() is to calibrate the stepper. It would normally be used in association with a limit switch of some form.

If you set the motor to go to 1000 and then tell it that the motor is actually at 1500 then of course it will then try and go back to 1000 - you have told it that is where you want it, but you also told it that's not where it is.

The normal usage would be:

Step the motor constantly in one direction until it hits a limit switch or similar
Set the current position to whatever that actual position is
Start going to actual positions that are relative to that reference point.

For example

Move the motor anti-clockwise
Motor triggers limit switch
Stop moving the motor
Set the current position to 0
Start using the motor normally


Converting an int to an unsigned char for display on a Nokia 5110

The idea is that I would read a list of ints from a file ( I have
several files that I would iterate through) and convert that list to
the unsigned char array on each loop iteration.

The file could be a stream of bytes just as well as a stream of ints (or uints). If it were, no conversion would need to be done - just read a byte & store it, read a byte & store it, ....  If instead, it is a character representation of values, "37, 150, 8, ...", again, read the characters of one value, convert them to int8_t or  uint8_t and store them in your byte array. Look up the atoi() or sscanf() functions to do the conversion.


Because you have a common-anode display and you're trying to use it as a common-cathode display. LEDs, like all diodes, only conduct freely in one direction.


Help Connecting MicroSD Module with Arduino Uno

OMG, what a vile listing!

Anyway, I think you'll probably find they are in the order listed in the description when the connector is facing south. It's probably printed on the rear of the board which they don't show.

That is, from left to right, GND, VCC, MISO, MOSI, SCK, CS.

As for connecting a speaker, that depends if you want low quality (PWM) audio, or high quality (DAC) audio.  The latter requires the addition of an audio shield, most of which have an SD card slot on them already thus alleviating the need for this SD card breakout board.

For the former there is a library and instructions here: http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio


A set of posts on Instructables uses an Arduino Nano to generate a Phase Induction pulse, with a capacitor instead of a dump resistor to set up a decaying oscillation, which is then limited with diodes and detected by the analog comparator with interrupts.  The comparator interrupts then count the frequency of the decaying ringing oscillation producing some ferrous/non-ferrous discrimination, and the duration of the ringing, producing some signal strength and size information.

Nano doing Pulse induction with LC-trap oscillation: https://www.instructables.com/id/Arduino-Based-Pulse-Induction-Detector-LC-Trap/
Nano meta detection software with high-frequency ADC sampling: https://www.instructables.com/id/How-to-Program-an-Arduino-Based-Metal-Detector/
Nano doing Pulse Induction, shifting the recovery pulse to match the arduino's analog comparator: https://www.instructables.com/id/Arduino-Based-Pulse-Induction-Detector/

The tricks in the Pulse Induction LC-trap system of using the analog comparator would be applicable to detecting phase shifts and detecting crossings in sync with a timer-based output.


Cant upload arduino code when ESP8266-01 module is connected

Your problem is that there are two ways of wiring your ESP-01 module to the Arduino:

Wired so the PC has access to it and the Arduino is effectively disabled, and
Wired so the Arduino has access to it

You are wired in configuration 1 at the moment whereby the Arduino is effectively turned off and the USB connection goes direct to the ESP-01. When you try and upload code to the Arduino it's the ESP-01 that the computer is talking to, not the Arduino.
You need to wire it in configuration 2. In this configuration the TX/RX pins of the ESP-01 connect to any two pins of the Arduino except pins 0 and 1, and the RESET pin is not connected to anything. Then you can't talk to the ESP-01 through the serial monitor - instead you have to write code for the Arduino that uses SoftwareSerial to communicate for you.
There are many many tutorials online about communicating between the Arduino and the ESP-01.


Print connection password typed by user on NodeMCU Lua ESP8266 ESP-12E

You can't.

The password does not exist.

In short:

The password is used to create a key
The key is used to encrypt the connection
If both ends agree on the encryption then it's "connected" and packets can travel back and forth.

There is no password for you to print, only the fact that encryption didn't agree.

It actuality it's more complex than that, but that's the rough outline of how it works.


if(key != '%' && key != '@'){
  count++;
}
else if(count == 1){
  spot1 = key;
}
else if(count == 2){
  spot2 = key;
}

You've got a problem here.  If key isn't '%' and isn't '@' then you increase count but since all the rest are else if to that then it skips over all of them and never actually puts the digit int the spot.


motor does not move without Serial.println

My guess is Serial.println adds additional delay so stepper motor can react. Without it changes are way too fast (= high frequency noise) to do whole step.

Try to add delay(1); or more into the main loop.


Take a look at the uTube site of "iforce2d". Chris has a couple of GPS projects, which use a GPS and nRF24L01 transceivers to implement a "GPS tag" and he has a model car follow the tag. He also has a ground station with a pan and tilt and a camera following his quadcopter (drone). Lots of useful stuff there.


How would I include Arduino libraries using AVR-gcc without the IDE?

Since you will end up using a significant portion of the Arduino core
library, the easiest path is to accept the idea that you are now writing
“Arduino sketches” rather than plain C++ code. Don't resist, be
assimilated, fire the IDE and write setup() and loop(). ;-)

Once you have something working, the next step is to get rid of the IDE,
which is admittedly not very nice. A couple of ways to do that:

Use Arduino Builder, the command-line tool for building
Arduino sketches. The internals of this are the same as for the
Arduino IDE, but it works on the command line.
Use a Makefile, like Sudar Muthu's Arduino-Makefile. This
is a generic Makefile for building Arduino programs. It is not 100%
compatible with the IDE or Aduino builder, as it does not add function
declarations for you, but it may suit you better if you are used to a
more standard toolchain (it's just make + avr-gcc + avrdude).


Your code is not very long, but I already see a few things that I would change.

int analogPin = 0;
[...]
pinMode(A4, INPUT);

These usages of pins are inconsistent. I personally prefer settings at the beginning of the file, so I'd expect

int analogPin = 0;
int whateverPin = A4;  // I don't have a good name yet

While you have

pinMode(A4, INPUT);

there's no

pinMode(analogPin, INPUT);

The main loop is doing 2 things: a) show temperature reading and b) show the component specs. This would be more obvious if written like this:

void loop() {
  input = analogRead(A4); //analogRead function is used to receive analog data
  volt = (input * 5.0) / 1024.0; //formula using for perform action

  showTemperatureReadings();
  showComponentReadings();
}

Now, that looks a bit strange, don't you think? What about the stuff before these two big show...() methods? These two lines clearly belong into showComponentReadings().

Now, a lot of variables are declared outside of methods. This makes them global variables. It's possible to change them from anywhere in the code. When the project grows, side effects are evil. Let's remove as many of them as possible.

You can get rid of:

int input = 0;
float volt = 0;
float buffer = 0;
float R2 = 0;
float Vout = 0;
int raw = 0;

After this change, I think the setup() method could be more concise. A lot of stuff just deals with the temperature sensor. I would extract a method as well.

The error messages like

  Device did not acknowledge! Freezing.

could not mean very much to the user. A message like

  Temperature sensor did not acknowledge! Check the wiring and press the reset button to retry.

could give more meaningful instructions.

The final code with these suggestions applied:

#include <SparkFun_MCP9600.h>
MCP9600 tempSensor;
int analogPin = 0;
int whateverPin = A4;
float R1 = 220;
int Vin = 5;

void setupTemperatureSensor() {
  tempSensor.begin();
  if (tempSensor.isConnected()) {
    Serial.println("Temperature sensor acknowledged.");
  }
  else {
    Serial.println("Temperature sensor did not acknowledge! Check the wiring and press the reset button to retry.");
    while (1); //hang forever
  }

  if (tempSensor.checkDeviceID()) {
    Serial.println("Temperature sensor ID is correct.");
  }
  else {
    Serial.println("The temperature sensor ID does not have the expected value. Do you use a different sensor type? Use a SparkFun MCP9600.");
    while (1);
  }
}

void setup() {
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(100000);

  setupTemperatureSensor();

  pinMode(whateverPin, INPUT);
  pinMode(analogPin, INPUT);
}

void showTemperatureReadings() {
    if (tempSensor.available()) {
    Serial.print("Thermocouple: ");
    Serial.print(tempSensor.getThermocoupleTemp());
    Serial.print(" °C   Ambient: ");
    Serial.print(tempSensor.getAmbientTemp());
    Serial.print(" °C   Temperature Delta: ");
    Serial.print(tempSensor.getTempDelta());
    Serial.print(" °C");
    Serial.println();
  }
}

void showComponentReadings() {
  int input = analogRead(whateverPin); //analogRead function is used to receive analog data
  float volt = (input * 5.0) / 1024.0; //formula using for perform action
  int raw = analogRead(analogPin);
  if (raw)
  {
    float buffer = raw * Vin;
    float Vout = (buffer) / 1024.0;
    buffer = (Vin / Vout) - 1;
    float R2 = R1 * buffer;
    Serial.print("Vout: ");
    Serial.println(Vout);
    Serial.print("R2: ");
    Serial.println(R2);
    Serial.print("voltage is:");
    Serial.println(volt);
    Serial.print("current is:");
    Serial.println(volt / R2);
    delay(1000);
  }
}

void loop() {
  showTemperatureReadings();
  showComponentReadings();
}

With code folding active, I'd say it's now very simple to get an overview of what the code is doing and what can be configured:

Edit:

After you linked to the schematics, I would

rename whateverPin to voltageDividerPin.
change the calculation float volt = (input * 5.0) / 1024.0; to a mapping, because it maps the 1024 input values to 5V, so float volt = map(voltageReading, 0, 1024, 0, Vin);
remove analogPin completely, because it's not used in the original code as well.

I also hope that read the article and you understood the consequences of using a 220 Ohm resistor.


Those aren't multiplexing chips. Those are just chips to give you more outputs than your arduino has.

The multiplexing is just done on the microcontroller. But it depends on how you are wiring the leds. You can wire the cube to use less digital outputs, but you'll end up with a less bright leds.

You could use no multiplexing. That way the leds are lid with a 100% duty cycle. But for that you'd need 512 outputs.

You can choose to light up only one level at a time. That way you only need 72 outputs (64 for the leds, and 8 for selecting the level). This is a form of multiplexing. Since only one level is lid at a time, the leds have a duty cycle of 12.5%. Please note that because of the way humans perceive light, it will look more like 1/3rd the brightness, instead of 1/8th (so that's great). Also note that since you only need one level to be on at a time, some people prefer to use a decade counter IC for that.

You could also choose to only light one row at a time. That way you only need 24 outputs (8 for the leds, 8 to select which row, 8 to select which level). But you'd need some additional circuitry to combine row- and level-selection.

There are specialized multiplexing IC, but those only support rows and colums (not level). So you need 1 chip for each level, and more problematically you need to run 8-row and 8-culumn wires for each level to the bottom. That's quite a bit of wire, which might ruin the aesthetics of the cube.

In short. There are quite a few ways of making a 8x8x8 cube. I'd suggest finding a well documented build from someone else that you like and follow that.

Quite a bit of information. I hope it's of help. If you have any more question feel free to ask.


Windows driver installer not detecting arduino

Per my comment above, the drivers are not installed when using the Arduino editor from an extracted zip file. If you are feeling adventurous, they are located in the /drivers folder and you can install them manually, there are plenty of instructions elsewhere on the internet on how to do that.

My recommendation would be to just download and run the installer version of Arduino, as that will take care of registering the drivers for you. The installer can be found on the download page indicated with the text "Windows Installer".


How do I connect a LED strip to a Multiwii SE 2.5?

The led strips I've used with my Naze32 have three connection, +5VDC, GND and DATA. I'm not familiar with your FC but based on the image you provided it looks like you would use one of the two I2C ports. As long as you don't try to run too many LEDs (I've maxed out my FC with 32 LEDs no problem) the +5VDC connection should be able to power the LEDs. Obviously connect LED GND to the FC GND. You'll need to check the docs for you FC to confirm but it would make the most sense to me to connect the FC SDA to the LED DATA. The FC SCL would not be used.

NOTE: If your PDB has a +5VDC output you'd be better off using that one to power the LEDs.

In the picture with the Arduino one of the leads is providing +5VDC. I've read the suggestion for LED strips to place a capacitor across the +5VDC and GND to make it more stable but I don't and I've not had any issues. FYI, the lead to the Arduino is for GND and DATA (being driven by one of the Arduino Digital I/O Pins.


Unexpected accident of my board, CH341 issue for Linux or Dead ESP?

Shorting VIN to GND will over-stress the diode that is in-line with the power coming in from the USB.

The result

The diode will blow and you will not get power from the USB to power the board.
The PC may detect "over-current" and shut down the USB port
The USB port on the computer may be damaged

How do you fix it?

Replace the diode if blown.
Use a different USB port.

How do you work around it?

Provide an external 5V power source to VIN & GND if the diode is blown

How do you avoid it happening in future?

NEVER short VIN to GND, even for a short time.  There is a reset pin RST provided for the purpose of resetting the board.


Will the Duemilanove bootloader work in the Uno?

Yes it will.

Both the Arduino Duemilanove and Arduino Uno use the ATMega328P microcontroller. (There is also a version of Arduino Duemilanove ATMega168 that uses the Diecimila bootloader and that is not compatible, so just watch out).

The main difference between the Arduino Duemilanove and the Arduino Uno is that the Duemilanove uses FTDI FT232R IC, whereas the Uno uses the Atmega8u2 microcontroller fto handle the USB to serial UART interface.

Also important is that both boards both have the same 16MHz clock rate.

The schematic for the Arduino Duemilanove can be found here.
The schematic for the Arduino Uno can be found here.

Of course, instead of selecting Arduino Uno as the board type, you need to always select Arduino Duemilanove or Diecimila and the ATmega328 processor.


motor affecting time calculation between hardware interrupts

Noise from electromagnetic sources is always an important issue that must be addressed. The aims are to minimise noise generation at source, reduce transmission of noise between source and the "target" affected circuitry and reduce noise impact at the target.

Motor controller circuit diagram here

The shield power supply link MUST have been removed.
Shield must have all own powering.
Coupling via a common eg 5V supply has a high chance of being problematic.
The two 5V supplies (arduino & shield) could have a common higher voltage source but need separate regulators and proper noise removal in each supply.

Placing extra capacitance across the arduino Vin or main power source MAY help.

I assume that the motors are driven in either direction during operation. If not then a reverse diode across the motors should help.
If bidirectional,  try reversed diodes from each motor lead to Vout (= V+ motor drive voltage).

The shield's Vout filter capacitors C7 & C8 care 47 uF each.
Vout could usefully have 1000 or so uF added somewhere on the board.

I do not know how much motor current is drawn and exact control strategy. This MAY interfere with motor drive but probably not: Identify one motor which "has issues". Add a small series resistance in each lead with a capacitor across the leads on the motor side. Here "small" means "does not noticeably affect performance". eg 1 Ohm if Imotor < to << 1 amp. Capacitor needs to be biplar for bidirectional motor control - eg a 1 uF ceramic or plastic (polyester, mylar, ...) cap.

'If all else fails'[tm] opto coupling the driver interface is possible BUT should not be needed.

Try above.
Report.
Ask more questions if needed.


Two rows of white squares means that the driver chip has been successfully initialised to run in a 2x16 mode (it defaults to 1x16 which was the 1 row of squares you had originally).

So that means that you are configuring the display at least partially correctly.

You should adjust the pot so that you can just about see the squares. The squares are the background and the text would appear over them. If they are too bright you won't see the text. So adjust the contrast until you can just see that there are squares there.

If the wiring is correct and the code is correct then you should be able to see the text.


Mac OS X Catalina Serial Monitor Problem

I fixed issue last night. Catalina has ch340 drivers already and I setup oem driver from GitHub. Apples driver and oem drivers conflicting. If you use Mojave and higher os, you dont need any driver for ch340. So if you installed ch340 oem driver you should delete it.
I am adding the post: Platformio post


Using a potentiometer to control number of lit pixels on an NeoPixel strip

You forgot to clear every other pixel in colorWipe(). Pixels that aren't sent a color retain their previous color.


Turn on a LED when an other LED turn off

First, make sure the LEDs are connected correctly: I presume the red LED is connected to whichever pin LR is, and the green LED to LV.

According to your diagram, your LEDs will be on if the output is HIGH, and off if the output is LOW.  Your code sets LR to high, but then immediately to LOW again.

Here's a fixed (I hope) verson of your loop():

void loop()
{
  readSerial();
  if (received_code == 200){
    // Turn the red LED on
    digitalWrite(LR,HIGH);

    // Turn the green LED off
    digitalWrite(LV,LOW);
  }
}

Unrelated to the problem you're having, but worth a mention anyway:

There's nothing in your code to stop you overrunning buf if you get a longer input than you're expecting.  If this happens you'll get unpredictable results as you trash over whatever happens to be in that part of memory.


Pushing sketches to pro mini with Uno 101

There is no "Arduino Uno 101" there are only "Arduino Uno" and "Arduino 101".

101 uses completely different hardware, and tricks to use an Uno as an USB to UART adapter won't work on an 101.

101 has also separate serial interfaces for USB serial (Serial) and hardware serial (Serial1).

If you have have an Arduino 101 you can solve this by software means.
The board needs to be able to change the baud rate and use DTR for reset.

There is a sketch from PaulStoffregen on GitHub that does that.

/* USB to Serial - Teensy becomes a USB to Serial converter
   http://dorkbotpdx.org/blog/paul/teensy_as_benito_at_57600_baud

   You must select Serial from the "Tools > USB Type" menu

   This example code is in the public domain.
*/

// set this to the hardware serial port you wish to use
#define HWSERIAL Serial1

unsigned long baud = 19200;
const int reset_pin = 4;
const int led_pin = 13;  // 13 = Teensy 3.X & LC
                         // 11 = Teensy 2.0
                         //  6 = Teensy++ 2.0
void setup()
{
  pinMode(led_pin, OUTPUT);
  digitalWrite(led_pin, LOW);
  digitalWrite(reset_pin, HIGH);
  pinMode(reset_pin, OUTPUT);
  Serial.begin(baud);       // USB, communication to PC or Mac
  HWSERIAL.begin(baud);     // communication to hardware serial
}

long led_on_time=0;
byte buffer[80];
unsigned char prev_dtr = 0;

void loop()
{
  unsigned char dtr;
  int rd, wr, n;

  // check if any data has arrived on the USB virtual serial port
  rd = Serial.available();
  if (rd > 0) {
    // check if the hardware serial port is ready to transmit
    wr = HWSERIAL.availableForWrite();
    if (wr > 0) {
      // compute how much data to move, the smallest
      // of rd, wr and the buffer size
      if (rd > wr) rd = wr;
      if (rd > 80) rd = 80;
      // read data from the USB port
      n = Serial.readBytes((char *)buffer, rd);
      // write it to the hardware serial port
      HWSERIAL.write(buffer, n);
      // turn on the LED to indicate activity
      digitalWrite(led_pin, HIGH);
      led_on_time = millis();
    }
  }

  // check if any data has arrived on the hardware serial port
  rd = HWSERIAL.available();
  if (rd > 0) {
    // check if the USB virtual serial port is ready to transmit
    wr = Serial.availableForWrite();
    if (wr > 0) {
      // compute how much data to move, the smallest
      // of rd, wr and the buffer size
      if (rd > wr) rd = wr;
      if (rd > 80) rd = 80;
      // read data from the hardware serial port
      n = HWSERIAL.readBytes((char *)buffer, rd);
      // write it to the USB port
      Serial.write(buffer, n);
      // turn on the LED to indicate activity
      digitalWrite(led_pin, HIGH);
      led_on_time = millis();
    }
  }

  // check if the USB virtual serial port has raised DTR
  dtr = Serial.dtr();
  if (dtr && !prev_dtr) {
    digitalWrite(reset_pin, LOW);
    delayMicroseconds(250);
    digitalWrite(reset_pin, HIGH);
  }
  prev_dtr = dtr;

  // if the LED has been left on without more activity, turn it off
  if (millis() - led_on_time > 3) {
    digitalWrite(led_pin, LOW);
  }

  // check if the USB virtual serial wants a new baud rate
  if (Serial.baud() != baud) {
    baud = Serial.baud();
    if (baud == 57600) {
      // This ugly hack is necessary for talking
      // to the arduino bootloader, which actually
      // communicates at 58824 baud (+2.1% error).
      // Teensyduino will configure the UART for
      // the closest baud rate, which is 57143
      // baud (-0.8% error).  Serial communication
      // can tolerate about 2.5% error, so the
      // combined error is too large.  Simply
      // setting the baud rate to the same as
      // arduino's actual baud rate works.
      HWSERIAL.begin(58824);
    } else {
      HWSERIAL.begin(baud);
    }
  }
}

Then you need to connect:

Arduino 101  |  Arduino Pro Mini
-------------+------------------
VCC          |  VCC
GND          |  GND
TX           |  RX
RX           |  TX
PIN 4        |  DTR

After that you can use the port as a Arduino Pro Mini programmer.


Pin 0 (62) you are trying to use is not supporting interrupts

It is quite right. Those pins aren't interrupt pins. What you want to do is make it use PinChange interrupt pins instead.

This can (by the look of things) be done by including the PinChangeInt.h library before including the RCLib library.


How do I get a nonzero output from my HX711 and load cell?

The zero factor 8388607 showed up in a similar question on another forum and is associated with the range of the HX711 amplifier. This indicated that my amplifier was broken; I have since replaced it and am now receiving a signal from the load cell.


Sending servo position data from one Arduino to another

Yes, sending data over Serial is as simple as using Serial.write() or it's siblings. When sending data over Serial you have to consider, how you want to send it.

Raw binary data: You can simply use the Serial.write() command, which will send the variable as binary data. If you whatch this on the serial monitor of your PC, you will not see readable numbers, because what is shown there is interpreted as ASCII-encoded data, where every byte value has a corresponding character (for example the value 97 is the letter 'a'). On the other Arduino you just use Serial.read() to write the byte data directly to a variable. This is practical, if you are sending always the same amount of data (like the value of one sensor). If the length of a message is variable, you have to use a delimiter, to mark the end of a message. Here the second way is more save.
ASCII encoded data: You can send your data human readable as ASCII encoded data. The value 128 then would consist of 3 bytes, one for each character. Here you always have to use a delimiter, so that the receiver can tell the values apart. A common message delimiter is the newline character '\n'. On Windows you also often have newline and carriage return '\r' together. For decoding you can use one of the many functions, that convert a string/character array to a number with the wanted format (in your case integer), for example atoi().

Refer to the Serial examples in the Arduino IDE to see the code in action.

Note: Since the value of pos only varies between 0 and 180, you can use one byte to save and transmit it, instead of the 2 bytes the integer uses.


Can both the 3.3V and 5V pins on the Arduino be used at once for power?

Yes.

Here's a block diagram of how the Arduino power is arranged:

As you can see the USB power is fed through a FET (P-channel MOSFET) to isolate it when there is external power applied (as decided by the comparator COMP).  External power is fed through a 5V regulator and is fed to the same point as the USB power.  Thus you get the same 5V at the same point regardless of if you have USB or Barrel Jack power.  From there the 5V (wherever it comes from) is fed into a 3.3V regulator.  The 5V pin on the Arduino is connected directly to the 5V point where the USB and the 5V regulated input are connected. The 3.3V pin is connected directly to the output of the 3.3V regulator.

So no matter what input power arrangement you use - barrel jack, USB power, battery connected to the V IN pin (not shown, but connects to the barrel jack), or regulated 5V into the 5V pin, you get access to the same 5V and 3.3V power on the 5V and 3.3V power pins.


Calling a function that is outside of a class from inside

The problem is your definition of tmb2.  You're declaring the variable in the header file, and not the C(++) file.

Please try this:

TimerTwo.h

#ifndef __TIMER_TWO_H__
#define __TIMER_TWO_H__

extern void TIMER2Services(void);

class Tmb2
{
    public:
        void initTIMER2(unsigned int Hz, unsigned int ulPeriod);
        void resetTIMER2(unsigned int Hz, unsigned int ulPeriod);
        TIMER2_TYPE getPeriodTIMER2(void);
        void activeTIMER2 (void);
    private:
};

#endif // #ifndef __TIMER_TWO_H__

The #ifndef TIMER stuff saves you getting multiple definitions from header files if they're included more than once.  There's other ways to do this, but this is simple and well-known.

TimerTwo.cpp

#include "TimerTwo.h"

void Tmb2::initTIMER2(unsigned int Hz, unsigned int ulPeriod)
{
    //setperiod and enable interrupt
    if (Hz)
    {
        ulPeriod = 1000/Hz;    //if Hz > 0 use frequency microseconds
    }
    Timer2.attachInterrupt(TIMER2Services).setPeriod(ulPeriod).start();
}

TimerTwoTest.ino

#include "TimerTwo.h"

Tmb2 tmb2;
volatile unsigned long burpCount = 0;

// This routine services the interrupt
void TIMER2Services(void)
{
    burpCount++;
}

void setup()
{
    tmb2.initTIMER2(blah1,blah2);
}

For the sake of neatness, I'd move TIMER2Services into class Tmb2 as a static function... if possible.


What are the main differences between the Arduino Tre and the Intel Galileo?

Biggest difference IMHO: Tre hasn't been released yet!

Besides that, there are a few different things that you should compare. Not much is available about the Tre as of now, but I'll update this post when it's released.

Basic Specs: [First sub-bullet is TRE, second Galileo; better spec in bold]

Microcontroller:

Texas Instrument Sitara AM3359AZCZ100 (ARM Cortex-A8) (1 GHz, 32 bit), Atmel ATmega32u4 (16 MHz, Secondary, found on Leonardo)
Intel® Quark SoC X1000 (400 MHz, 32 bit)

RAM:

512 MB SRAM (2.5 KB ATmega32u4)
512 MB SRAM

Pins

14 Digital 5V, 7 of which are PWM, 6 analog 5V (additional 6 multiplexed) (32u4); 12 Digital 3.3V, 4 of those are PWM (Sitara)
14 5V digital, 6 of those are PWM, 6 analog 5V

Networking:

Ethernet 10/100
Ethernet 10/100

USB port:

1 USB as slave, 4 USB host ports
Up to 128 devices as host, 1 USB slave

Video

HDMI (1920x1080), LCD header
None that I can find

Audio

HDMI, stereo analog audio input and output
None that I can find

MicroSD card

Yes
Yes

PCIe Slot

No
Yes

Sources (I combined a bunch of data for this): Galileo & Tre

Conclusion: If you need a board before the Tre comes out, which seems to be soon (Spring 2014), Galileo is your only option. Other than that, the Tre seems to be better all around in most aspects, minus the PCIe slot. I can't comment on power, but it seems like the Tre will be able to supply 4x the power per pin than the Galileo. The Galileo is getting older, and it doesn't seem like the Galileo can provide full Linux support like the Tre will.

Personally, I'd wait for the Tre. The only thing I can think that the Galileo would be better for would be either a.) lower power usage or b.) the PCIe slot for a WiFi adapter that works decently. The second one could be solved by doing a common WiFi router hack.

If you need a lot of processing power without the need of low latency, you should conciser sending data to a computer to process.

Source

Source


This is the most basic ultrasound pulse and receive code. I wrote it to work with the HC-SR04 modules; so hopefully it will work fro you too as those also sound at 40khz.

The main functionality comes from the pulseIn() funciton.

#define TRIGPIN 9
#define ECHOPIN 10

void setup() {
  Serial.begin(9600);
  pinMode(TRIGPIN, OUTPUT);
  pinMode(ECHOPIN, INPUT);
}

void loop() {
  digitalWrite(TRIGPIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGPIN, LOW);

  uint16_t duration = pulseIn(ECHOPIN, HIGH, 4000);
  int distance = (duration*.0343)/2;
  Serial.println(distance);
}

Note that you will need to adjust the 4000 (μs) to whatever timeout in you want (or emit entirely if you don't want it).


Motor Shield and HC-06 Bluetooth Module competing for pins

The motor shield doesn't actually use the TX and RX pins. Though as a shield it will go into all the arduino pins.

You could either solder some wires to the TX and RX pins, or use something like the proto shield to sandwich in the middle of it, and connect the BT module onto this shield.

You could also remove all the male headers from the motor shield, and replace them with stacking headers


How do I calibrate an ESC after connecting it to an Arduino?

The is a standard with RC connectors, that is Black always goes to ground white/orange goes to the signal and red/brown goes to 5V.

I don't know if you have made a typo, but you need to connect the white to D9 and the black to GND. Here is a instructables post, it describes using a brushed ESC step two reiterates the colour code standard.

You would also need a rotary encoder or shaft encoder to tell the distance moved, there are lots of ways to achieve this from simple(coded disk and IR arrangement) to custom made PCB add-ons.


Why doesn't pin 3 blink? It blinks in another program

In the tone function reference you can read:

  Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega).

analogWrite() is PWM


Waking up async the Arduino while it is sleeping periodically

My aim was to attach multiple interrupts to my Arduino but my problem was that I didn´t know if when the board changed to sleep mode using LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF) then it could be awake using another interrupt instead of the timer.

The void loop() method must sleep the board every 8 seconds if no button is pressed. Aside there is a method that is called when a button is pressed, that´s because in the void setup () I´ve attached an interrupt using PCintPort::attachInterrupt(PIN_NUMBER, METHOD_TO_CALL,MODE);

OP (PinaGamer) posted this answer inside the question, hence the community wiki answer.


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

At a 30000 ft. level, it's because the defined F_CPU value doesn't match your hardware. This can happen because the incorrect device is chosen in the IDE or because the device is misconfigured in boards.txt, or because the hardware is somehow different from what is expected.

Given that you are using a bare ATmega328P, assuming that you've selected the correct crystal, and that the apparent time scale is 8x, it is likely that the CKDIV8 fuse is set. This means that the chip is running at 1/8 the crystal speed. You will need to unprogram (set to 1) bit 7 of the low fuse byte in order to reset it. Use AVRdude from the command line to read the low fuse byte (-U lfuse:r:-:h), set the bit (lfuse | 0x80), and then write it back (-U lfuse:w:0xnn:m).


The simplest thing is just to mask an individual bit, not do any shifting:

if (options & 0x04) {
    // Do something if true
} else {
    // Do something if false
}

Or, to invert it:

if (!(options & 0x04)) {
    // Do something if false
} else {
    // Do something if true.
}

The thing with C is that 0 is false, and anything else is true.  So if your options variable contains 0b00001010 and you AND it with 0x04 (which is HEX for 0b00001000) you end up with 0b00001000.  That is 0x04, which is something other than 0, so it's true.

If options contains 0b00000010 and you AND it with 0x04, you get 0b00000000, which is 0. Since 0 is false the result is false.

You don't care what the actual number is - you only care if it's 0.


PCINT0, PCINT1, PCINT2, etc. on ATtiny45/85

That is simply the difference between an external interrupt INTx and a pin change interrupt PCINT. The first is an interrupt for a single pin. The second is an interrupt for a complete group of pins. Normally this group is a complete port. As the Attiny85 only has one port, this is the case here. So the whole group is only 1 single interrupt source. Thus it only has one interrupt vector named PCINT0_vect.

A pin change interrupt triggers, when any of the pins under it's supervision changes. You can remove pins from it's supervision by masking them with the PCMSK register.

So the interrupt vector PCINT_vect will be triggered by every change on any of the pins, that are not masked out. It is up to you to check, which one changed it's level.

On bigger microcontrollers, there are more pins and mostly also most of them are connected to a pin change interrupt. Here mostly every complete port is connected to a single pin change interrupt. Thus the corresponding registers are additionally marked with a number (PCINT0_vect as the interrupt vector for the first port, ...)


Is there an Arduino simulator that runs on Mac OS X?

There is a decent program called Simulator for Arduino made by Virtronics. Although it is made to run only in windows, you could run it in a WINE environment. WINE allows windows programs to be ran in Mac and Linux OS.


How does one wire OV7670 camera with Arduino Due?

I am working with small project same in little bit like what you trying to do..
starting with..
1- Arduino UNO + OV7670 + 2.4" TFT LCD (I got not clear live Image)..
so I made some changes..
2- Arduino DUE + OV7670 Live Image (still working with, having problem in reading Image) want to compile the result Image (convert it to text) then sending the result to (3) by serial Port
3- Arduino UNO + 3.5" TFT LCD (it works)..
by the way  Arduino UNO + OV7670 Live Image (worked perfectly), but I am trying to get same project using DUE.. (faster speed & maybe could deal with Image too..)
here link of how OV7670 work with Arduino DUE..
https://www.instructables.com/How-to-Connect-OV7670-to-Arduino-Due/
.....


According to my program running on the chip, it acts as master for SPI peripherals. If using ICSP, how does the chip know that it is supposed to act as SPI slave and receive a program?

A special signal is sent using the RESET pin. From the datasheet (p361):

  Power-up sequence: Apply power between VCC and GND while RESET and SCK are set to “0”. In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to “0”.
  Wait for at least 20ms and enable serial programming by sending the Programming Enable serial instruction to pin MOSI.
  The serial programming instructions will not work if the communication is out of synchronization. When in sync. the second byte (0x53), will echo back when issuing the third byte of the Programming Enable instruction. Whether the echo is correct or not, all four bytes of the instruction must be transmitted. If the 0x53 did not echo back, give RESET a positive pulse and issue a new Programming Enable command.

  Is there anything I must take into account with regards to what is connected to the SPI pins? i.e. does it harm in any way if I have other SPI slaves on the board connected to these same pins?

Yes. It is possible that a chip may respond to the ICSP signals. You should have pullup resistors on all your CS (or SS if you prefer to call it that) pins on all your slave chips so that while the ATMega328P is in programming mode (and all the GPIO pins are in INPUT mode by default) the CS pins of your slaves aren't floating.

  Same for serial programming: how does the chip know that it's supposed to receive a program on the serial interface, when my application uses this port for a different purpose?

Simple: it listens for 2 seconds after power-on or reset for a special sequence of bytes arriving on the serial port. If they arrive within that 2-second window (8 seconds for ATMega32U4 based boards, to allow time for USB enumeration) the bootloader keeps running and looking for programming instructions. If it doesn't see that start sequence within the timeout period it exits the bootloader and runs your sketch.

The STK500 protocol (which the Arduino bootloader is based around) is detailed here. The trigger sequence is the "CMD_SIGN_ON" command detailed on page 4.


Can I generate 5 sec delay within an interrupt program?

You don't need interrupts for any of that. Your main loop just needs to test the switch, eg.

void loop ()
  {
  if (digitalRead (button) == HIGH)  // assuming LOW means pressed
     return;

  // read thermocouple here

  // display results

  delay (5000);

  }

  I want to print the value of the thermistor on lcd using interrupts and i want the value to stay about 5 secs

You are misusing interrupts in what you are attempting. See my page about interrupts. You simply should not be attempting to print or delay inside an interrupt routine. The most you should do is detect that the switch is pressed:

volatile bool switchIsPressed = false;

// Interrupt Service Routine (ISR)
void buttonPressed()
  {
  switchIsPressed = true;
  }  // end of buttonPressed ISR

Now in your main loop you detect that the switch is pressed and take your reading. If you want to do something else "remember" the time you showed the value, like this:

unsigned long whenTemperatureDisplayed = 0;

void loop ()
  {
  if (switchIsPressed && whenTemperatureDisplayed == 0)
    {
    // take reading ...
    // display reading ...
    whenTemperatureDisplayed = millis ();  // when we displayed the reading
    switchIsPressed = false;               // ready for next time
    }  // end of if switch was pressed

  if (whenTemperatureDisplayed != 0 &&
      millis () - whenTemperatureDisplayed >= 5000) // 5 seconds are up
    {
    // stop displaying the reading ...
    whenTemperatureDisplayed = 0;
    }  // end of if time is up

  // do other stuff here

  }  // end of loop


Instead of manually downloading a file from the github repository, check out the repository properly with git clone 《repository》


I keep getting the 'expected unqualified-id before if' error message when trying to run my program

The root of your problem is this line:
if (distance > 10);

You have an extraneous semi-colon and lack the opening bracket of the block it's intended to start.  It should read:
if (distance > 10) {

Also, later on you have something similar:
if (distance <= 10); {

Here you have remembered the bracket, but have still slipped in the semi-colon that is not wanted.
It is important to remember that every opening bracket must have a matching closing bracket, and every closing bracket must have a corresponding opening one.
If you are strict with yourself and keep your indenting strictly correct you will catch such errors much quicker.
Another trick is to start at the top and count your brackets - add one for every opening bracket and subtract one for every closing bracket. If you ever go negative then you know you have a mismatch. If you go to zero and you're still inside a function then you have a mismatch. You should end up on zero. If you don't then you know you have a mismatch.


When your code:

if (currentMillis - previousMillis >= onTime){
    digitalWrite(ledPin2, LOW);
    previousMillis = millis();
}

was in the loop, it was executed multiple times, so when if (currentMillis - previousMillis >= onTime) eventually became true, it would set ledPin2 LOW again.
Now that you moved it to the timer funtion, it only gets executed once (and if (currentMillis - previousMillis >= onTime) never gets a chance to become true).

You need to introduce a loop in the timer function. It also looks like you have your currentMillis / previousMillis messed up. I think you are looking for something like this:

void timer(){

    unsigned long previousMillis = millis();
    unsigned long currentMillis = millis();
    digitalWrite(ledPin2, HIGH);

    while((currentMillis - previousMillis) < onTime) {
        // wait for a bit
        sleep(10);
        // update currentMillis
        currentMillis = millis();
    }

    digitalWrite(ledPin2, LOW);
}


(Arduino Uno) Is my code for a follow the sun project valid? We want the motor to stop when both photoresistors have the same amount of light

There are many issues with this code:

pinMode(7,OUTPUT);

What is this pin for? Why do you set it to OUTPUT and then never
actually output anything? If the pin is in use, you should declare a
constant for it, like

const int fooPin = 7;

and then use the constant instead of the bare number 7.

Serial.println(analogRead(RlightPin));   //Write the value of the right photoresistor to the serial monitor.
TranslateAnalogR=analogRead(RlightPin); //Read the right photoresistor value

analogRead() is a slow function, and it is quite inefficient to do the
analog to digital conversion twice. You can instead

TranslateAnalogR = analogRead(RlightPin);
Serial.println(TranslateAnalogR);

As a matter of style, I would remove the comments. Commenting code is
generally considered a good practice, as long as the comments tell
something non obvious, like giving the “big picture” or the rationale
for doing something in a particular way. Paraphrasing in English what
the code already says in C++ is useless.

Serial.println(analogRead(RlightPin));   //Write the value of the right photoresistor to the serial monitor.
//...
Serial.println(analogRead(LlightPin));    //Write the value of the left photoresistor to the serial monitor.

You won't know what value corresponds to the left and what value
corresponds to the right. I would instead do something like:

Serial.print("L: ");
Serial.print(TranslateAnalogL);
Serial.print(", R: ");
Serial.println(TranslateAnalogR);

Then:

if(TranslateAnalogR=TranslateAnalogL){        //If Photoresistor Value is above 355 the motor will stop

You mean ==.

if(TranslateAnalogR=!TranslateAnalogL && TranslateAnalogR>TranslateAnalogL) { //If Photoreistor R is not equal to L and higher than L move until equal

The first test is redundant. If R>L, then obviously R≠L.

    for (pos=0; pos>=40; pos=pos+1)  {
        myArms.attach(servoPin);
        myArms.write(pos); //send servo to pos
        if(TranslateAnalogR=TranslateAnalogL){
            myArms.detach();
        }
    }

This is a very contrived way of searching the optimum. Normally you
attach the servo once and keep it attached all the time. Then you adjust
the position until you see the same illumination on both LDRs. This way
you keep track of the correct position and you need not redo the whole
angle scan every time. Also, this will not work for three reasons:

You mean TranslateAnalogR==TranslateAnalogL rather than
TranslateAnalogR=TranslateAnalogL
TranslateAnalogR and TranslateAnalogL are not updated within the
loop, you need to explicitly perform an analog read.
The loop will run too fast for the servos to follow the requested
positions.

Later:

    for (pos=0; pos>=40; pos=pos-1){

The loop is backwards. You probably mean

    for (pos=40; pos>=0; pos=pos-1){

Here is my take at this, completely untested:

#include <Servo.h>

// Pinout.
const int PIN_LDR_R = 0;  // right photoresistor
const int PIN_LDR_L = 1;  // left photoresistor
const int PIN_SERVO = 9;  // servo

const int SERVO_DELAY = 20; // time motor waits before working again

int pos = 90; // servo position in degrees
Servo servo;  // servo object

void setup() {
    Serial.begin(9600);
    pinMode(PIN_SERVO, OUTPUT);
    servo.attach(PIN_SERVO);
}

void loop() {
    // Read and report light levels.
    int level_L = analogRead(PIN_LDR_L);
    int level_R = analogRead(PIN_LDR_R);
    Serial.print("L: ");
    Serial.print(level_L);
    Serial.print(", R: ");
    Serial.println(level_R);

    // Adjust the servo position.
    if (level_R > level_L && pos < 180)
        ++pos;
    if (level_R < level_L && pos > 0)
        --pos;

    // Update the servo.
    servo.write(pos);
    delay(SERVO_DELAY);
}

A few things worth noting:

Constants are qualified as const (it helps the compiler optimize and
catch bugs) and spelled in full caps (a common stylistic convention).
The servo position is adjusted step by step, one degree per loop
iteration. No need to perform a full scan every time.
The program does not do anything special when the light levels are
equal, because in that case there isn't actually much to do.
I increased the delay between servo updates to 20 ms, as
the serial communication alone can take close to 19 ms per
iteration.
You may want to add some hysteresis in order to avoid the servo
jitter when it has found the optimum.


Behaviour of tone() not as expected within while loop

You can't use delay() or timer based tone() function in interrupt handler. Set a flag in interrupt and run the code  in loop() conditionally based on the flag state. Do not forget to have the flag variable volatile.


Be sure to select correct board (Arduino UNO) and port.

See this guide for details:
https://www.arduino.cc/en/Guide/ArduinoUno#toc5


How to use float data from a sensor with the Arduino mouse library

The mouse library expects the movement coordinates to be provided as
8-bit signed integers, which corresponds to the int8_t data type. This
type is actually an alias to signed char, but calling it this way is
confusing, as the word char somehow implies a type meant to store
characters, which is definitely not the case here.
Converting a float to any integer type can be done by plain
assignment, with two caveats:

If the float exceeds the range of the integer, the assignment will
wrap around modulo 2^(integer size in bits). This is undesirable and
can be prevented by first constrain()ing the float to the
appropriate range.
The assignment rounds towards zero, whereas rounding to the nearest
integer is better if you want to minimize the errors. This can be
achieved with the round() macro.

In summary:
// In global context:
const float scale = 0.4;  // scale factor for mouse moves

// Within loop():
float rotation = get_data_from_gyroscope();
int8_t mouse_move = round(constrain(rotation * scale, -128, +127));

Note that the optimal scale can only be determined experimentally: you
have to tweak it until your input device “feels” right.


Arduino as analog to digital converter for temperature sensor

Both the ESP8266 and the Arduino have UART serial interfaces. This is by far the simplest method of communicating between two boards.

Connect the TX of the Arduino, through a voltage divider to drop it to 3.3V, to the RX of the ESP8266. Connect the grounds together. That's all you need. Yes, you can connect the TX of the ESP8266 to the RX of the Arduino but if you are never going to send anything from the ESP8266 to the Arduino then there is little point.

Then, with both devices set to the same baud rate, you can Serial.print on the Arduino, and Serial.read on the ESP8266. Just follow one of the many many tutorials about communicating between Arduinos using UART.


How to Capture Data from a Webpage in Arduino and Display it over Serial Monitor of ESP8266?

There are two basic things you are doing wrong:

Firstly your HTTP request is wrongly formatted.  You have:

GET /apps/thinghttp/send_request?api_key=689WYA85WW1VJSBA
Host:api.thingspeak.com

What it should look like is:

GET /apps/thinghttp/send_request?api_key=689WYA85WW1VJSBA HTTP/1.0
Host: api.thingspeak.com:80

Also you only need one blank line after your request, not 5 as you seem to have.

Secondly you are not actually doing anything with the data the site is sending you. You make the request with +CIPSEND= but then the response, which is in the form +IPD,<len>:<data> is completely ignored.  You need to use the SoftwareSerial's .read() and associated functions to receive that data into the Arduino so you can actually do something with it - like send it down through Serial.

Tips:

Look for +IPD, first
Read up to the : and interpret it as a number
You now now how many bytes to read from the data section
Read that data
Do something with it


Arduino R/C compatible transmitter and reciever

If you want to involve an Arduino on the receiver, you may want to choose a transmitter which is compatible with a 2.4 GHz chipset that is both available, and for which you can find Arduino code.  The NRF24L01+ and Beken compatibles are probably the most available, and a lot of RC toys use something compatible, though getting firmware right to interact with them can be tricky.  Beware that there are some other chips in wide use too, which can be harder to source a module for.

You can use an off-the-shelf multi-channel receiver, but that will tend to output each channel on a distinct PWM pin, which is annoying if you want to capture the data into an Arduino.

You might want to spend some time looking on rcgroups and in various hobby drone sites - the latter folks have a similar problem, as they want to collect all the control channels and mediate them through a custom flight computer (which in the early days was sometimes Arduino-compatible).

You can also make your own transmitter - perhaps by retrofitting an NRF24L01+ module and miniature Arduino equivalent into the casing of an older 5/72/75 MHz set - or the IR transmitter from a toy helicopter.


How is a long int stored in an 8 bit Arduino register

It isn't.  It's split into four 8-bit values, each representing a quarter of the bits.  Each value is stored in a separate register or memory location (depending on what is being done with it).

Software then combines them together to act as a single 32-bit value.


The Dout is a TTL threshold indicator; basically it goes high when a certain threshold of the sensor is reached, which is adjusted by the pot.  The Aout is the VRef of the sensor.

Now the MG-811 is not the best sensor in the world; I did look at the datasheet which shows this sensor outputs mV in relation to the PPM so a map function could be used such as 100-600mV maps to 400-10000ppm CO2, see MG-811 CO2 Sensor Module, so you could feed this into a map() function and get the result but since there is a signal conditioning circuit consisting of a op-amp I'm not sure what it does to the raw sensor voltage.

Now the sandbox electronics module may not be identical to the SainSmart module, so you may need to reverse engineer the module you have to determine what is going on or use the schematic from the sandbox site to build your own and de-solder the MG-811 from the SainSmart module.


The ATMega328P chip is, indeed, clocked by a ceramic resonator. The website is misleading in stating that it has a crystal (I have emailed the webmaster to try and get this corrected, though I don't hold out much hope).

The 16MHz crystal in the schematics is part of the USB interface circuitry and has nothing to do with the timing of your running code. It is purely used to clock the ATMega16U2 chip which provides USB connectivity (USB requires a higher accuracy for stable communication).

There are other boards available with better crystals - most often boards that have native USB connections, such as the Arduino Due or Leonardo, or any of the myriad of boards by other manufacturers, like Teensy or chipKIT.


Is it required to delete variables before going to sleep?

You have probably learnt that objects created with new are stored in
the heap, while globals are stored in the .data and .bss sections, and
locals on the stack¹. This distinction, however, only exists in the
software. At the hardware level, .data, .bss, heap and stack are just
arbitrary portions of the RAM.
Think of what would happen if the RAM was erased, or somehow corrupted,
when the microcontroller sleeps. Not only would that affect the
heap-based objects, but also every variable in the program. And even the
return address from the call to gotToSleepAndWakeUpIn4Seconds() would
be lost, so the CPU would not know where to resume execution when it
wakes up. The only reasonable thing to do at wakeup would then be to
restart the program from scratch. And this is actually what happens when
you reset the microcontroller².
But a sleep is not a reset. The contents of the RAM is preserved while
sleeping. This means that the whole state of the program is preserved:
locals, globals and heap-based objects. No need to delete and re-create
stuff.
As a side note, if you can allocate memory statically, this is usually
better than dynamic allocation, ans you avoid the risk of heap
fragmentation:
Foo someObject(arg1, arg2, ..);  // static global instance

void loop()
{
    // Some code, then,

    if (something)
        someObject.executeFunction1();
}

Notes:
¹ As an optimization, locals of the current stack frame may be in CPU
registers, but this doesn't change the conclusion.
² On AVR, a warm reset doesn't loose the RAM, but it is then
reinitialized by the C runtime. A cold reset (power-cycle) does loose
the RAM.


By prefixing your pinData variables with int, you are declaring local variables in your BLYNK_WRITE() functions, whose scope is only in that function. The local version is written to, instead of the global.

To fix this, do not declare a new variable in BLYNK_WRITE():

BLYNK_WRITE(V3) //Button Widget is writing to pin V1
{
  pinData = param.asInt();
}
BLYNK_WRITE(V2) //Button Widget is writing to pin V1
{
  pinData1 = param.asInt();
}
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
  pinData2 = param.asInt();
}


USB control panel with endless turn knobs

Options for the Arduino you have:

Get an Arduino supporting HID drivers (e.g. 32u4 based boards, Due /Zero/ Arduino Leonardo/ Micro or Pro Micro/ M0)
You use this library it supports UNO/MEGA/Leonardo/(Pro)Micro/ any 8u2/16u2/at90usb8/162/32u2/32u4 compatible boards and some more

Then you have to "just" code the communication between your programm and the HID driver -> pretty standard serial/usb stuff.
The parts (knobs) you seek could be rotary encoders, which have no fixed zero point, endless rotation and need 2 input pins per encoder (except GND or optional push function). The signals a rotary encoder produces (and what can be handled by libraries) are based on a 2-bit gray code available on 2 digital data signal lines.
So when choosing whatever Arduino make sure you have enough (usable) I/O ports for the number of encoders and possible additional parts (status led/s or similar, I2C LCD display)


References (e.g, libraries and tutorials) for connecting the 24-bit ADS1256 ADC to arduino

You are lucky. Looks like there is an Arduino library available for the ADS1256. You should give it a shot: https://github.com/Flydroid/ADS12xx-Library .

I haven't tested it but checked the registers and functions from the datasheet and it does look good.


Multiple nodes with the same receiving and transmitting address

as well as comment #1 the other thing will be the ack packets that the slaves will send back to the master to confirm message recieved. with all slaves sending back a ack at about the same time there will be no way for master to tell which ack is from which client, and thus who needs a retransmit. a way around this is to turn off ack for the clients and make the master transmit max times regardless. there is a rf24 fork that has broadcast mode, the makes it more easy to specify not to wait for ack before retransmitting


No, it burns energy by doing nothing.

You definitively should send your MCU to sleep and wake up on events or use the watchdog timer to wake up after a predefined period of time.


Temperature anomaly on BS18B20 + NodeMCU on Tingspeak

Have you checked the device's Scratchpad CRC

Idk how to.

  How is your device hooked up (diagram)

Device is hooked up in normal mode, right like in this pic

DS18b20 (waterproof) is located on top of the boiler in a special pit for measuring temperatures, there are definitely no any sort of microwaves here, and the temp is not higher than 80C.
I'll try today to change the power supply, just in case, and later switch the sensor into parasite mode.


Stop time in Tkinter Stopwatch with a PushButton

In the pyserial docs it states this:

  Be careful when using readline(). Do specify a timeout when opening the serial port otherwise it could block forever if no newline character is received. Also note that readlines() only works with a timeout. readlines() depends on having a timeout and interprets that as EOF (end of file). It raises an exception if the port is not opened correctly.

You need to specify the timeout and the end of line string. Try using this  modified line:

if arduino.readline(eol='\n') == 'E\n':

Also, add the timeout option where you define arduino as a pyserial object. For example:

arduino = pyserial.serial(port,baud,timeout=t,etc...)


Our MyoWare sensor is a single channel EMG sensor and should only be used to detect a single muscle at a time. BUT, if you have 5 sensors, then you can indeed use them to measure each finger's flexion or extension individually. It would take 10 sensors to do both flexion and extension of all your fingers.

However, keep in mind that there are many muscle groups on top of each other in the forearm (e.g. finger muscles, wrist muscles, forearm rotation muscles) and the MyoWare uses surface electrodes. The sensor will detect the activity of any muscle(s) that get activated under the area of the electrodes and you could get a lot of cross-talk between these muscles. For example, the muscles that control your wrist are under the muscles that control your fingers. Any activation of your wrist muscles when trying to measure the finger muscles would cause the sensor to falsely register activity for your finger muscles.

If you are thinking of using it to detect finger position, I would advise using a flex sensor or something similar than a muscle sensor. Muscle sensor sensors are usually used to detect force or as an on/off switch given a threshold value to activate the switch.


For those reading this answer prior to acquiring an LCD for an Arduino project, consider using a more common alpha / numeric LCD rather than a graphic LCD or GLCD.  Likely there will be more examples to follow as well as more software with more community support.

The linked to Graphical LCD (or GLCD) uses a SED1520 controller.  Searching the Arduino community resulted in finding this openGLCD project.  There may be others.  Looking here (near the end of 2019) we see the comment "added custom sed1520 init routine to fully initialize sed1520 chips" next to the sed1520_Device.h file.  Likely this project supports GLCD modules which use the SED1520 chip.

With regards to wiring GLCD module, on page 19 of the specifications linked to in the question, the table in section 5.1 lists the description of the 20 GLCD pins.


how to get an unofficial WiFi Shield to work?

Somewhere it should say this: It is really really difficult to implement enough of the TCP/IP stack on an Uno to handle talking over the Ethernet.  In other words, the shield is doing almost all the work.  As such, if you don't have any documentation, using this Ethernet shield will be difficult.  That said, it looks like this shield is using an ESP8266 which IS widely documented. And if you search around, can even find people creating Arduino / ESP8266 software.


Both ++x and x++ increment the value of x. The difference is whether you evaluate the value of x in your expression (formula) before or after incrementing it.

int x1 = 0;
int y1 = 0;

int x2 = x1++; //Post-increment: Move current value of x1 (0) to x2, THEN increment x1
int y2 = ++y1; //Pre-increment: Increment y1. Then move the NEW value of y1 (1) to y2.

In the above, x2 will be 0, and y2 will be 1.

The same logic applies to your if expression. If you use pre-increment, your if statement makes its decision on the new value after incrementing it.

If you use post-increment, the if statement makes its decision based on the value before it's incremented.


Sketch will not start with external power source

The problem was, as Gerben said, the battery was too weak to run the engine.


Wiring diagram for Arduino to prevent relay firing on reboot

You can add a pull down/up resistor between the wire and ground/vcc so that when the arduino pin is set to high impedance during reboot the wire is pulled low/high as desired.


You should provide a good power source for the VCC. One that can supply 170 mA for WiFi operations of esp8266. You should use the power regulator to supply 3.3 V to VCC and there is no reason to use other power source for the CH_PD pin. CH_PD pin is "enable" pin, it doesn't need a strong power supply.
IO 0 should be connected to ground only for upload, not for normal operation.


pulseIn() is used to Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout.

The timing of this function has been determined empirically and will probably show errors in shorter pulses. Works on pulses from 10 microseconds to 3 minutes in length. Please also note that if the pin is already high when the function is called, it will wait for the pin to go LOW and then HIGH before it starts counting. This routine can be used only if interrupts are activated. Furthermore the highest resolution is obtained with short intervals.

Syntax

pulseIn(pin, value)
pulseIn(pin, value, timeout)

Parameters

pin: the number of the pin on which you want to read the pulse. (int)

value: type of pulse to read: either HIGH or LOW. (int)

timeout (optional): the number of microseconds to wait for the pulse to be completed: the function returns 0 if no complete pulse was received within the timeout. Default is one second (unsigned long).

Returns

The length of the pulse (in microseconds) or 0 if no pulse is completed before the timeout (unsigned long).

For additional information and example code, visit: https://www.arduino.cc/en/Reference/PulseIn, hope this help you to understand the meaning of pulseIn().


Arduino writes file to SD but not content to file

db.create(0, TABLE_SIZE, (unsigned int)sizeof(table_name));

The third parameter is the record size! sizeof doesn't work on data, it works on types, so your getting the size of a char* instead of the size of your sensorlogN struct.

Your code as written shouldn't compile! a char* doesn't have a .id member.

table_name.id = i;
table_name.input = 0;
table_name.timestamp = 0;


How to build (concat) a string with big numbers

The concat function does not implement a float version, but some of char, int, unsigneds...

unsigned char String::concat(long unsigned int)
unsigned char String::concat(unsigned int)
unsigned char String::concat(int)
...

so the compiler does not know how to cast (truncating probably the float) to integer, as there are several options.

You have to convert first your float to string, use dtostrf() or sprintf() then concat to your string.

char outstr[25];
sprintf(outstr, "%f", GPS.latitude);

or

dtostrf(GPS.latitude, 6, 2, outstr);  //check docs for 6, 2 values, and set them for your needs

And then:

vnnt.concat(outstr)

Also note that sprintf is very handy for compact creation of a (char) string:

char msg[80];
sprintf(msg, "$VNNT,GPS, %s %f", GPS.fix, GPS.latitude);


For the digital output pins, how is LOW different than no connection?

(Edit for clarification: I've assumed in this answer that you're asking about the difference between connecting the relay to ground/LOW vs. connecting the relay to nothing at all. I've also assumed by the word "trigger" that your relay has some kind of digital actuation built-in, such as a transistor, or that it's simply a Solid State Relay.)

If something is unconnected, it is described as 'floating'. This means there could be random voltage spikes in it caused by nearby electromagnetic fields, making it appear to be switching on/off.

Connecting something to ground or LOW can stop this from happening by drawing away any induced currents.


How to get an angle from two ultrasonic sensors

Your question is unclear. You say you want "...to measure the angle at which he presses buttons". I don't know what that means.
If you're using ultrasonic sensors those measure distance. buttons tend to be fixed in place. Maybe you're  talking about having a joystick on the gaming chair? Two-axis joysticks should let you input an X and a y value.
If you're trying to calculate the angle between a pair of ultrasonic sensors and something that is in their "line of sight" (line of sound?) then you'd use trig.
You would have your sensors at a known distance from each other. You'd measure the distance to each sensor, form a triangle out of all 3 distances, and use the law of cosines to calculate the angles.
The formulas from that page are:
cos(C) =  a² + b² − c²/2ab
cos(A) =  b² + c² − a²/2bc
cos(B) =  c² + a² − b²/2ca
(Where upper case letters denote the angles of the triangle at a vertex, and lower-case letters denote the legs of the triangle. See the illustration on that page.)
 SensorA
    \
     \      SensorB
      \       /
       \     /
        \   /
         \ /
          V
        object

(one leg would be the SensorA-to-SensorB distance. Another leg would be the SensorA-to-object distance, and the 3rd leg would be the SensorB-to-object distance.)
However, all of that will only work if the object you are detecting is in the range of angles in which your sensors are able to detect objects, and in the range of distances they provide accurate readings.
Edit:
When I copied the formulas from the source site, the superscripts were lost. I've edited them back so the formulas are more readable.


What can be used as a connector for the I2C sensors? It should be customer friendly. So something like RJ11 or USB. What can be used for that?

Almost anything you like. Whatever is easy to get hold of and use. You only need 4 wires, and they are all low voltage, so nothing too fancy is needed.

  Is it possible to send data wirelessly from a I2C sensor?

No. But you can connect the I2C sensor to an Arduino then use that with a wireless interface of some form to send the data wirelessly.

One thing for you to know though:

I2C is not suitable for long distance communications. A few inches to a foot or so is about the limit. Anything longer and you will start running into communication problems. For longer distance communications you need to use a more reliable protocol.


I see a couple of issues here, which are related to your questions. I will use numbers here, but these do not necessarily correspond to the numbers you have used when asking.

The first thing you need to do when controlling a motor is to know it maximum stall current. The stall current is the current that will circulate through the motor (and through the transistor) when you apply an external force to stop the motor's shaft. But it's also the same current needed for the motor to start when it's completely stopped. So, for dimentioning a transistor, you typically will select one that has, as a rule of thumb, a collector current two times bigger than the motor's stall current.
The 2N2222 has a maximum Ic of 800 mA (best case, since there are 600 mA versions as far as I know). Although you are not specifying much about your particular motor, a typical 3V DC motor may easily be asking for 500+ mA. Some small motors (specially bad quality ones) may have stall currents bigger than 1 A.
If your motor is asking for, let's say 300 mA when continuously running, then, you are near enough of the maximum current of the 2N2222.
But there is something more important here: dropout voltage in the transistor. The 2N2222 is a bipolar one, so it will have a Vce superior to 1V (probably around 2V), which means that you are dissipating a non trivial amount of power in the transistor. That power is not useful for your motor, nor for your transistor. Here, if the motor has a 3V nominal voltage, the 2V dropout in the transistor is even desirable, but I don't see your calculations about the real dropout in your description. So I assume that you are just counting that there will be an approximate 2V dropout. That means that, if your motor is taking 0.5A to work, you are dissipating 2V x 0.5A = 1W (Watt) in the transistor. But the poor 2N2222 is a 0.5W transistor! But even if your motor is using much less current, let's say 0.25 A, you are sill using it at its limits. That will explain why it's getting hot.
So, my advice is to go for a bigger transistor, if you want to count on its dropout to do not apply a voltage bigger than 3V to the motor (which can really reduce it lifespan a lot), AND do some calculations to be sure that at the currents you are using, you will have the Vce that you want.
Another option, probably better, is to replace that bipolar old transistor by a MOSFET, but you will need to provide the apropiate voltage for supplying the motor, since if not you will get nearly all the 5V to the motor (due to the very low Ron on Mosfets, and thus very low dropout voltage), and that will be very bad.
Also, please note that the 500mA of the USB port are probably not enough for your setup. But even if you are powering your Arduino from an external power supply through its power jack, you will find a good idea to use common grounds but different Vcc sources for logic and for the motor.
Finally a short advice: be sure that the diode protecting the back EMF (the diode connected with its cathode to Vcc in your circuit) is a fast diode. A slow, 1Nxxxx diode is usually to slow for effectively protecting your transistor. If you are using for example an 1N4007, you can switch to a UF4007 (Ultra Fast).
Regarding your 560R vs 2K2 resistor, this exceeds the answer a bit, so my advice is to read something about base resistors in transistors, like this. Also something about open collector configurations may help.
Finally, the practice of connecting the base resistor to Vcc in this kind of circuit to test the transistor should be fine. But DO NOT CONNECT the transistor's base directly, use always the resistor.


I have found the answer. I am not an arduino-newbie, but I was thinking that probably I am making a stupid mistake somewhere. But the problem is in my arduino. I tried setting pin D13 (and then all other pins) to HIGH, and I only measured 4.60V! I measured my USB port and it outputs 5.00V exactly, so there must be a problem in the arduino. So the solution - the ADC takes 4.60V as 1023, and therefore if you calculate it you get that the real voltage is 3.90V, which is exactly the same as my DMM said. Thanks Majenko, you were pointing the right way :) By the way, I was using a cheap Arduino Nano from China, I bought it only for 2.2 USD from Ebay. When I used original Arduino, the code and circuit perfectly works. Do you think that this can limit the functionality of my board?


Is it common that Uno clones misbehave when connected to 12v on VIN?

Is it common that Uno clones misbehave when connected to 12v on VIN

Whether it is "common" is probably unanswerable unless you do some sort of survey.

However bear in mind that clones or "knock off" boards (some of which pretend to be official ones) are built to a price. The original Arduino was already designed to be cheap. To make them even cheaper the manufacturers may well make a number of compromises. For example, some use a cheaper USB interface chip. It wouldn't surprise me if the components like the voltage regulator, capacitors, etc. are under-specified.

I see from eBay that clones are already quite cheap, possibly around $US 4.50. To compete with that, some manufacturers may be cutting back even further on the quality of components.

  I assume the solution is to either use a linear regulator wired to VIN, or a battery?

You are probably better off bypassing the on-board regulator entirely. Get a wall-wart that outputs 5V regulated. The sort of thing that might power a USB-based device. Then plug that into the 5V pin of the Uno (not VIN). In fact, virtually any mobile phone charger wall-wart will output exactly what you want. Just run a USB cable from that to the USB port on the Arduino, and there you have it! Regulated 5V power.

The other thing that could work would be to give the voltage regulator a break. Don't put 12V into it, put in 9V. Then it doesn't have to work so hard (that is, dissipate the extra voltage as heat).


DC-DC converter with Arduino not working

The arduino output pin cannot provide enough current to drive the pump. The DC-DC converter is not designed for this use.

You need external power supply with enough current to drive the motor that you switch on and off with the arduino output pin.

Search for "Arduino 3V DC motor control" for examples of how to do this, there are many options.


Please explain this adafruit image for connecting a DS1307 RTC

It's written in the tutorial

  If you set analog pin 3 (digital 17) to an OUTPUT and HIGH and analog pin 2 (digital 16) to an OUTPUT and LOW you can power the RTC directly from the pins!


'Serial1' was not declared in this scope for automatic plant watering

The UNO only has one serial port, named Serial.  You can create another one using SoftwareSerial (which you have included but not used) and you can, if you choose, name this Serial1.

#include <SoftwareSerial.h>

SoftwareSerial Serial1(4, 5); // RX, TX


Well, DUMBO (that would be me) found the problem, and it was a real bonehead error.

When I applied the stand-alone code to the RTOS environment, I did not reallocate pin assignments, so there were multiple I/O events writing to the same port that was using the Test LEDs.

I knew that FreeRTOS couldn't be that bad, as if the I/O went to the incorrect pins, the code would be useless.

So, don't take shortcuts, even if you're not ready to complete all segments of the project. Check for duplicate definitions or they will bite you in the ass.......


HC06 correct baud rate but missing characters/ no AT commands

Sorry, my question was not easy to understand. Your solution had not worked for me.
I found another libary where its possible to add the parity bit:
https://github.com/ledongthuc/CustomSoftwareSerial

This works fine for me.

Thanks for your help :)


Honeywell HPMA115S0, sensor not start again after stop

I have the same problem here. I'm using a HPMA115S0 with an ESP8266 and found out that the sensor don't respond in general if you are doing a deep sleep with the ESP. If the ESP wakes up, the sensor does not respond on commands till you remove the 5 volts of the HPMA for a short time to make an "hard reset" of the sensor.

I think there is a problem with the ttl-level on the UART-RX-line of the HPMA. Because if you're pulling the rx-line of the sensor manually to ground (maby the ESP is doing this if he goes to deep sleep or wakes up), the sensor does not respond after that.

I spend very much time in this phenomenon. I used different pins on the ESP for software UART and used the hardware UART, problem still exists.
I assume that the ESP pulls all his pins on ground level for too long. That means that the stop bit (high-level), which the sensor wants after 8 bits are transmitted, is not present. This leads to strange behavior of the sensor.
I don't have a digital storage scope to see the level on rx-line, so this is only a presumption. But I don't have this problem, if the ESP idles with an sleep-command.
Maby you are also doing a deepsleep with your ESP which results in the same problem?

Best regards


Where could I find the "Serial.find()" source code?

It is part of the Stream class which the Serial class inherits from.

https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Stream.cpp#L93

It just calls findUntil() which is a little further down in the same file:

https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Stream.cpp#L114

That itself calls findMulti() which is where all the magic happens:

https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Stream.cpp#L256

int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
  // any zero length target string automatically matches and would make
  // a mess of the rest of the algorithm.
  for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
    if (t->len <= 0)
      return t - targets;
  }

  while (1) {
    int c = timedRead();
    if (c < 0)
      return -1;

    for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
      // the simple case is if we match, deal with that first.
      if (c == t->str[t->index]) {
        if (++t->index == t->len)
          return t - targets;
        else
          continue;
      }

      // if not we need to walk back and see if we could have matched further
      // down the stream (ie '1112' doesn't match the first position in '11112'
      // but it will match the second position so we can't just reset the current
      // index to 0 when we find a mismatch.
      if (t->index == 0)
        continue;

      int origIndex = t->index;
      do {
        --t->index;
        // first check if current char works against the new current index
        if (c != t->str[t->index])
          continue;

        // if it's the only char then we're good, nothing more to check
        if (t->index == 0) {
          t->index++;
          break;
        }

        // otherwise we need to check the rest of the found string
        int diff = origIndex - t->index;
        size_t i;
        for (i = 0; i < t->index; ++i) {
          if (t->str[i] != t->str[i + diff])
            break;
        }

        // if we successfully got through the previous loop then our current
        // index is good.
        if (i == t->index) {
          t->index++;
          break;
        }

        // otherwise we just try the next index
      } while (t->index);
    }
  }
  // unreachable
  return -1;
}


how can i fix the error ? stk500v2_getsync(): timeout communicating with programmer

It's our old friend the CH340G again, isn't it?

You've been sold a dud, I'm afraid. The USB chip used there is dead. It happens a lot with those cheap Chinese boards. You should still be able to use the board with an external FTDI adapter by wiring it in to TX->RX, RX->TX and DTR->RESET (via a 100nF capacitor) with power and ground connected of course.

There is also a slim chance that the CH340G may interfere with the TX/RX pins, in which case you may need to remove it. Simply cutting the pins on it with an xacto knife then removing the stumps with a soldering iron and tweezers would do the job.


Should I buy Arduino as a Computer Engineering Student?

It depends. If you don't have any knowledge about microcontrollers it might be useful.

However, Arduino hides a lot of concepts in their libraries. If you want to go more indepth check other systems like STM32 or PIC.

You also can do both, start with Arduino to get a rough feeling, continue with another.

More important is WHAT you try, don't stop with LEDs/switches, but check communication protocols like SPI, I2c, UART etc. And learn what timers, interrupts etc. are and how to use them.


What pins to use on a Teensy to get data from multiple peripherals?

The first thing to look at when determining which pins to connect a peripheral to is what protocol that peripheral uses - e.g. I2C, SPI, analog voltage via ADC, etc. The Teensy pinout for the version you have (e.g. the 3.2 pinout) lists which pins can function as which protocol functions. For example, pin 19 can act as an analog input (A5) or as part of the 0th I2C unit, SCL0. Your LSM9DS1 can use I2C, so you could connect it to that I2C unit. Typically Arduino libraries will default to using the default peripheral type. In Arduino, an I2C bus is called Wire, so a library for an I2C device will typically use the Wire device. Well-written libraries will also let you pass in your own peripheral, which is how you change the pins. Each library will do this differently.


This is a common question when designing software. The simple answer (rule of thumb) is statically allocate the maximum size of the array. In this case the maximum size of the arrays. This simple rule will keep you out of trouble and make testing etc much simpler.

Using dynamic allocation (adjusting array size etc) especially for small scale embedded systems such as the Arduino opens a "can of worms" with possible memory (heap) fragmentation and hidden concurrency and performance issues.

If the required maximum size of the array is 32 elements the application has to allow that and there is no memory to save. Statically allocating will make the sketch simpler and easier to test.

Cheers!


Constructing my own serial command syntax to control arduino

Expanding on my comment... I wrote a simple command line interpreter
that you can use as a base, or an inspiration, for your own interpreter.
In order to not make a link-only answer, I will put here an annotated
and simplified version.

The incoming characters are handled by loop(). They are stored into a
static buffer until a carriage return (CR = '\r') is received. When
the CR is received:

the buffer is NUL-terminated in order to make it a proper C string
it is handed to the exec() function for interpretation
the variable storing the command length is reset to zero for the next
command

Here is the code:

while (Serial.available()) {
    static char buffer[BUF_LENGTH];
    static int length = 0;  // length of line received so far
    int data = Serial.read();
    if (data == '\r') {
        buffer[length] = '\0';     // properly terminate the string
        if (length) exec(buffer);  // give to interpreter
        length = 0;                // reset for next command
    } else if (length < BUF_LENGTH - 1) {
        buffer[length++] = data;   // buffer the incoming byte
    }
}

The exec() interpreter function uses strsep() to split the
command line into a command verb and subsequent parameters. It then
compares the command verb with all supported commands in a long if...
else if sequence, like this:

static void exec(char *cmdline)
{
    char *command = strsep(&cmdline, " ");

    if (strcmp(command, "mode") == 0) {
        int pin = atoi(strsep(&cmdline, " "));
        int mode = atoi(cmdline);
        pinMode(pin, mode);
    } else if (strcmp(command, "read") == 0) {
        int pin = atoi(cmdline);
        Serial.println(digitalRead(pin));
    } else if (strcmp(command, "write") == 0) {
        int pin = atoi(strsep(&cmdline, " "));
        int value = atoi(cmdline);
        digitalWrite(pin, value);
    } else {
        Serial.print(F("Error: Unknown command: "));
        Serial.println(command);
    }
}

This one supports the three commands:

mode <pin> <mode>, meaning pinMode()
read <pin>, meaning digitalRead()
write <pin> <value>, meaning digitalWrite()

The full version is here: Simple Arduino command line
interpreter. Compared to the version in this answer, the
main differences are:

it echoes the characters it reads, and does so in a way which is
friendly to terminal emulators:

it echoes CR as CRLF
it handles BS (backspace) and echoes it as BS + space + BS

it uses strcmp_P() instead of strcmp(), with the PSTR() macro,
in order to keep the constant strings in Flash only
it supports more commands, including "help".


Arduino Pro Mini Avrdude stk500_getsync() not in sync

I just change the processor to 5V even if i have 3.3V and it works!!


Yikes! Invalid device signature. Fail to burn bootloader and read fuses

If you are burning the bootloader through the IDE it won't expect the CKDIV8 fuse to be set.

I have a bootloader programmer which you could use to reprogram the bootloader. You just need another Arduino (eg. Uno, Mega) and connect 6 wires between each of them like this:

The sketch for programming the bootloader is available on Github:

https://github.com/nickgammon/arduino_sketches

You want the one in the "Atmega_Board_Programmer" subdirectory.


Arduino countdown timer for repeating actions

Something like this would work as a non-blocking, general purpose timer:

unsigned long startTimestamp;
unsigned long timestamp;
const unsigned long timer_length = 10000; //10 seconds

startTimestamp = millis();
timestamp = startTimestamp;

while ( (timestamp - startTimestamp) < timer_length)
{
    // keep doing thing

    timestamp = millis();
}

// stop doing thing now


How to turn I2C Sensors on and off with an Arduino Mega 2560?

The SDA and SCL pins have pull up resistors on them. So their voltage is 5V. By disconnecting Vcc on the sensor you are running the sensor out of spec. since the voltage on the SDA and SCL pins exceed Vcc.

Most chips have clamping diodes. So the chip is clamping the 5V on the I2C pins to Vcc. So you are powering the chip through the pull-up resistors on the I2C pins.

This would explain why the power led is lit, but not as bright.


From the picture you posted, i was able to google and find something called a BC04-B Bluetooth serial module. It looks almost exactly like yours, and I found a diagram on how to hook it up.

I also believe that these are the serial commands you can use with it...


Arduino Yun not getting response from Azure API

Found the problem, even though I set azure to accept http requests, it was still redirecting to https which the arduino couldn't handle. I've written a python script to offload the requests to the linux processor, and now it works.


You've tried to print an interval at the bottom of the setup() function, using finishtime before you have ever used it. Fortunately, finishtime will have been initialized to zero before the program runs so the the arithmetic result will be zero, though meaningless.

In loop(), you've never completed the interval calculation before you try to print it.

If nothing at all is being printed, check your wiring and be sure your code is getting the triggers. You haven't showed your wiring, so we can't help you debug that, in case there is a problem with that also.


Common/standard library and/or protocol for Arduino to be I2C slave for driving NeoPixel

You should break your project up into smaller parts.

Consider using other led strips, that can be driven directly. Consider using ready-made parts or opensource code (google).
Make an Arduino drive a NeoPixel Ledstrip. (Check adafruit libraries/NeoPixel guide)(Sanity/wiring check)
Communicate with Arduino and Beaglebone over I2C. Try sending "Hi" and respond "Ok".
Think of a protocol, how to indicate start/stop of a message.
Send the "color bytes" using said protocol.
Unpack the color bytes and put them in a pixel array (See NeoPixel library).
Run "ledstrip.show();”

Please atleast try to do these steps. If one fails, you can create a question with details on what you have tried or what isn't working.

Maybe "nodepixel" already has the Arduino code for you. You then only need to know what bytes to send over I2C, which you can do with any programming language that supports I2C access on your platform.


what command should i use to read and write through spi.tranfer command

In the LM74 the third byte you send (or more specifically the last 8 bits of up to 32 bits past the 16th bit that you send) is read and used as the configuration register setting.

Since the configuration register only has two states 0xFF is go to sleep sleep and 0x00 is do conversions (as shown in table 1 of the datasheet).

So:

0x00 0x00 0xFF

means get one result then go to sleep.

0x00 0x00 0x00

means get one result and stay awake.

If the LM74 is currently asleep from an 0x00 0x00 0xFF sequence the result you get returned is not a temperature but the chip's manufacturer ID.

It's not an obvious method of controlling a chip, and it's actually pretty poorly written in that datasheet, so don't feel bad about not understanding it, it took me a few moments to understand it.


Running a DC motor for a set amount of time

#include <Arduino.h>

const int pirPin = 9;
const int motorPin = 2;
int switchState = 0;
// the setup routine runs once when you press reset:
void setup()
{
 // initialize the digital pin as an output.
 pinMode(motorPin, OUTPUT);
 pinMode(pirPin, INPUT);
}
void loop()
{
 while (digitalRead(pirPin) == HIGH)//this part of the code gets executed if the pir
 //pin is read high
 {
   digitalWrite(motorPin, HIGH);//the motor pin is set high so if a motor is connected
   //the motor will start turning.
 }
 while (digitalRead(pirPin) == LOW)//this part of the code gets executed if the pir
 //pin is read low
 {
   delay(100);// so your motor stop after running for extra 0.1 seconds
   digitalWrite(motorPin, LOW);//the pin gets low and the motor should stop turning
 }
}

I have commented all the lines
Hope this helps.


How to control cold to hot (blue to red gradient) RBG LED strip/bulb with a rotary encoder?

Well as I understand you want to use a rotary encoder ? Rotary encoder can turn freely. Which you can read via arduino easily with a library. You can count a number(let's say x) from 0 up to 255, and write that number to one of the color. For the other color write 255-x so when blue is fading down the red is increasing. But I suggest you to use a potentiometer which has a limited turn (about 270 degrees). Connect it to arduino's one of the analog read pins. It will give you a 10 bit value which is between 0-1023 . You can scale this down to 0-255 range with map function. [Example:  "x = map(x,0,1023,0,255);" ] after that just follow the same process as before.