When it says the Uno has logic level at 5 V is that also true of a bareduino/breadboard Arduino?

The logic level is the same as the voltage you supply the chip.

You can think of the IO pins as tiny switches that either connect the output pin to the supply voltage or to ground (when in output mode) or compare the incoming voltage to an input pin to a percentage of the supply voltage (typically <0.3×Vcc for low and >0.6Vcc for high)

So yes, if you run the chip at 3.3V the logic level will be 3.3V logic (or more specifically < 1.1v for low and > 2.2v for high).


Perhaps you are looking for items like these from from a well established seller adafruit.com.  However, what you are proposing is not cheap when compared to soldering.  I would recommend you learn soldering as it will likely be the way you want to assemble your final Arduino project.


I got the same problem here. But I found the solution. You must install a driver for chip CH340G. Here is all the steps http://www.instructables.com/id/Instalar-driver-para-CH340G/


Flashing with the serial port is the only practical option. The flash chip can be removed, and it can be flashed off board, but that isn't practical.

Has the board ever worked? Have you used other RSP8266 boards before or is this the first you have? Do you have a different USB cable you can try? Marginal power can cause unpredictable operation.


How can we know the status of the DC Motor whether it is ON or OFF

Unfortunately, the L298N does not return a status, so you are going to have to add sensors to detect motor movement.
Here are a few options you can try:

Current sense. Add a small resistor to the output of the L298N and measure the voltage differential across that resistor. If there is current being supplied to the motor then you will have a voltage differential.
Rotation sensor. This can be in the form of a quadrature encoder wheel, tooth sensor or Hall effect sensor detecting a magnet on the shaft. If you see pulses from the sensor then you know the motor is spinning.
Optical sensor. A camera system or other optical sensor to detect motor movement. Probably too complex for a simple application. There are however off the shelf sensors that will turn on an output if they see movement in their field of view. Alternatively you could use a PIR sensor from a home alarm system if the movement is course enough.


Use Print library to set string variable

You can get all the functionality of Print by creating your own class
that inherits from it. For this, you only need to implement the
size_t write(uint8_t) method that prints a single character. Here is a
simple class that inherits from both Print and String, i.e. you get
a String you can print() and println() into:

// A String you can print() and println() into.
class PrintString : public Print, public String
{
public:
    PrintString() : String() {}

    size_t write(uint8_t c) {
        *this += (char) c;
        return 1;
    }
};

And here is how you could use it:

PrintString answer;
answer.print("The answer is ");
answer.println(42);


How can I increase the responsiveness/speed of my stepper motor?

Your problem is that you want to go from a standstill to full speed instantly. That just isn't going to happen. As you have seen there is a limit to how fast you can go from stationary.

If you want to go faster you will have to accelerate up to that speed.

The simplest way to do that is to use a library that is designed for it, such as the popular AccelStepper.h library.


// You don't need to return anything since it's just a delay
// also I changed the parameters to long ints because millis()
// returns a long int
void timeLoop (long int startMillis, long int interval){ // the delay function

    // this loops until 2 milliseconds has passed since the function began
    while(millis() - startMillis < interval){}
}

// Your call for a 2 millisecond delay would be
timeLoop(millis(), 2);

Also the leds may be acting weird because this schematic is wrong. As you can see one of the led's anode isn't connected to ground. It's circled in red.

If you really want it to return something you could use this:

long int timeLoop (long int startMillis, long int interval){ // the delay function

    while(millis() - startMillis < interval){}
    return millis() - startMillis;
}

But it really isn't needed.


Python Arduino Serial Communication Speed

All of the code takes time. It takes ~0.2 ms just to send the 8bytes at 250k, then you have to process the data. I would suspect that all that is taking longer then 2.5 ms and so by the time you read again, you have more then 8 bytes in the buffer, and eventually it overflows. I would try decreasing from 25ms to 24 and re-test, then reducing again. you may be able to find the lower limit of what will work reliably. This is assuming there is a need for it to update faster then 40 times a second, if not then just stay at 25ms


It depends what sort of comparison you want to do.  If you want to see if note[x] == learn[x] then that's what you do.

If you want to see if all the notes match all of learn then you'll need to put the comparison in a loop.

for (int n = 0; n < MAX_NOTE && note[n] == learn[n]; ++n)
{
    // Empty loop
}

If you want to see if the first n notes match the current note and the proceeding n notes then its a bit more complex, but its just a loop.

int n = 0;
for (int l = currentPos;
(l > (currentPos - 10)) && (note[n] == learn[l]);
 l--, n++)
{
    // Empty loop
}

If it is something else you want, please can you try and describe it in idiot proof terms so I can understand it.


How will Arduino sketch and Android app communicate over GPS?

How will i make arduino with gps to communicate with android app? i just need this for my school project.

as gps is one-way communication, you will have to either launch your own birds capable of two way communications, or pick a different school.


How to switch an external circuit with Arduino?

If I understand your writeup correctly, this is what you have built:

simulate this circuit – Schematic created using CircuitLab

What you didn't mention in your question is that you made a connection from Arduino ground to the base of the transistor and the seconds circuit's ground connection. I drew the extra lead 'loose' for illustration only, but you see where it should connect. Current needs a return path, it is not sufficient to only have the forward path (from Arduino through R1 and base-Q1). The return path is emitter-Q1 to Arduino-GND.

Do notice though that the two batteries / power supplies must be floating with respect to each other otherwise you're going to short them out.


Why using static volatile for variables and only static for arrays in TWI library?

You use volatile to mark variables that are going to change at any moment, in a ISR (Interrupt Service Routine) typically.

You mark them so the compiler doesn't optimize, and always go and pick its actual value. If you don't do that, then an ISR may update a variable while the main "thread" of execution keeps using its old value. That's is a nasty situation to debug.

You only need to mark variables that are used both in the ISR and in the main sketch. If twi_masterBuffer is not changed inside an ISR, you don't need to mark it with volatile.

static is used inside function to mark variables that need to be permanent, i.e., keep their values between calls, but not accessible from outside that function.


I think it always will if the redbear is the type of board that has very little memory and only runs one program at given time.  It resets to run the new program in my humble opinion.  Your mileage may vary.


First off you're going to need to define some custom characters. There's examples for how to do that.  You want characters that gradually fill up from the bottom to full, such as:
▁ ▂ ▃ ▄ ▅ ▆ ▇ █
Now, you have 8 lines per character and two lines of characters, which gives you a possible drawing range of 0-16. So you need to map your maximum range into that 0-16 span.
Finally you want to create a function to draw a single bar. This will take two parameters - the position of the bar (x) and the height of the bar (y). A simple little bit of mathematics later and you can work out what to print in the upper and lower characters.

If the value is = 0:

Both top and bottom are spaces

If the value is <= 8:

The bottom character is the one with the same number of lines as the value
The top character is empty.

If the value is > 8:

The bottom character is the one with all 8 lines filled
The top character is the one with the value - 8 number of lines filled.

So you may end up with something like (note - untested):
const uint8_t bars[8][8] = {
    { 0, 0, 0, 0, 0, 0, 0, 0xff },
    { 0, 0, 0, 0, 0, 0, 0xff, 0xff },
    { 0, 0, 0, 0, 0, 0xff, 0xff, 0xff },
    { 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff },
    { 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff },
    { 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
    { 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
};

void setup() {
    // other stuff, like setting up the LCD...

    for (uint8_t i = 0; i < 8; i++) {
        lcd.createChar(i, bars[i]);
    }
}

void drawBar(uint8_t x, uint8_t y) {
    char top, bot;

    if (y == 0) { // Both spaces
        top = ' ';
        bot = ' ';
    } else if (y <= 8) { // Bottom has bar graph, top is empty
        top = ' ';
        bot = val - 1; // Characters start at 0, so 1-8 is 0-7
    } else if (y <= 16) { // Bottom is full, top has bar graph
        top = (y - 9); // Characters start at 0, so 9-16 is 0-7
        bot = 7;
    } else { // Overflow - both top and bottom full
        top = 7;
        bot = 7;
    }

    lcd.setCursor(x, 0);
    lcd.write(top);
    lcd.setCursor(x, 1);
    lcd.write(bot);
}

void loop() {
    // your stuff in here
}

Then to draw a bar you just call drawBar 16 times:
for (uint8_t i = 0; i < 16; i++) {
    uint8_t y = <your calculation on vector2[i] here>
    drawBar(i, y);
}

If you've done it right you should end up with something like:
▁█ ▄ ▆█▇   ▃ ▃▇
██▃█▇███▅▆▇█▆██▃


Is it possible to press a button from Arduino and my computer will get a key event?

The Uno is not the best board for this. You may be able to get somewhere with the Virtual USB project but there are a couple of boards that are better suited for this.

Those are the Arduino Leonardo, Micro, and Due. In those, you can use the Keyboard Library just like you are using the Serial library now. This page has an example very similar to your project:

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send the message
    Keyboard.print("Hello!");
  }
}


There are a lot of much more powerful boards available (especially if you move from ATmega to ARM).  I'm partial to the Teensy boards myself but Adafruit also makes some nice ARM-based boards.  For example, I'm currently developing a multi-user, Arduino-compatible Unix-ish OS on one of the latter (48MHz ARM, 256kB flash, 32kB SRAM) and it runs great.  Honestly, controlling 5 non-graphical LCDs over I²C is should be easily doable on an Uno but if you need more power there are lots of options available.
(No affiliation to either of those companies)


Can I use Arduino to generate a 0 to 15V analog output?

The Arduino cannot directly produce anything more than 5V.

You can use PWM and a Low-Pass Filter to produce an analog waveform between 0 and 5V, which you can then amplify using a suitable non-inverting buffer with 3x gain (op-amp), which will boost the voltage to 15V. Whether that is suitable for your needs, though, since the current will generally be quite low (most op-amps have a high output impedance) is unknown.

If you want a cleaner waveform you can attach or create a DAC which produces discrete output voltages (again between 0 and 5V) which you then amplify similarly.

simulate this circuit – Schematic created using CircuitLab

R3 and C1 form the low-pass filter and should be sized according to the frequency ranges you want to filter and keep. Note that many op-amps that can cope with the higher voltages you need aren't rail-to-rail which means you will have to use a higher power supply voltage than you want to output to leave some headroom. Similarly the 0V will be clipped and will never go below a certain voltage. If you want to get right down to 0V you will need a negative power supply to feed the V- supply of the op-amp (which is currently connected to ground in this schematic). That would allow the output to drop right down to 0V.


Which Arduino is compatible for atmega164pa

There is an Arduino core for the '1284A, but it can be adapted to the '164A.


What you could do with for this is hysteresis.

Instead of simple threshold ranges (0 < A < B < C < 5) you instead need to watch the voltage over time and decide what it is doing compared with what it has done in the past.

You need to keep a record of what state the voltage is in at any one time - That is, is it in band A, B or C in the thresholds above. You then need a second set of thresholds, A1, B1 and C1.

The two thresholds overlap:

If, for example, the voltage rises from between A and B to between B1 and C1 then you switch states to the BC state.

If it falls from between B1 and C1 to between A and B then you switch to the AB state.

Basically, if the voltage rises, it needs to transition between the lower set of thresholds to the upper set of thresholds to register as a change. If it drops it has to transition between the upper set of thresholds and the lower set of thresholds to register as a change.

So, in pseudocode,

if (State == 0A && Voltage > A1 && Voltage < B1)
    State = AB
    Turn on LED 1

if (State == AB && Voltage > B1 && Voltage < C1)
    State = BC
    Turn on LED 2

if (State == BC && Voltage > C1)
    State = C5
    Turn on LED 3

if (State == BC && Voltage < B && Voltage > A)
    State = AB
    Turn on LED 2

if (State == AB && Voltage < A)
    State = 0A
    Turn on LED 1

if (State == C5 && Voltage < C && Voltage > B)
    State = BC
    Turn off all LEDs

It's up to you to decide what a good level of separation is suitable for your system.


Trouble configuring Arduino Due SPI to ADC

For anyone else who comes across the same problem, this worked for me:

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

// Set Constants
const int adcChipSelectPin = 8;      // set pin 8 as the chip select for the ADC:

// Start setup function:
void setup() {
    pinMode (adcChipSelectPin, OUTPUT);

    // set the ChipSelectPins high initially:
    digitalWrite(adcChipSelectPin, HIGH);

    // initialise SPI:
    SPI.begin();
    SPI.setBitOrder(MSBFIRST);         // Not strictly needed but just to be sure.
    SPI.setDataMode(SPI_MODE0);        // Not strictly needed but just to be sure.
    Serial.begin(9600);

    //Clock Speed: Master clock/divider
    //84Mhz/64 =  1.3 MHz
    SPI.setClockDivider(SPI_CLOCK_DIV64);

    //Send dummy values over when ADC is turned on
    //Hold Din High for 16 clock cycles twice
    digitalWrite(adcChipSelectPin, LOW);
    SPI.transfer(0xFF);
    SPI.transfer(0xFF);
    digitalWrite(adcChipSelectPin, HIGH);

    digitalWrite(adcChipSelectPin, LOW);
    SPI.transfer(0xFF);
    SPI.transfer(0xFF);
    digitalWrite(adcChipSelectPin, HIGH);
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    //Send dummy values, next read should have correct values

    digitalWrite(adcChipSelectPin, LOW);
    byte FirstByte = 0x83;
    byte SecondByte = 0x50;
    byte response1 = SPI.transfer(FirstByte);
    byte response2 = SPI.transfer(SecondByte);

    digitalWrite(adcChipSelectPin, HIGH);

    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    ///////////////////////////////////////////////////////////////////////////////////

    //50ns quiet time?
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
    asm volatile("nop");
} // End setup function.

// Start loop function:
void loop() {
    float voltage[2];
    for (int i = 1; i < 17; i++) {
        voltage[i] = readAdc(0, 1);
        //50ns quiet time?
        asm volatile("nop");
        asm volatile("nop");
        asm volatile("nop");
        asm volatile("nop");
        asm volatile("nop");
    }
} // End of loop function.

//Function to read the ADC, accepts the channel to be read.
float readAdc(int channel, int slave) {
    float value;
    if (slave == 0) {
        byte FirstByte = 0x83;
        byte SecondByte = 0x50;
        FirstByte |= channel << 2;

        noInterrupts(); // disable interupts to prepare to send address data to the ADC.

        digitalWrite(adcChipSelectPin, LOW); // take the Chip Select pin low to select the ADC.
        //Write = 1
        //SEQ = 0
        // ADD3-ADD0 = 0000
        //PM1 = PM0 = 1
        //Shadow = 0
        //WEAK/Tri = 1
        //Range = 0
        //Coding = 1
        //0b10000010 1010 0000
        //extra 4 zeros to fill

        //May need to wait 16 * (1/freq)
        //16 * (1/1.3MHz)
        byte response1 = SPI.transfer(FirstByte);
        byte response2 = SPI.transfer(SecondByte);
        digitalWrite(adcChipSelectPin, HIGH);

        interrupts(); // Enable interupts.

        //Serial.println(response1);
        Serial.println(response2);
        byte channel = (response1 >> 4);
        //byte value = (response1 << 4);
        //byte digitalValue = (response1 << 4) | response2;
        //Serial.println(digitalValue);
        //Serial.println(channel);

        byte digitalValue = 0x00;
        float value = (float(digitalValue) * 3.3) / 4096.000; // The digital value is
        converted to an analogue voltage using a VREF of 2.048V.
        //Serial.print(channel);
        //Serial.print("\t");
        //Serial.println(value);
    }
}


i2c of Atmega 328 on arduino uno not working

I2C (SDA-SCL) line needs to be pull up (place resistor on both to 5v input from master- the uno), it works with the arduino code for master-slave I2C (uno on master-severino on slave) using the code from arduino website (just be sure you set the address for the slave on the slave sketch (any number 1-126), it works for me that way, my pull up resistor is 10kohm, the same goes for my breadboard, if this is not doing the trick, maybe there's something wrong (I wouldn't know the answer to, just tried the i2c yesterday) update : on august5th (today) I just finished reading i2c's on atmel site, it is a complex one, there are several factors on why something is doing something on your twi comm, post your code, and maybe I have an answer


I'm assuming you already have some understanding of programming, so I won't literally explain everything line-by-line (that would probably be beyond the scope of this site, and would result in a very long answer). I'll try to explain the important points though. If you need to lookup more information about specific commands, I recommend checking out the Arduino reference.

At a very broad level, the program is taking some readings, and reporting data to a screen (LCD). I would guess that the data is the fluid level in a tank, as well as some kind of temperature reading. It's impossible to be sure about that though, as I don't know what's actually connected to the inputs.

This line creates an object for talking to the LCD screen. The numbers specify which pins it's connected to:

LiquidCrystal lcd(2, 3, 10, 7, 5, 4);

The setup() function gets run once when the device starts up, and is typically used for initialisation tasks. In this case, the lines within setup() initialise two pins as outputs (#12 and #13), initialise serial communication (which isn't actually being used), and initialise the LCD object/screen:

pinMode (12,OUTPUT);
pinMode(13,OUTPUT);
...
Serial.begin(9600);
lcd.begin(16, 2);

The rest of the program is in the loop() function, which runs repeatedly as long as the device is on.

The following lines take 4 analog-to-digital readings (from different inputs), and output the approximate result:

int se25 = analogRead(A4);
int se50 = analogRead(A3);
int se75 = analogRead(A5);
int se100 = analogRead(A2);
if(se100>=1000){lcd.print("100%   ");mem=100; }
else if(se75>=1000){lcd.print("75%   ");mem=75; }
else if(se50>=1000){lcd.print("50%   ");mem=50; }
else if(se25>=1000){lcd.print("25%  ");mem=25; }
else{lcd.print("emty");mem=0;}
if(se100<1000&&se75<1000&&se50<1000&&se25<1000){
    digitalWrite(13,LOW);
    lcd.setCursor(12,1);
    lcd.print("emty");
}

My guess is that each of the analog readings comes from a different fluid sensor in a tank. If the top sensor shows a strong reading, the tank is considered full. Otherwise, it checks the next sensor down, and so on. If none of them shows a strong reading, the tank is considered empty. Interestingly, the condition for an empty tank is actually checked twice, which is presumably a mistake.

(Once again, bear in mind that I'm just guessing that the readings are from fluid sensors in a tank. I don't know for sure.)

The remainder of the code only runs if a particular input (#6) is low, and if the tank is not empty. Input #6 could be from some kind of override switch, but again that's just speculation.

The following block takes 6 analog readings, all from the same input. There's a short delay (20 millisecond) between each reading. The results are then averaged. This is a common approach when you want to try to eliminate noise spikes in an analog signal.

int tempa = analogRead(A1);
delay(20);
int tempb = analogRead(A1);
delay(20);
int tempc = analogRead(A1);
delay(20);
int tempd = analogRead(A1);
delay(20);
int tempe = analogRead(A1);
delay(20);
int tempf = analogRead(A1);
delay(20);

int avg = ((tempa + tempb + tempc + tempd + tempe + tempf ) / 6);

The next block re-maps that reading onto a different range (presumably related to the expected temperature range). It then takes another analog reading from a different input, and remaps that to a different range:

int temp = avg;

temp = map(temp, 0, 1023, 0, 4900);
float tempx = temp * (0.1);

int tempy=analogRead(A0);
tempy = map(tempy, 0, 1023, 0, 150);

The following block outputs the two re-mapped readings. It looks like both of them are treated as temperatures. One is presumably from a temperature sensor, and the other is presumably from a potentiometer used to calibrated the system:

lcd.setCursor(0,0);
lcd.print("act T=" );
lcd.print(tempx);
lcd.print("'C  " );
lcd.setCursor(0,1);
lcd.print("set T=");

lcd.print(tempy);

lcd.print("'C  ");

These lines compare the two readings from above, and set output pin 13 high or low depending on which reading is higher. I'd guess it could be connected to a warning light or similar.

if(tempy<=tempx){digitalWrite(13,LOW);}
if(tempy>tempx){digitalWrite(13,HIGH);}

Lastly, this delay stops the loop from running too fast. Interestingly though, the code only reaches this point under certain circumstances. In other circumstances, there's no limit on loop execution speed:

delay(200);


PHP/My SQL Database -> to Arduino Serial Monitor

Firstly if you really are using an Uno then you cant read the data without putting the uno on a network (obviously).  To do this you could get either a Ethernet shield of a Wifi shield.  A wifi shield is probably based on an ESP8266 and you talk to it by creating a serial connection (using a software serial port).  There are plenty of examples and messages on here to get you started.

Once that's working you need to write a web client (note that this is much easier if you program the ESP8266 rather than the Arduino).  Your client needs to request the page from your server and then parse the returned data and extract the field you want.

While you are waiting for you network shield to arrive you could practice doing it on a Windows PC with Visual Studio, it will be easier to debug.


analogWrite(PIN, 1023)  digitalWrite(PIN, HIGH)

I can confirm that 1023 does indeed give 100% duty cycle. I connected an output of my D1 Mini to my oscilloscope and got a steady voltage.
I can also confirm that the same voltage is output for digitalWrite() and analogWrite().
However the output drivers may not be the same. With analogWrite() it may be using a weaker output driver that can't deliver as much current, so the voltage droops slightly more than it would with digitalWrite(). However even with a 470Ω resistor connected between the output and GND (the smallest value I had easily to hand in a through hole variant) I see no variation in the voltage at all.
So if there is some variation then it might be some variable that is showing a variation in your specific unit but not mine.


The HttpClient object must be instantiated with a Client object which will handle the underlying connection. Source:

  Requires a networking hardware and a library that provides transport specific Client instance, such as:

Refer to the following code:

https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/examples/DweetGet/DweetGet.ino
https://github.com/adafruit/Adafruit_CC3000_Library/blob/master/Adafruit_CC3000.h#L86
https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/src/HttpClient.h#L51

In the above example, it is done like

WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);

Which means that for your code, you might want to pull out client as global object and instantiate it as:

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,    ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIVIDER);
/* Create new Adafruit_CC3000_Client object */
Adafruit_CC3000_Client cc3000_client;
/* Feed this into the client */
HttpClient client (cc3000_client, "dweet.io", 80);

You should also use the example code to see how to print the response after executing client.get():

  // read the status code and body of the response
  statusCode = client.responseStatusCode();
  response = client.responseBody();
  Serial.print("Status code: ");
  Serial.println(statusCode);
  Serial.print("Response: ");
  Serial.println(response);

The example code is pretty much example what you want, you just have to give it a Adafruit_CC3000_Client as the Client.

Full code:

#include <Arduino.h>
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <HttpClient.h>

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,    ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIVIDER);
/* Create new Adafruit_CC3000_Client object */
Adafruit_CC3000_Client cc3000_client;
/* Feed this into the client */
HttpClient client (cc3000_client, "dweet.io", 80);

#define WLAN_SSID       "ssid"
#define WLAN_PASS       "pwd"
#define WLAN_SECURITY   WLAN_SEC_WPA2

int statusCode = 0;
String response;

void setConnection(){

    Serial.println("Initializing...");
    if (!cc3000.begin())
    {
        Serial.println("Couldn't begin()! Check your wiring?");
        while(1);
    }
    Serial.print("Attempting to connect to ");
    Serial.println(WLAN_SSID);
    if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
        Serial.println("Failed!");
        while(1);
    }
    Serial.println("Connected!");
    Serial.println(F("Request DHCP"));
    while (!cc3000.checkDHCP())
    {
        delay(100);
    }
    Serial.println(F("DHCP success!!"));
}

void dweet(){

    int ctr=0;
    char buff[100];
    int x=0;
    const char* host = "https://dweet.io/get/latest/dweet/for/dunebot";

    Serial.println(F("Initializing dweet client ..."));

    client.get(host);
    Serial.println(F("Client Connected !"));

    // read the status code and body of the response
    statusCode = client.responseStatusCode();
    response = client.responseBody();
    Serial.print("Status code: ");
    Serial.println(statusCode);
    Serial.print("Response: ");
    Serial.println(response);

    /*
    Typical response is:
    {"this":"succeeded",
    "by":"getting",
    "the":"dweets",
    "with":[{"thing":"my-thing-name",
      "created":"2016-02-16T05:10:36.589Z",
      "content":{"sensorValue":456}}]}
    You want "content": numberValue
    */
    // now parse the response looking for "content":
    int labelStart = response.indexOf("content\":");
    // find the first { after "content":
    int contentStart = response.indexOf("{", labelStart);
    // find the following } and get what's between the braces:
    int contentEnd = response.indexOf("}", labelStart);
    String content = response.substring(contentStart + 1, contentEnd);
    Serial.println(content);

    //There was a missing brace here. Was the code cut off?!
}

void setup(){
    Serial.begin(115200);
    while(!Serial);
    Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
    setConnection();
}

void loop() {
    dweet();
}


Break down your project into steps, both hardware and software, and tackle a step at a time.

First do a block diagram of the system, showing the different components, the layout of the control buttons, etc.

Then map out the desired behavior, perhaps using a flowchart. What should it do when you first turn it on? How will it respond to different button inputs? Will it continue to flash in the current pattern indefinitely until there's another input? Will there be a cancel button?

Then read up on how to power and control NeoPixel LEDs. I believe they use I2C? Are there any NeoPixel libraries you can use?

You might then try using a circuit simulator to create a virtual prototype of your circuit. Figure out how big a battery & voltage regulator you're going to need. (If you're running off of batteries you should use a switching or "buck" type voltage regulator rather than a linear voltage regulator since they are much more efficient. Just make sure you pick a regulator that can provide enough current for all your LEDs plus your Arduino, with a little extra left over.))

Once you get a virtual circuit working, it's time to use real hardware.

For a bike tail-light, you should think about how to make it weather-proof. are there waterproof enclosures you can use? What about waterproof NeoPixels? If there are no waterproof NeoPixels, what about waterproof enclosures with clear covers?

Buy the Arduino you're going to use, and at least a few of your NeoPixels. Work out how to control and flash a single LED. Then gradually add complexity to your project until you get it working.


NodeMCU Modbus interfacing with Pressure Multi-Switch

Now you have node.begin(1, Serial1), but you can't use Serial1 for RS485 because Serial1 doesn't have RX pin

According to the picture you wired the adapter to RX/TX pin of Serial, but this pins are wired on board to USB for communication with the computer (upload and Serial Monitor). You can't use Serial for RS485 adapter while you are using it for debug prints.

You can use SoftwareSerial fo example on D1/D2 for RS485.

Or if you have an USB-to-TTL-Serial adapter then you can use Serial1 for debug prints and Serial for RS485


This old and simple one has always worked for me on several Arduinos (but I haven't tried it on the MKR1000 specifically):
https://github.com/morrissinger/ESP8266-Websocket
I have forked it and made some changes, but nothing fundamental:
https://github.com/ocrdu/NINA-Websocket
Have a go, it just might work for you.


If you´re working with a development board, they (usually) come with tow buttons: Reset and Flash. If this is the case before start to upload your code you must press the Flash button, this error is common when the Flash button it's not pressed.

If you're working with an ESP8266-01 (this is the "naked" esp8266) you must read this tutorials: GreatScott vid on youtube, and for the connections: a good Hackster.io tutorial.

Hope you can make it run!!!


I think your problem is that you connected the positive wire to the 5v pin when it said 5v and not 9v. Also, I am assuming the 6 double AA is in series creating 9v. The thing is, double AA has a lot of amps. I tested it with my multimeter and it has 7 Amps, way to much. What I would do it connect a 9v battery to the voltage in pin-Vin. That pin can take a 9v but not 7 Amps produced by your 6 AA in series. You have 2 dc motors you said.Each is running I am assuming for each of them I notice draw about 1 Amp. 9v will supply enough and be safe. Try connecting a 9v to the Vin pin. I don't think your issue is software related.


it is how PWM works. digital pins can do only 1 and 0.


How can I run two Arduinos in sync for video generation?

I would take a look at MREtv which seems to promise all that you want to do, with just one arduino. This might not be the answer you're looking for, but getting threads to sync is a pain in the rear end, see this for explanation of why threads are a pain.

Now back on topic, it seems like MRETV might off what you want to do, and it can do some pretty impressive things from what I read in the arduino. You might need to modify the library a bit, but it offers already implemented encoding, so that is a plus.

http://www.instructables.com/id/MRETV-Video-Stereo-Sound-and-much-more-from-a-s/


So, after some close inspection I noticed that the blue potentiometer wasnt soldered in correctly. Also, its needs to be turned quiet a lot to have some effect. Might replace it completely. But now it works!


Pin 11 is shared between both PWM and SPI. By activating SPI you've disabled PWM from working on that pin. Either use another PWM pin instead, or switch to software SPI on different pins.


Is it possible to send 2 or more o/p signal at the same time?

Technically, it is possible to start two PWM outputs at the exact same
time on an Uno or Nano. If they are both controlled by the same timer,
you just have to update the corresponding control register once with
the relevant bits set to enable both channels. For example, you could
start outputs 5 and 6 simultaneously, as both are on Timer 0:
OCR0A   = value;  // set the duty cycle on OC0A = digital 6
OCR0B   = value;  // set the duty cycle on OC0B = digital 5
TCCR0A |= _BV(COM0A1) | _BV(COM0B1);  // enable both outputs

If the outputs are on different timers, it is a bit more tricky. Timers
0 and 1 can be synchronized by clearing their shared prescaler with the
Timer/Counter Synchronization mode active. I do not think there is a
simple way to synchronize Timer 2 with any of the others.
All this is highly hardware-dependent, and not supported at all by the
Arduino core library. Thus, if you want to apply any of this, you will
have to study the datasheet, and poke directly into the I/O
registers of the microcontroller.
But then, as Delta_G clearly points out in his answer, all this is
irrelevant to motor control. Motors are mechanical devices that have
significant inertia. They take time to speed up and slow down. Just to
give you a sense of scale, PWM outputs 3, 9, 10 and 11 deliver a square
wave with a period of 2.04 ms. Yes, those are milliseconds, and
this is too short for the motors to significantly change their speed
within one period. Contrast this with the handful of microseconds,
that the call to analogWrite() will take.


How do i send data from a Master to another Master?

Both your master devices must support Multimaster mode, i.e. Arbitration and Synchronization. See I2C Spec here for a description of the arbitration process.
It's up to you to handle a lost arbitration in your software.

  or are there other solutions to have the ESP32 communicate to the
  ATMega?

Of course. As you considered I2C to be sufficient, UART and SPI are feasible alternatives supported by almost all microcontrollers.


Sending digital signal from one arduino to another

OK , start by connecting an LED at the Output of Arduino 2 pins .. ( hopefully it will glow )

Measure the current out of the output pins of Arduino 2 too


What is the physical location of the U1A symbol on Arduino Uno?

The op-amp is a LM358 so you can look at the ICs themselves. Also it's a dual comparator with 8 pins. On my example image below you can see it below the crystal. I can't comment if that's the correct way to sense what you need, but it seems the comparator output should be 1 if there is external power applied. You could check with a multimeter.


How do I make my LCD screen scroll text while allowing for button input?

See my answer to a similar question - about motors but the idea is the same. You call a function for each piece of the job that needs to be done. The function itself decides whether it needs to be done yet, and if so, does it and returns, otherwise it just returns. The loop() function just calls all your other action functions and does nothing else -- all of the real work takes place in those functions.
Looking at your scrolling code, I think one function could print successive pieces of the message by remembering what did last. Another could read and debounce the button(s) and save its/their state.
And once you get to controlling the infusing process, one (or maybe more) functions could be used to control that.


Basic WiFly server returning unexpected output within web client

Your browser sent a HTTP GET request. You need to send a HTTP response in kind, in accordance with the protocol, for your browser to correctly interpret the data. Something like this should do:

  #define TIMEOUT 100
  char response[] = "
Hi

This is text.
";
  unsigned long lastRead;
  ...

  while (client.connected()){
    if (client.available()){
      lastRead = millis();
      while (millis() - lastRead < TIMEOUT){
        while (client.available()){
          Serial.write(client.read());
          lastRead = millis();
        }
      }
      client.println("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: closed\r\n\r\n");
      client.print(response);
      break;
    }
  }
  delay(1000);
  client.stop();

EDIT:

It turns out that the Wifly shield sends a response status as well as "HELLO" by default. You have to disable that with a few commands:

set comm remote 0
set comm open 0
set comm close 0

This will ensure that "HELLO" isnt sent each time a client connection is made, though I'm not sure if this affects the default HTTP/0.9 200 OK response status that is always sent. You can try the sketch above with and without the response header to see what you get.


Connecting 4 servos, 2 motors, hc-05, sr-04 and L293D to Arduino

1) Is 6V supply enough for 4 servos and 2 dc to work?

If the motors are 6V motors then 6V is not only enough, it is what you need. What you should be asking is "Can my power source provide enough current.

  2) Is the connection between L293D and 2 DC motors correct?

Not quite. You have only got half your grounds connected up. Also 3,4EN should be connected to Vcc1 not Vcc2.

1A/2A and 3A/4A are the direction/break pins (one high and one low for a direction, both low for break). The EN pins can be (if you wish) used to control the speed with PWM (if you have any spare) - if not then they should be tied to the logic supply voltage, Vcc1, not the power supply voltage, Vcc2, since that can be up to 36V and is way too high for logic inputs like EN.


Sparkfun OBDII - Arduino Uno Stuck at 832RPM-13Kmh

after 1 week of try i finally solved it :)
As you guys know UNO has 1 i/o serial port, and Sparkfun's OBDII board doesn't work on same i/o serial port (at least i couldn't be able to), with uno when you send a command through serial to obd board you need to wait minimum 3 seconds to send another command or car's can-bus thinks that you canceled the first command returns STOPPED error, but with MEGA it works perfectly because mega has 3 i/o serial ports. You simply define Serial(TX)-Serial1(RX) and it works perfectly with 75ms delay.
Here is the working code.
//Set up ring buffer
char rxData[20];
char rxIndex = 0;
int rpmstored = 0;

    void setup()
    {
      Serial.begin(9600); // prints to serial monitor
      Serial1.begin(9600); //Hardware serial connection to the obdii uart
      OBD_init(); //initiates obd link
      delay(3000);
    }

    void loop()
{
rpmstored = getRPM();
//int mph = (int)((getSPEED() * 10000L + 5) / 16090); //convert to mph
//  Serial.print (mph);
Serial.print("S:");
Serial.print (getSPEED());
Serial.print (",");
Serial.print("R:");
Serial.println (getRPM());
//Serial.print (",");
//Serial.print("W:");
//Serial.print (getWATERTEMP());
//Serial.print (",");
//Serial.print("O:");
//Serial.print (getOILTEMP());
//Serial.print (",");
//Serial.print("F:");
//Serial.print (getFUEL());
//Serial.print (",");
//Serial.print("V:");
//Serial.println (getVOLT());
delay(100);
Serial.flush();
    }

    void OBD_init(void)
    {
      //Wait for a little while before sending the reset command to the OBD-II-UART
      delay(2000);
      //Reset the OBD-II-UART
      Serial1.print("ATZ\r");
      //Wait for a bit before starting to send commands after the reset.
      delay(2);
      OBD_read();
      Serial1.print("ATE0\r");
      OBD_read();
      //Serial1.flush();
    }

    int getRPM(void)
    {
      //Query the OBD-II-UART for the Vehicle rpm
      Serial1.flush();
      Serial1.print("010C\r");
      OBD_read();

      return ((strtol(&rxData[6], 0, 16) * 256) + strtol(&rxData[9], 0, 16)) / 4;
    }

    int getSPEED(void)
    {
      //Query the OBD-II-UART for the vehicle speed
      Serial1.flush();
      Serial1.print("010D\r");
      OBD_read();

      return strtol(&rxData[6], 0, 16);
    }

    int getOILTEMP(void)
    {
      //Query the OBD-II-UART for the vehicle speed
      Serial1.flush();
      Serial1.print("015C\r");
      OBD_read();

      return strtol(&rxData[6], 0, 16);
    }

    int getFUEL(void)
    {
      //Query the OBD-II-UART for the vehicle speed
      Serial1.flush();
      Serial1.print("012F\r");
      OBD_read();

      return strtol(&rxData[6], 0, 16);
    }

    int getVOLT(void)
    {
      //Query the OBD-II-UART for the vehicle speed
      Serial1.flush();
      Serial1.print("0142\r");
      OBD_read();

      return strtol(&rxData[6], 0, 16);
    }

    int getWATERTEMP(void)
    {
      //Query the OBD-II-UART for the Engine Coolant Temp
      Serial1.flush();
      Serial1.print("0105\r");
      OBD_read();

      return strtol(&rxData[6], 0, 16) - 40;
    }

    void OBD_read(void)
    {
      char c;
      do {
        if (Serial1.available() > 0)
        {
          c = Serial1.read();
          if ((c != '>') && (c != '\r') && (c != '\n')) //Keep these out of our buffer
          {
            rxData[rxIndex++] = c; //Add whatever we receive to the buffer
          }
        }
      } while (c != '>'); //The ELM327 ends its response with this char so when we get it we exit out.
      rxData[rxIndex++] = '\0';//Converts the array into a string
      rxIndex = 0; //Set this to 0 so next time we call the read we get a "clean buffer"

    }

I only need RPM & Speed that's why i comnented out other parameters but tested all and works perfectly.


Arduino - Calculating the time for which a Pushbutton is pressed and held without being released

There is a library called "Debounce", which you can find here: playground.arduino.cc. Based on that library, here is a simple sketch that displays the amount of time a button is pressed.

// Connect one end of a N.O. push button switch to GND and the other
// end to pin 4 of the Arduino.
// NOTE: If the button is held down for less than the debounce delay
//       time, the elapsed time will display the debounce delay time.
#include <Debounce.h>
const byte SWITCH = 4;
unsigned long startTime = 0;
unsigned long endTime = 0;
unsigned long elapsedTime = 0;
const byte debounceDelayTime = 50;

Debounce debouncer = Debounce(debounceDelayTime, SWITCH);

void setup(){
  Serial.begin(9600);
  pinMode(SWITCH, INPUT_PULLUP);
}

void loop(){
  if(debouncer.update()){
    if(debouncer.read() == 0){
      startTime = millis();
      Serial.println("Button Pressed");
    }
    else if(debouncer.read() == 1){
      endTime = millis();
      Serial.println("Button Released");
      elapsedTime = endTime - startTime;
      Serial.print("Button Held Down For ");
      Serial.print(elapsedTime);
      Serial.println(" ms.");
    }
  }
}


Depends on the voltage that is on that mute pin. If it's below 5 volt, you could use the arduino pin. You can measure the voltage using a multimeter.

If it's more than 5v you can use a NPN transistor and resistor combination.

Current isn't a problem with these kinds of "settings" pins, as there is just a pull-up resistor that by default (unconnected) sets the pin to HIGH. By connecting the pin to ground you set the pin to LOW.


Yes, the library

https://github.com/bportaluri/WiFiEsp

Is suited for your task because it implements talking to a ESP8266 over a software serial. On this serial connection, AT+ commands will be sent. This also means that you must have the AT firmware flashed onto your ESP-01.

If that is not the case you can download the binary image here and flash it with a serial adapter, as instructed with the tools on that page. You can check whether your ESP8266 has the firmware flashed by attach a UART adpater to the TX output. It should print a "ready" on bootup.

For your wire-up, you will just have to add VCC (+3.3V), GND, TX and RX connections to the ESP-01 board, preferable with a big capacitor between VCC and GND, as the ESP8266 draws a lot of power when sending data over WiFi.


Sim900a AT+HTTPREAD does not get fully answer

Apparently you were running software serial at too high of a baud rate (57600) and bringing it down to 9600 fixed the issue.


Communicating and Encryption are to completely separate things. How you communicate (with what device) has no relevance to encryption. True, there are devices that can themselves encrypt data, but they tend to be higher-end or geared towards a specific purpose (such as WiFi).

What you send is just data. What that data consists of is entirely up to you.  If you want your communications encrypted then send encrypted data before sending it and decrypt it after receiving it.

Of course, you have to then consider such things as sharing of keys, etc.

There are numerous ways of encrypting data, but one of the easiest to implement on Arduino is AES, for which there is a library here.


Detect if Serial1 and Serial2 are defined, at compile time

HardwareSerial.h in Arduino AVR boards core defines HAVE_HWSERIALX

example

#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif


Client or WiFiClient wrapper for adafruit CC3000 wifi

As I didn't get any answer, and further search for an existing solution failed, I decided to roll my own. The class header is very straightforward, I decided to go for single inheritance and composition of Adafruit_CC3000_Client:

class CC3000Client: public WiFiClient {
public:
    CC3000Client(Adafruit_CC3000& cc, Stream& stream=Serial);
    virtual ~CC3000Client();

    virtual int connect(IPAddress ip, uint16_t port);
    virtual int connect(const char *host, uint16_t port);
    virtual uint8_t connected();
    virtual int available();
    virtual void stop();
    virtual void flush();
    virtual int peek();
    virtual int read();
    virtual size_t write(uint8_t v);
    virtual size_t write(const uint8_t *buf, size_t size);
    virtual int read(uint8_t *buf, size_t size);
    virtual operator bool();

private:
    Adafruit_CC3000& cc3000;
    Adafruit_CC3000_Client client;
    bool peeked;
    int peeked_byte;
    Stream& stream;
};

The implementation is a bit tricky (or I didn't manage to find a better way), as the Adafruit client does not have peek() functionality, so this wrapper class have to implement it.

CC3000Client::CC3000Client(Adafruit_CC3000& cc, Stream& stre) :
        cc3000(cc), peeked(false), stream(stre), peeked_byte(0) {
}
CC3000Client::~CC3000Client() {
}

int CC3000Client::connect(IPAddress ip, uint16_t port) {
    client = cc3000.connectTCP((uint32_t) ip, port);
    peeked = false;
    if (client.connected())
        return 1;
    return 0;
}
int CC3000Client::connect(const char *host, uint16_t port) {
    uint32_t ip = 0;
    if (!cc3000.getHostByName((char*) host, &ip)) {
        stream.println(F("Couldn't resolve!"));
        return 0;
    }
    client = cc3000.connectTCP(ip, port);
    peeked = false;
    if (client.connected()) {
        return 1;
    }
    return 0;
}
uint8_t CC3000Client::connected() {
    return (uint8_t) client.connected();
}
int CC3000Client::available() {
    if(peeked)
        return 1;
    return (int) client.available();
}
void CC3000Client::stop() {
    peeked = false;
    flush();
    while (client.connected()){
        client.close();
        delay(10);
    }
}
void CC3000Client::flush() {
    peeked = false;
    while (connected() && available())
        read();
}
int CC3000Client::peek() {
    if (!peeked) {
        if (available()) {
            peeked_byte = read();
            peeked = true;
        } else
            return -1;
    }
    return peeked_byte;

}
int CC3000Client::read() {
    if (peeked) {
        peeked = false;
        return peeked_byte;
    }
    return (int) client.read();
}
size_t CC3000Client::write(uint8_t v) {
    return (size_t) client.write(v);
}
size_t CC3000Client::write(const uint8_t *buf, size_t size) {
    return client.write(buf, size);
}
int CC3000Client::read(uint8_t *buf, size_t size) {
    if(peeked){
        buf[0]=peeked_byte;
        peeked=false;
        return client.read(buf+1, size-1);
    }
    return client.read(buf, size);
}
CC3000Client::operator bool() {
    stream.println("Error, bool() not implemented");
    return true;
}

Both files are available here, if you are using biicode all you have to do in your code is to put an include like the following and run "bii find", that will also retrieve and install the cc3000 library:

#include "diego/ardunet/cc3000client.h"

I have used and tested it with a simple http_get call (also here) and with the temboo service, and it has worked OK for sending emails from a Gmail account from an Arduino Mega2560 connected to the CC3000. This temboo service uses via the SDK Client interface most methods of this wrapper, but the bool() operator and the CC3000Client::write(const uint8_t *buf, size_t size) method.


How to get the overall average of the data received

void setup(){
Serial.begin(9600);
}
void loop(){
    static unsigned long count=0;
    static float sum=0;
    float ave=0;
    int volt=analogRead(A0);
    float voltage = map(volt,0,1023,0,2500) / 100.0;
    Serial.print("Voltage: ");
    Serial.print(voltage,2);
    sum=sum+voltage;
    count++;
    ave=sum/count;
    Serial.print("  Average: ");
    Serial.println(ave,2);
    delay(3000);
}

This runs quite a while. The average is restarted only with a Reset of your arduino.

Alternatively, you might want to learn about a moving average (aka low pass filter)


mega2560- Interrupts reading digital input

There isn't any interrupt code in what you posted. What exactly is the problem?  One important note is that you shouldn't try to print to Serial line in the interrupt handler as serial is itself driven from interrupts which are switched off during your handler code.  If all you really want to do is to print something every 10ms then you don't need any interrupt.  Just use the "Blink Without Delay" style of timing and keep the other code from blocking.


Serial monitor doesn't work with piezo buzzer

Pin D10 of NodeMcu is io 1 which is RX pin of Serial interface of the esp8266. Serial is on NodeMCU connected to USB. The pin is on board labeled RX.

D8 is boot config pin io 15. It must have pulldown on board. The pulldown can disturb the input on this pin. Use D6 (io 12) as echoPin.


Using LM70 temperature sensor with Arduino

There are several things that are not doing correctly. This is not a complete answer but to provide you some directions on how to get it right.

A0 is pin 54, it is not SS which is pin 53;

On how to use the SPI library properly, I would suggest that you read my blog on SPI, it will also help you to get the data out of data sheet that you need for SPI programming. Based on the timing diagram on the data sheet, you will need to configure the SPI as SPI_MODE2;

LM70 SI/O pin is used as both MOSI and MISO, you will need to connect MOSI to SI/O via a 10k resistor, and connect SI/O direct to MISO, this information is available in the data sheet;

LM70's temperature data is in Two's complement format, To convert it, it needs a little bit work. It is then need to shift down/right using bitshift operator by 5 bits to get ride of the first 5-bits, before finally multiply by 0.25C as per data sheet.

int value = 0x4b1f;  //value from SPI, temp = 125 degree C
int mask = 0x8000;   // mask for MSB
int temp = (-(value & mask) + (value & ~mask)) >> 5;
Serial.print("Temp");
Serial.println(temp*.25);

Read all links that I provided to understand the subjects and give it a try. Good luck!


Your strip has 2 LEDs with different color temperature directly besides at the same spot for every element of the strip. So the adjusting of the overall color temperature is done by changing the relative brightness of both LEDs. If the LED with the warmer light is brighter, the overall color temperature will also be warmer. Common Anode means, that V+ is the connected to the positive pin (anode) of both LEDs, so it has to be connected to +24V. The electrical circuit is completed by connecting the pins W and C (Warm and Cold) to ground. To control the individual brightness of the warm and cold LED groups, you have to use PWM.

You are right, that an Arduino cannot handle currents this big. You need a transistor for this. I would suggest using a MOSFET, since this is the easiest and most efficient possibility. By one MOSFET for every channel (Warm and Cold), which is capable of handling the needed power (Important! Or you will fry the MOSFET). Also it should be a logic level MOSFET, that is well in saturation of the gate voltage for the output voltage of your Arduino. Connect the MOSFETs Drain pin to the channel on the strip, the Source pin to ground of your power supply and the Gate pin to a PWM pin of the Arduino. Also connect the ground of the power supply with the ground of the Arduino.

Now you can control the brightness of the Warm and of the Cold LEDs by adjusting the PWM duty cycle with the Arduino.


There is little information on the Amazon page about these devices.  Only that the output is digital (only on and off) and that the sensitivity is controlled manually by an on board pot.  It would appear impractical to enhance this type of device with out detailed specifications and / or a schematic.

If you would prefer using software to solve some of the problems you listed, I would suggest you use an IR parallax (not the company, the technique) distance sensor with an analog output.  That way the Arduino Uno's analog input can be used to read the sensor and software (sketch) can process (filter) the data before it is put to use.

Added later...

Here is an article describing how to use an IR parallax distance sensor.  Here is an Arduino library design to work specifically with the Sharp IR parallax distance sensor.


PWM should be applied to ENA or IN1/IN2 for L298N board for speed control

I'd use PWM on EN input. Motor will be driven in HIGH and left floating in LOW. The other method means it'll be shorted (= full on brake).

L298N is based on bipolar transistors. That means relatively big voltage drop between drivers Emitter and Collector (about 2V on each transistor), so there are big power losses (= heat).

Maybe something like LMD18200 could be used as unipolar replacement.


Programmatically Upload Arduino Sketch From Android App

If I wanted to do this for a conventional Arduino I'd start by figuring out the operations against a serial API to talk to the bootloader, and perhaps test it against something exposing desktop serial ports to Java, as debugging Android host mode stuff is a pain given you have to use ADB-over-wifi. You might try to figure out how avrdude works, for example. Then I'd try to combine that with existing code that is out there for talking serial-over-USB to Arduino boards with the various device-side chipsets. For a leonardo type board the two pieces may be more tightly coupled.

Copy of Chris Stratton's comment which was acknowledged as an answer.


What is the correct way to interpret the built-in Analog-to-Digital Converter output?

the Atmega328P's datasheet, it indicates the conversion factor is
  5V/1024 [...]

Indeed. And the datasheet is the only authoritative source. All the
other sources are second-guessing.

  If Vin and Vref are 5V, then the ADC reading would need to be 1024 in
  order to have a true reading of 5V

You can't get a true reading of 5 V. As per the datasheet (emphasis
mine): “0x000 represents analog ground, and 0x3FF represents the
selected reference voltage minus one LSB”.

Any input voltage larger that the maximum representable voltage will
read as 0x3ff (i.e. 1023), just like any negative voltage (within
the forward voltage of the protection diode) will read as zero. Thus,
reading either 0 or 1023 should be interpreted as a saturation
of the ADC, meaning the actual voltage is unknown.

  The ADC is inherently sampling, and I am not sure if the ADC rounds
  up/down to the nearest value

In principle it should round to the nearest value. The transition in the
reading from 0 to 1 should ideally happen at
Vref/2048. C.f., again, the datasheet, subsection “ADC
Accuracy Definitions”: “Offset: The deviation of the first transition
(0x000 to 0x001) compared to the ideal transition (at 0.5 LSB).”

A little bit further in the page it is stated that the ideal position of
the last transition (1022 to 1023) is “at 1.5 LSB below maximum”.

  Perhaps I am splitting hairs since the absolute accuracy of the ADC is
  "±2 LSB absolute accuracy"

Indeed. If you really care you should probably calibrate your ADC. See
Response of the Arduino ADC.

Edit: in a comment you mention that the factor 1024 could
conceivably be “a persistent typo that it appears in multiple AVR
chipset datasheets”. It may be an error, but certainly not a typo, as
the datasheet contains multiple independent statements that confirm the
factor 1024.


Detect button on a ground line (reverse eng)

It sounds like you might have a PCB with debounced switches on them. One such circuit for debouncing switches looks like this:

That circuit and more about switch debouncing can be found here.

A debouncer basically masks the problem of switch "bounce" which is what happens when the contacts get close and the circuit is quickly closed and opened in rapid succession until a firm connection is obtained. Its a natural problem  mechanical switches.

If that's not quite right, maybe you could help us help you better by posting a photo of the board in question.


Since you are sending from the Arduino the received serial data back to the C# application (Serial.print(message);), I would advise to check what you receive on the C# side.
Register to the DataReceived event of the SerialPort as so:

serialPort1.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

And add an event handler:

private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
    SerialPort port = (SerialPort)sender;
    string data= port.ReadExisting();
    // check here what data you received, if any
}

This way you could confirm that the Arduino gets the data properly from the C# side to begin with. Next step would be to understand if this if statement treats the data properly:

if (message == '5')

But starting from examination of what you get from the C# side will help you decide where exactly is the problem.


Default sketch working but arduino is not recognizing

Hahaha! I figured it out! The USB connector on the board's side was loose connected! It didn't felt like more pressable & when I pressed it enough, it firmly fitted.

When it loose connected, the board connects power only.

The drivers were installed automatically & it showed under COM6. I've got sketches running in no time.
I' ve tried a lot of knight rider patterns with a bunch of RGB LEDs then ;-)

Thank you @Majenko and the arduino stack exchage for your kind replies.


It is possible to have some success with this, but keep in mind that the longer the wire, the higher the inductance and voltage drop across the wire. Prefer to use a star topology rather than a chain topology, with the Arduino in the middle of all the shields in use.


Two Leonardos on one USB hub - not working properly

There is no reason I can think of that would stop it working as it should.

lsusb is showing both the devices, so they are being detected by the kernel.

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

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

The important bit is the I: lines - they show the individual USB interfaces and what kernel driver has been associated with them.   For the keyboard, of course, it's the last entry, which is assigned to the usbhid driver.

Another good diagnostic is dmesg -w

Run that with both Leonardos disconnected.  Plug one in and it should show it registering as a USB device.  A few moments later you should get a pair of lines like:

[ 2106.937086] input: Arduino LLC USB IO Board     as /devices/pci0000:00/0000:00:1a.7/usb1/1-1/1-1.4/1-1.4.1/1-1.4.1:1.2/0003:2341:0036.0006/input/input21
[ 2106.990523] hid-generic 0003:2341:0036.0006: input,hidraw4: USB HID v1.01 Mouse [Arduino LLC USB IO Board    ] on usb-0000:00:1a.7-1.4.1/input2

That is the board being associated with an input device (in this case input 2).

Repeat it with the second Leonardo and see if the same appears, but this time with a higher input number (it would be 3 on mine if I had a second Leonardo).

The fact that the two Leonardos work together normally means that they should be working fine in any arrangement, so if the OS is seeing it all fine but the data isn't getting through, then my money is on the hub.  It looks quite a new hub, so it may have a few bugs in it that are yet to be ironed out.

USB devices are identified to the drivers using the VID and PID, but to the kernel the USB device is just a chain of bus/port numbers.  For instance my Leonardo above is identified as:

1-1.4.1

That's USB bus 1, downstream port 1 (root hub - normally only has 1 port), which connects to a hub (the one built into the computer to drive multiple ports) which then has downstream port 4 connecting to a hub (on my desk) which then has downstream port 1 connecting to the device.  Nothing else can be connected to that same combination of downstream ports - it's physically impossible, so it's uniquely identified.


As @IgnacioVazquez-Abrams said, a 16u4 is virtually identical with a 32u4, so you can use a Leonardo or Micro core with a tiny modification to boards.txt. A 16u2 is a rather different animal, with fewer timers, many fewer pins, and no A/D converter, so you’d have to do a fair amount of editing to obtain a usable Arduino core.

That said, if you’re reasonably fluent in C++, building your own Arduino core is not very difficult, and I found it an instructive exercise. If you care about getting your project up as quickly as possible and not get sidetracked, however, go with the 16u4.


Not able to get response from esp using Arduino uno

SoftwareSerial ESP(0,1); // RX, TX

Pins 0 and 1 are hardware serial on the Uno, used with the Serial object, these pins are used to communicate with your computer (e.g. Serial Monitor) via the USB-serial chip on the Uno.

There is absolutely no reason you should ever use SoftwareSerial with pins 0 and 1. If you want to use software serial then connect the ESP8266 to pins other than 0 and 1. Otherwise don't use SoftwareSerial at all, but be aware that using Serial to communicate with the ESP8266 and with the computer is problematic and can also cause issues when you try to upload to your Uno.


Make device based on CH340G working as keyboard

No, it's not possible. The device enumerates as a USB serial device, and the only way to change that is to change the internal silicon of the device.

The closest you could do is (though I have no clue how on Windows) write (or if you are lucky, find) a program that reads serial data through the COM port and somehow injects keyboard commands into the input subsystem of the operating system.


What is using up all the RAM in my program?

There is a lot you are missing.  Such as:

SoftwareSerial is using RAM.
The system stack is using RAM.
The Arduino core software is using RAM.

There's plenty more going on than just your sketch. For instance, where do you think it stores the current millis() and micros() counts? Where do you think incoming serial data gets buffered? Where do you think your registers, PC, etc, get stashed when a function (such as setup()) is called? All that takes RAM.


Did you change the firmware? I think Baud rate can be changed only if you flash it with newer version of the firmware.


Use object of LiquidCrystal class within another class

You must also include LiquidCrystal.h in your sketch. That way the IDE will know to include it in the list of files to compile and link with your sketch.


When you go below (or above) the manufacturer's voltage/clock specifications, expect some problems. One chip may work another will not.  Remember the lower the voltage normally the slower the clock needs to be.  The CPUs are cut from a wafer (size and geometry specific) which may contain many thousand CPU die, they are at different locations on the wafer they will be a little different and they make more then one wafer.

Check the data sheet, it will show what clock speed will work at what voltage.  As the CPU clock changes so will your baud rate so plan on recalculating that if you change the clock. Example:  If you are operating with a 16MHz clock and change it to 8MHz the baud will be exactly 1/2.  If at 9600 it will be 4800 unless you modify the clock dividers.

Your error indicates a potential baud rate problem. One of the funny things that happens when the voltage is above/below the manufacturer's speck not all instructions operate properly over temperature. Clock problems should be expected.


Possible to connect 3 MPU9250 to Node MCU without multiplixer?

It sounds like the MPU9250 has a pin, AD0, that lets you switch the device between 2 fixed I2C addresses.

That gives you an easy solution if you need to use 2 of them.

For more, the post you linked suggests keeping them all at the same AD0 state except the one you want to talk to. You’d switch that one’s AD0 pin to the other state, which would cause it’s I2C address, and then talk to it at that address, which would be unique on the I2C bus.

That approach should work, but it’s a bit of a hack.

You say "I have connected 2 sensor as test. SCL & SDA of both parallel with D1 & D2 of node mcu. Then connected AD0 of both sensors to different I/O pin of node mcu but it didn't work." What didn't work? What happens? What output do you get What pins on your mcu are connected to AD0 on your 3 different MPU9250 modules? Where is the code that manipulates the digital pins to select one and only one of your MPU9250 modules for reading?

You need to throughly explain your setup, including the different pin assignments and how they are supposed to work. Don't leave us to read your code and try and figure out your intentions.

Looking at your code it looks like you're using D7 and D8 on your mcu to try to control which MPU9250 is active. However i don't see any code the sets D7 and D8 as outputs.

Why don’t you want to use an I2C address mapping chip? They are readily available, and the ones I’ve seen would let you address up to 8 I2C devices that are hard-wired with the same address.


Here is a schematic;

You may also find those links useful;

Link#1

Link#2

P.S. Please do little bit a google search. There are many samples and schematics all over the place.


The slow clockr is primarily used for the real time clock (RTC) module inside the SAM3X chip.  It can also be routed to other places when you want a low speed clock source, but the only places it is actually required are the RTC and the watchdog.

The slow clock can be generated from an internal RC oscillator instead of requiring an external crystal, but the accuracy and stability of the RC oscillator is many orders of magnitude worse than a crystal.  Trying to use that for the RTC module will result in the clock drifting over time.  The watchdog won't really care if the clock isn't perfectly accurate.


Random numbers being printed back after entering data

The problem is that you are blindly reading serial data without first looking to see if there is actually any serial data available to read.

If there is no data there Serial.read() will return -1.  Since you have only provided a snippet of your program I can't say what data type inbyte is, but my guess is it's some form of unsigned 32-bit value, since -1 mapped into an unsigned 32-bit value is 4294967295.

You need to be checking the presence of data, and only reading when you should read, and also looking for the end of your data sequence (add some terminating character, like a line feed) to know when to stop looking for and reading characters.


if (sensorValue = 0) {

That assigns zero to sensorValue, which then tests false. You want:

  if (sensorValue == 0) {


In the setup(), you have:
Serial.print("Hello World!");
Serial.begin(9600);

One should avoid printing to the serial port before enabling it with
Serial.begin().


Scroll LCD display connected to an Arduino Uno

I would do the following (beware - not tested):

lcd.clear();
lcd.setCursor(15, 0);
lcd.print("x");
for (int i = 0; i < 15; i++) {
    lcd.setCursor(0, digitalRead(switchPin) == LOW);
    lcd.print("5");
    delay(500);
    lcd.scrollDisplayLeft();
}


Can we use Arduino mini in eagle to create new custom modal

From https://www.arduino.cc/en/Main/FAQ#toc8:

I want to design my own board, what should I do?
The reference designs for the Arduino boards are available from their specific product pages. They're licensed under a Creative Commons Attribution Share-Alike license, so you are free to use and adapt them for your own needs without asking permission or paying a fee.

You can find the board design files on the Documentation tab of each product page.
Arduino Mini product page:
https://store.arduino.cc/arduino-mini-05
Arduino Nano product page:
https://store.arduino.cc/arduino-nano


Can not receive data from UART with stepper motor

If you look at AccelStepper.cpp code of the library you're using, you'll notice that runToNewPosition() is:

void AccelStepper::runToNewPosition(long position)
{
    moveTo(position);
    runToPosition();
}

which, in turns calls:

// Blocks until the target position is reached
void AccelStepper::runToPosition()
{
    while (run())
    ;
}

In turn, run() returns false only when the position is reached, as shown here:

boolean AccelStepper::run()
{
    if (_targetPos == _currentPos)
    return false;

    if (runSpeed())
    computeNewSpeed();
    return true;
}

As you can see, your program is blocked until the position is not reached.

Data can be still received by the serial port (until buffer is exceed), but you won't be able to read it until that while ends.

To make the motor running without blocking the program, you should implement the AccelStepper functions in the loop function, in a non-blocking way.

In particular, (I only help you to set the position to 1100. You'll make the effort to bring it back to 0, with small modifications), in rotate_motor() call only:

stepper1.moveTo(1100);

Then in the loop, write somewhere:

stepper1.run();

EDIT:
Hint for having the motor moving forward and then backward as in your original code:
Add a state variable (say you call it "m"), where you store if you need to move forward (e.g. 2), backward (e.g. 1) or stop (0). Then, before calling stepper1.run(), check if you actually must move (if (m != 0)). When you call the stepper1.run() method, check if it returns false. In this case it means it reached the position, then you must change the value of m accordingly.


How to calculate actual Baud Rate and its percent error?

First, look at the code used by the Arduino core library to configure
the USART baud rate register: it's in
HardwareSerial::begin(). The general formula is
uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;

but beware of the hard-coded exception. You can replicate that part of
the code in your own.
Then, look at the ATmega328P datasheet. More specifically, at section
24.4.1. Internal Clock Generation – The Baud Rate
Generator. Here you find the formula
BAUD = F_CPU / (8*(UBRR0 + 1))

assuming the U2X0 bit has been set (again, beware of the hard-coded
exception). Combine both formulas and you get the actual baud rate.


SoftwareSerial can only listen to one port at a time. You cannot listen to both, no way. To really listen to both, you need an Arduino with more hardware Serial ports, where most of the protocol is done in hardware, thus can receive without CPU intervention. The Arduino Mega has 4 hardware Serial ports.

Or you could impose a protocol on the Serial stream to make the listening Arduino the master. You would listen to the first serial interface, send a start byte over this interface, that tells the slave Arduino to start sending. It sends and the listening interface receives (The transmission has to be delimited by either a time limit, e.g. listen for a specific time, or by a stop byte). Then you listen to the next interface, send again the start byte and receive. And so on.

With such a protocol, you could even use a single serial interface. The protocol makes sure, that only one slave is transmitting at a time. Though you should add resistors to every slave to protect their TX pins.

  in real system I need to listen 6 ports

Serial (UART) is really not the best interface type for such topology. You should consider using interfaces like SPI. It doesn't need additional electronics and is better fit for multiple slaves.


Can i use Arduino IDE with the Wemos D1 R2 AND also use its ESP8266 module to send AT commands?

A year ago I ported my project from Uno with esp8266 (Uno WiFi Dev Ed) to Wemos D1 R2.

Wemos D1 R2 board has esp8266 as the only MCU. The AT firmware is an application running in the esp8266. An Arduino sketch with esp8266 boards package is an application too, so it replaces the AT firmware.

Instead of AT commands you will use for networking the WiFi library of the esp8266 arduino package. It is much simpler and there are many examples.

The esp8266 and the D1 R2 board have 3.3 V logic level on pins. So be careful with inputs and check if your devices will read the 3.3 V as HIGH.

In code use Dx constants matching the labels on the board. D1 R2 has less pins then Uno. I recommend to use I2C devices if possible. I had a Grove Base shield on D1 R2, so I have a mapping of D1 R2 pins to 'Uno' pins.

Some of the esp8266 pins are read at boot as boot configuration. Pins D3 (io 0)
and D4 (io 2) have pull-up on board and pin D8 (io 15) has pull-down on board. Not all devices will work on this pins. Here is a pin overview of the NodeMcu and Wemos boards.

The esp8266 has only one ADC pin. The A0 of the esp8266 can read 0 to 1 V. Wemos boards have a voltage divider on A0 so the board's pin can read 0 to 3.3 V. Don't read A0 in every loop. WiFi part of the esp8266 uses the ADC hardware too and continuous reading of A0 interferes with WiFi operations.

The Wemos D1 R2 has a strong power regulator 7 to 20 V for Vin and power jack. You can power devices from 5V and 3.3V pin. I use Grove relay modules powered from 5V pin and controlled by logic signal at 3.3 V.


Any way to use F macro with a passed variable?

There is a special type for just this occasion - the __FlashStringHelper type.

void displayMenu(const __FlashStringHelper *txt, byte var) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(txt);
  lcd.setCursor(0, 1);
  lcd.print(var);
}

Note I removed the & from var - you don't want that unless you are passing a complex class or are wanting to modify the contents of var in the function and have it reflected back outside the function.  Passing a reference to a byte (&var) requires two bytes of data - just passing the content of a byte only requires one byte of data.


Make an Arduino board act as both a usb storage device and a keyboard?

The Leonardo can easily be used as a keyboard. There are also special codes to turn the USB-to-Serial chip on newe Unos into a keyboard (see here)

USB mass storage is another game all together. The Brondani EasyUSB is a simple chip that exposes 2MB of storage space on both the USB and microcontroller. They say they will be releasing larger capacities.

The easyUSB also has a serial link built into it from uC to computer.

If you really want, you can make your own USB stack to handle this on you own, but the pitifully small amount of ram on these chips would prohibit it.


Problems stopping an if loop, and starting it as well

There are two major flaws with your program - and both of them can be "fixed" by you understanding some concepts better.

Firstly, in your program, there is no concept of "When the button is pressed", only "While the button is pressed".  This is caused by an error in your understanding of how reading of buttons needs to be done.

The digitalRead() function will return the current state of the button at that precise moment in time. It has no concept of "This has just been pressed", only "This is currently pressed".  So you need to remember in what state the button was last time you looked at it, and only if it has changed do you do something to react to it.  The same with the releasing of the button - at the moment it only knows that it isn't pressed, not that it was pressed but is no longer pressed.

The second problem is that of state, and is closely coupled with the fixing of the reading of the buttons.  At the moment the state of your arduino (i.e., what it thinks it should be doing at the moment) is entirely defined by what buttons are currently being held in or not held in at any one time.  Instead the buttons need to be used to set flags that tell the Arduino what it should be doing and when - such as a flag that says "You should be moving the servos".  Such an arrangement is called a finite state machine and is one of the simplest ways of getting something small like an Arduino to do multiple things at once - in this case reading what is happening to the switches whilst at the same time making motors do different things.

For more information on finite state machines you might like to cast your eye over this: http://hacking.majenko.co.uk/finite-state-machine


How can I read a piezo sensor and have it output a fixed voltage?

A piezo will output a decaying sinusoid when you feed it an impulse (a hit on the attached surface). Problem with a high frequency sinusoid is that one: half the time it's negative, and two: it forces a near-real-time monitoring of the analog voltage there, ie no or small delays in your code.

I've made a pattern recognition 'drum' with piezos, and the general approach was to first start with plotting the analog voltage of the piezo. This is done by putting the positive of the piezo to an analog pin and the negative to ground, and a 1M resistor between the leads (this value worked for me, play with different values to see what works best). Then do a serial plot (ctrl shift L in the IDE) and observe:

how high the peak is for different distances and strengths of 'knocks'
how many times a significant peak occurs before decaying.

Your end goal is to have the Arduino recognize a peak by seeing when the analog reading is above a threshold value , then have a dead period where it ignores subsequent peaks (so it doesn't read multiple events on a single sinusoid), and then play your note. Longer dead period means less false-positives, shorter means more responsive.

I apologize for the long-windedness of my somewhat ambiguous response, I'll try to remember to paste my code when I'm at my computer tomorrow.


I tried your sketch on an Arduino Uno, with no servos connected, and the LED on pin 13 did not blink.

DataFiddler makes a good point in their comment. To be sure you are actually uploading the sketch, try uploading the Blink sketch that comes with the IDE. Change the delays from 1000ms to 200ms then upload it. The difference in flash rates should confirm or deny the ability to successful upload sketches.

You don't say which servos you are using, so I'll assume they are SG90. I'm not sure if the data sheet for every SG90 servo is the same, but if you look at this one, SG90 Specifications, you'll see the "stall current" can be between 570mA and 730mA, each. If you are powering them from the Uno, it can't supply that much current. Another limiting factor is the computer's USB maximum current output, (if you are powering the Uno with a USB port). FWIW, my computer can only provide 500mA per USB.

I would suggest powering the servos with a separate power supply, then see what happens.


Why does reading an analog pin give a different results when interfacing with Processing?

You have not provided a schematic of how the Arduino is wired up.

However, if nothing is connected to the pin, i.e. it is not connected to ground or a supply voltage, then the input will float. That means that just by placing your hand near the Arduino, then analogRead() will produce a different value than when your hand in not near it.

I would hazard a guess that if you ran both sets of code multiple times then you will get different answers each time, if you start waving your hand around the Arduino.

Try that first, and then tie the input to either HIGH or LOW and then repeat the previous experiment.

In the second case the results should be consistent, and equal in the Arduino and Processing alike.

However, according to your comment, that is not your issue, as your inputs are not floating.

I think that issue is actually this:

  Even with Firmata installed, the Processing application needs to define the pin mode for ALL the pins being referenced, telling the Arduino instance that xPin, yPin, and zPin are ANALOG pins.

Source: Re: Firmata problem with analogRead in Processing Library

Looking at your Processing code the pins are not defined. You need to do so.

With the Arduino code, there is no need to define the analogue pins.


USBasp problem: could not upload sketches to Arduino clone with PL2303 USB-to-UART chip

Do you have a USBasp plugged into the computer? if yes then you need to install USBasp driver else why don't you just use the bootloader option from the arduino IDE.


Connecting to the Sparkfun Redboard on Mac OS X Sierra

I'm using MacOS Sierra and an Arduino Pro Mini (from Sparkfun) with a breakout USB-to-UART board that uses an FTDI FT232 chip. I'm using the default Apple FTDI drivers (the ones that are bundled with Sierra) and I'm having no problems whatsoever.

Some people have reported problems using the manufacturer (FTDI) drivers that they had already installed after upgrading to Sierra. Some of them solved it by uninstalling the conflicting drivers and relying on the default Apple FTDI drivers uninstalling the conflicting drivers and relying on the default Apple FTDI drivers instead. It's worth a try.

OTOH, the CG340 driver doesn't currently work under Mac OS Sierra. Fortunately, Adrian Mihalko patched the driver and made it available at GitHub, along with some troubleshooting instructions.


In your code the buttons only control the direction, but are not turning the motor on or off. This is only be done with the potentiometer, which can be set to zero speed.

To really enable the motor with the buttons, you have add some logic for the enable pin. For example change the setMotor() function and give it also a boolean as parameter, which indicates the enabling of the motor:

void setMotor(int speed, boolean enabled, boolean reverse)
{
    if(enabled) analogWrite(enablePin, speed);
    else        analogWrite(enablePin, 0);
    digitalWrite(in1Pin, ! reverse);
    digitalWrite(in2Pin, reverse);
}

You can set a corresponding boolean variable in the loop() function like you did with the status variable. Set this new variable to true in both if-statement of the buttons. Alternatively you can do this inline with the setMotor() call by writing:

setMotor(speed, reverse || reverse1, status);

The || is a logical OR operation. It returns true if any of both operands are true. In a similar way you can ditch the other if-statement with the status variable:

setMotor(speed, reverse || reverse1, !reverse && reverse1);

! negates the value of reverse and && does a logical AND. You can decide yourself, if you want to use if-statements (which are a bit easier to read or these logical statements (which are more compact).

Also you should use better variable names. reverse and reverse1 are not really good to distinguish. Better would be reverse and forward.


Two ints declared simultaneously, one "does not name a type"

the following code

is properly indented
is missing the declarations of the variables for the 'button states' and the 'prior button states'
has additional text about a format error
is properly indented
has the code blocks properly separated by a single blank line

and now the code

int readButtons()
{
    rbuttonState = digitalRead(right);
    lbuttonState = digitalRead(left);
    sbuttonState = digitalRead(sel);
    obuttonState = digitalRead(off);
    nbuttonState = digitalRead(snooze);
    int ret = -1;

    if (rbuttonState != lastrButtonState)
    {
        if (rbuttonState == HIGH)
        {
            ret = right;
        }
    }

    if (lbuttonState != lastlButtonState)
    {
        if (lbuttonState == HIGH)
        {
            ret = left;
        }
    }

    if (sbuttonState != lastsButtonState)
    {
        if (sbuttonState == HIGH)
        {
            ret = sel;
        }
    }

    if (obuttonState != lastoButtonState)
    {
        if (obuttonState == HIGH)
        {
        ret = off;
        }
    }

    if (nbuttonState != lastnButtonState)
    {
        if (nbuttonState == HIGH)
        {
        ret = snooze;
        }
    }
}  << extranious closing brace ends the actual function

    lastrButtonState = rbuttonState;
    lastlButtonState = lbuttonState;
    lastsButtonState = sbuttonState;
    lastoButtonState = obuttonState;
    lastnButtonState = nbuttonState;
    return ret;
}


finally I got it (somehow) working.
After a reset and another run of run-avrdude /etc/linino/bathos-yun.hex (the first was a mistake by copy and past - not bathos-one I already ran bathos-yun before) and a reboot again I was able to read analog IO.

But still the digitals were missing.
Than I found the command gpioexport an ran it.
After that the correct entries (D13, D14...) were present in sys/class...

But an echo out > D13/direction resulted in a timeout error message.
Again reboot - again the Dxxx entries were gone.
Another gpioexport made them appear again.

And this time not timeouts - instead I could turn on / of D13 (for test).

I guess all I have to do to make the things better is include gpioexport in "startup code" so that it runs after a reboot.


error 404 in HTTP GET request with Arduino Uno and ESP8266 using AT commands

your HTTP request is incomplete. it should be

String cmd = "GET /greencare/login.php?product_id=123456 HTTP/1.1\r\nHost:alirezaabrishami.ir\r\n\r\n"

if the wen server host has more hostnames for the same IP address, the Host header is used on HTTP server to direct the request to the right web application


Go to File > Preferences. Under the Settings tab, click the checkbox for Display line numbers.

Keep in mind that this option is available in the latest version of the Arduino Integrated Development Environment (v1.6.6). In case you are using GNU/Linux distribution is recomended to use the one that is NOT in the distribution's repositories but the one that is offered in https://www.arduino.cc/en/Main/Software

If you are using a Linux OS this solution may not work. Look at the 'preferences.txt' where you can edit your preferences in a file without a GUI.It will display all possible options available for your current version of Arduino IDE on your OS. It is usually in the '.arduino' folder which may be in your 'home' folder.


Error 'exec: "python": executable file not found in $PATH Error compiling for board AI Thinker ESP32-CAM.' in Arduino IDE 1.8.12

All right so I was able to fix the problem. The Arduino IDE I was using had been installed from the Ubuntu Software Center. I uninstalled it.

Then I reinstalled the Arduino IDE by downloading it from the www.arduino.cc website and doing a manual install in /opt. Now it works awesome.


EEPROM bytes preset to 255 while programming

In flash and eeprom memory an erased value is 255. It's all about how flash memory works. If you want something other than 255 in there you will have to write something other than 255 in there.


Spikes in CO2 and TVOC measurements with CJMCU-811 sensor

I have two of those sensors in a long term setup and I know those spikes very well. I once put lots of effort in debugging and I personally gave up on the ccs811 and use a different sensor now.
Back then I have already tried what Jaromanda suggests in his comment.
Both of my sensos showed the same behaviour while the spikes on both sensors did not correlate in any form.
Also, if I remember it right, those erronous readings appeared to be at dedicated values.
I tried several pullups, which also didn't make any difference and on the oscilloscope everything looked fine.
Printing the output of the I2C related functions revealed that communication was always stable. If it was I2C related I would expect those erronous readings to be completely random anyway (which they aren't from my experience).
My final (vague) theory was that maybe there exist race conditions between the computation and the I2C interface or maybe the adc and the approximation algorithm (that's all "inside" of the sensor). I once produced such a bug myself which resulted in a similar behaviour.
At least I'm pretty sure that there is nothing you can do in your sketch to fix this problem, because for the mentioned reasons it is very unlikely related to communication problems. You might want to work-around it or look for an updated firmware.
Or (my prefered solution) choose a sensor which does a true CO2 measurement (the ccs811 only returns a pseudo, calculated CO2-equivalent approximation).
Those higher-class sensors use NDIR technique and are only a bit more expensive (still under 50$) but you'll probably have much more reliable readings, less problems and a wider measurement range (up to 0-40000ppm vs 400-8192ppm).
Ps: did you follow the guidelines concerning the "burn-in time"? Because honestly, that was a mistake I did: I simply plugged it in of curiosity to test communication and read about this step afterwards. But I don't believe it has something to do with this problem, because there are physical reasons why one should do so, but those artifacts seem to be of digital nature.


Crosses Initialization in switch case with different size of array per case

Create two global arrays that contain the maximum amount of number you ever need, e.g.

int tPTT_x[4];
int tPTT_y[4];

Than create one global int that contains how much x and y are filled, e.g.

int filled;

Than you can change your cases to

void time_Text(int PastTo_val) {
  switch (PastTo_val) {
   case 1:
   {
    tPTT_y[0] = 11;
    tPTT_y[1] = 11;
    tPTT_y[2] = 11;
    tPTT_y[3] = 11;
    tPTT_x[0] = 6;
    tPTT_x[1] = 7;
    tPTT_x[2] = 8;
    tPTT_x[3] = 9;
    filled = 4;
  }
  break;
case 2:
  {
    tPTT_y[0] = 11;
    tPTT_y[1] = 11;
    tPTT_x[0] = 10;
    tPTT_x[1] = 11;
    filled = 2;
  }
  break;
 }

Than you can use the 'filled' variable to see how many items in the array are 'valid' (0 <= item < filled).


The numbers are ASCII Codes (here is a chart from the Arduino website). 49 is the number 1, and 13 is a carriage return ('\n'). There should be a setting in the bottom right corner of Serial Monitor to change line ending, this should be set to "no line ending." If it is, than client.print() must be adding the carriage return, so you will need to remove it in Python. If you are only sending integers, replace

serial_data = String(Serial.read());

with:

serial_data = String(Serial.parseInt());

In the Python code I suggest adding a print statement to check if the connection is closed after

#came out of loop
    conn.close()


So you would rather use your Raspberry Pi than your PC? Easy, as it
turns out that a Raspberry Pi is not that different from a PC running
Debian or a Debian-like OS (e.g. Ubuntu).

Just connect the Uno to the Raspberry Pi through the USB link. Log the
data on your Raspberry exactly like you would do on the PC. You don't
need any Ethernet or WiFi shield. You just need to make sure that
whatever logging program you use on the PC can run on the Raspberry Pi.
This is most often trivial if the PC is itself running a Linux distro.


Having a problem to control digital servo with HC-06 bluetooth module

let have a look at following line of code:

int servopos = bluetooth.read();

I think that you are thinking that if you type in 1 in your
Bluetooth application. bluetooth.read() will pass that 1 to
sevopos. But, that's what not happens. What actually happens is that it will pass the ASCII value of whatever you type in you
app, to integer. So, if you have typed in 1, it will pass 49
to servopos.

  I put 45

Now, think about it. when you type in 4 of this 45,

bluetooth.available()>0

becomes true.

int servopos = bluetooth.read();

bluetooth.read() will pass 52 (ASCII of 4) to servopos. Next,

myServo.write(servopos);

myservo will move your servo to lets say 52 degrees. and then there will be a delay.

Now, when you type in 5 of this 45, the procedure will be
repeated and your servo will be moved again by 53 degrees.

Now, you might be wondering that why 4 and 5 sepratly? Well,
all these intructution are being executed in MHzs. and secondly,
you, yourself has programmed that if loop you read just once
character. Yes, it will read character by character.

  but it loose connection after servo moved once

I think your servo is drawing too much current from Arduino Board
which results in a drop in net voltage. And hence your HC-05 (kind
of) tuns off. This is what happens most of the time.


Why is one part of my code being executed over the part before it?

The problem is with your logic. You are saying:

If it's too close in front then move backwards
Otherwise stop all movement
If it's too close on the left then move forwards
Otherwise stop all movement.

That means that if it's too close in front, but not too close on the left, then it will think about moving backwards, but then immediately stop because it's not too close on the left.

You need to think more about the whole space at once, not just one individual direction. For instance, what do you do if it's too close in front and too close on the left? At the moment you'll crash into whatever is in front.

So you should be thinking about four conditions:

Too close in front AND too close on the left
Too close in front BUT NOT too close on the left
NOT too close in front BUT too close on the left
NOT too close in front AND NOT too close on the left.

Then you can choose the right action to perform.

If your specific setup means that it can never be too close in front at the same time as being too close on the left you can collapse it into a simpler form:

IF it's too close in front then move backwards
ELSE IF it's too close on the left then move forwards
ELSE stop all movement.


Is there a way to go to the start of the void loop() function kind of like a "continue" keyword in c in loops?

In the loop() function, return will perform that function. By exiting the function, the for() loop in main() (which we don't see) will iterate again, calling loop() again.
Another way to accomplish the same thing is to write everything in your setup() function, including whatever kind of loop construct you want, and use break; and continue; statements as you're used to:
void setup(){
   // pinMode() & digitalWrite() calls
   // Initialize the Serial port if you need to
   // Any other one-time setup
   //
   // Everything happens here:
   for( .... ){
      // loop contents here
      if( whatever ){
         continue;
      }
      else if( something_else ){
         break;
      }
   }
}

// This just stalls forever when setup() ends:
void loop(){
   ;
}


running a dc motor with a small L298N module and an arduino and the L298N library

PWM is used to control the duty cycle and not the voltage directly so your PWM will work directly on the input pins of motor driver and you will be able to control the speed.
just use analogWrite on the input pin which was held HIGH and HOLD the other pin to LOW. If you desire to change the direction while simultaneously controlling the speed. just analogWrite both the pins. Just keep in mind that the duty cycle of both the pins should not be tweaked simultaneously. while the speed is being controlled in one direction the other pin should be at analogWrite(other,0).


error: expected primary-expression before ',' token edit status 1

You have two commas in the command when making the lcd object:
LiquidCrystal lcd(13,,12,11,10,9,8);

Probably just a typo, delete the comma and you should be good to go.
LiquidCrystal lcd(13,12,11,10,9,8);


Is the Panstamp broken ?

Sounds like it. If one works, and the other does not, using the same wiring, it looks like you have a faulty one.

  or should I do a kind of factory reset?

You can't really "factory reset" a chip like that. Possibly there is a problem with the fuses. You may be able to explore further here:

Have I bricked my Arduino Uno? Problems with uploading to board


Code runs, then doesn't run after I add some routine code

I used this - it does the same thing basically, just moved where the bool variables were.

if(read3 == 0) {
    if(pressed2) {
      Serial.println("in on");
      digitalWrite(2, 1);
      pressed2 = false;
    }
    pressed = true;
  }
  else {
    Serial.println("in off");
    if(pressed) {
      Serial.println("in off once");
      digitalWrite(2, 0);
      pressed = false;
    }
    pressed2 = true;
  }