text:
How do I control the buttons on an Arduino LCD keypad shield?
I have just bought a 16x2 LCD display with buttons. I can get the display to work and do various basic sketches included in the Arduino IDE. However, I cannot figure out how to control the buttons.
The buttons work using analog pin 0 and from what I was able to understand from what I have read online, it is something to do with the values you receive when the buttons are pressed. I can't seem to find out what values mine gives, I have found a sketch that is supposed to map the buttons, but I cannot get it to work, as I don't really understand what it is doing, I am very new to this.
The code I am using is as follows:
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons() {
  adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 250)  return btnUP;
  if (adc_key_in < 450)  return btnDOWN;
  if (adc_key_in < 600)  return btnLEFT;
  if (adc_key_in < 920)  return btnSELECT;
  return btnNONE;
}

void setup() {
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Push the buttons");
}

void loop() {
  lcd.setCursor(9, 1);
  lcd.print(millis()/1000);
  lcd.setCursor(0, 1);
  lcd_key = read_LCD_buttons();
  switch (lcd_key) {
    case btnRIGHT: {
      lcd.print("RIGHT ");
      break;
    }
    case btnLEFT: {
      lcd.print("LEFT   ");
      break;
    }
    case btnUP: {
      lcd.print("UP    ");
      break;
    }
    case btnDOWN: {
      lcd.print("DOWN  ");
      break;
    }
    case btnSELECT: {
      lcd.print("SELECT");
      break;
    }
    case btnNONE: {
      lcd.print("NONE  ");
      break;
    }
  }
}

If anyone can give me any pointers it would be greatly appreciated.
Liam

Add a Serial.begin(9600) in setup, and a Serial.print(adc_key_in) after you read the key, to see what values you get. If they don't change, it's a hardware problem (faulty element or wrong circuit), otherwise you know what values you get per key.

Thank you for your help, it didn't occur to me to do that at all.

No problem, for Arduino this is the common way to debug (to use the serial port for print statements), for other AVR's debugging can be used.

I have found an easy way to do this, i found a tutorial on instructables that has explained in detail what to do, i then applied this to my LCD keypad shield rather than external buttons on a breadboard.
All you have to do to see what the results are for your particular buttons is to load the sketch below onto your board then open the serial mapper on the arduino ide, simply press the buttons and you should see the results.
 /*
  Debounce

  Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
  press), the output pin is toggled from LOW to HIGH or HIGH to LOW.  There's
  a minimum delay between toggles to debounce the circuit (i.e. to ignore
  noise).

  created 28 October 2009
  by Riaan Cornelius

  */

 // constants won't change. They're used here to
 // set pin numbers:
 const int buttonPin = 0;     // the number of the pushbutton pin
 const int ledPin =  53;      // the number of the LED pin for testing

 const int BUTTON1 = 1;
 const int BUTTON2 = 2;
 const int BUTTON3 = 3;
 const int BUTTON4 = 4;
 const int BUTTON5 = 5;

 const int BUTTON1LOW = 970;
 const int BUTTON1HIGH = 1024;
 const int BUTTON2LOW = 850;
 const int BUTTON2HIGH = 950;
 const int BUTTON3LOW = 700;
 const int BUTTON3HIGH = 800;
 const int BUTTON4LOW = 400;
 const int BUTTON4HIGH = 650;
 const int BUTTON5LOW = 250;
 const int BUTTON5HIGH = 350;

 // Variables will change:
 int ledState = HIGH;         // the current state of the output pin
 int buttonState;             // the current reading from the input pin
 int lastButtonState = LOW;   // the previous reading from the input pin

 // the following variables are long's because the time, measured in miliseconds,
 // will quickly become a bigger number than can be stored in an int.
 long lastDebounceTime = 0;  // the last time the output pin was toggled
 long debounceDelay = 50;    // the debounce time; increase if the output flickers

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

 void loop() {
   // read the state of the switch into a local variable:
   int reading = analogRead(buttonPin);
   Serial.println(reading);

   /*
   Not needed while getting the values.

   int tmpButtonState = LOW;             // the current reading from the input pin

   if(reading>BUTTON5LOW && reading<BUTTON5HIGH){
     //Read switch 5
     tmpButtonState = BUTTON5;
   }else if(reading>BUTTON4LOW && reading<BUTTON4HIGH){
     //Read switch 4
     tmpButtonState = BUTTON4;
   }else if(reading>BUTTON3LOW && reading<BUTTON3HIGH){
     //Read switch 3
     tmpButtonState = BUTTON3;
   }else if(reading>BUTTON2LOW && reading<BUTTON2HIGH){
     //Read switch 2
     tmpButtonState = BUTTON2;
   }else if(reading>BUTTON1LOW && reading<BUTTON1HIGH){
     //Read switch 1
     tmpButtonState = BUTTON1;
   }else{
     //No button is pressed;
     tmpButtonState = LOW;
   }

   // check to see if you just pressed the button
   // (i.e. the input went from LOW to a buttonState),  and you've waited
   // long enough since the last press to ignore any noise:

   // If the switch changed, due to noise or pressing:
   if (tmpButtonState != lastButtonState) {
     // reset the debouncing timer
     lastDebounceTime = millis();
   }

   if ((millis() - lastDebounceTime) > debounceDelay) {
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:
     buttonState = tmpButtonState;
     Serial.println(buttonState);
   }

   // save the reading.  Next time through the loop,
   // it'll be the lastButtonState:
   lastButtonState = tmpButtonState;

   // set the LED using the state of the button for testing:
   switch(buttonState){
     case BUTTON1:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON2:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON3:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON4:
     digitalWrite(ledPin, buttonState>0);
     break;
     case BUTTON5:
     digitalWrite(ledPin, buttonState>0);
     break;
   }
   */
 }

Liam

This is all about knowing what the values are corresponding to each button, and determining thresholds which reliably discriminate between different buttons.
Basic code to read the buttons:
 const int buttonPin = 0;     // the number of the button pin, AKA A0

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

 void loop() {
   // read the state of the switch into a local variable:
   int reading = analogRead(buttonPin);
   Serial.println(reading);
   delay(500)
}

Note the reading for each button - as well as no button of course - and choose values for comparisons halfway between these values.  While the values given in the answers above are probably appropriate, it is just as well to check.

Upload this and it will read the resistance of your buttons on the lcd screen
/*  /*
Arduino 2x16 LCD Detect Buttons
resistance
*/

#include <LiquidCrystal.h>

//LCD pin to Arduino
const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;

const int pin_BL = 10;

LiquidCrystal lcd( pin_RS,  pin_EN,  pin_d4,  pin_d5,  pin_d6,  pin_d7);

void setup() {

  lcd.begin(16, 2);

  lcd.setCursor(0,0);

  lcd.print("  Press Any Key ");
  lcd.setCursor(0,1);
  lcd.print("Resistance:");
}

void loop() {
  int x;
  x = analogRead (0);
  lcd.setCursor(12,1);
  lcd.print (analogRead (0));
  lcd.print("                ");
  delay (500);
  }

As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.


text:
How to fix when i shorted 5v to gnd accidentally (Arduino Nano)
I connected 5V to GND accidentally (connect directly, no LED, no motor). Now the LED on the board doesn't light up and power LED lights up but it is not bright. The 5V output pin is only around 1.98V. I'm using clone version from Alibaba. I ordered two, one is still working but the shorted one doesn't work. May I know how to fix them?

You very likely fried components on the board, and would have to troubleshoot and repair those components. If they are surface-mount components that is a highly skilled repai. As Systembolaget says, it's not likely worth it.

I would say that to repair an Arduino Nano clone yourself, if ICs/SMD parts are damaged, is not worth the effort, if you could do it at all (first having to find out which parts need to be replaced, carefully de-soldering the delicate SMD parts, then putting new parts in place, etc.).

First of all  thanks for answer my question, for my case MBR0520 diode is damaged, Voltage regulator is still working, i did a bypass from MBR0520 diode to voltage regulator and it's work perfectly.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
I get a redefinition of "..." on every single line, of every variable, class, function, etc
When I compile my program I get an error message saying redefinition of "..." on every single line, of every variable, class, function, etc.
What am I doing wrong?
int incomingByte = 0;   // for incoming serial data

int byteCount = 0;

bool decision = false;

bool last_debounce = false;

bool test_running = false;

bool ready_freq_enable = false;

int cur_cavity_address = 0;

char serBuffer[256] = {0};

unsigned long previousMillis_enable = 0;
const long interval_online = 1000 / 100;

unsigned long previousMillis_debounce = 0;
const long interval_debounce = 50;

void setup() {
  // put your setup code here, to run once:
 /* pinMode(22, OUTPUT);//address bit 1
  pinMode(24, OUTPUT);//address bit 2
  pinMode(26, OUTPUT);//address bit 3

  pinMode(36, INPUT);

  pinMode(40, OUTPUT);
  pinMode(48, OUTPUT);
  pinMode(52, OUTPUT);*/

  pinMode(2, OUTPUT);//address bit 1
  pinMode(3, OUTPUT);//address bit 2
  pinMode(4, OUTPUT);//address bit 3

  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

  pinMode(10, INPUT);

  Serial.begin(9600);
}

int seekChar(char c){
  for (int x = 0; x < 256; x++) {
    if (serBuffer[x] == c){
      return x;
    }
  }
  return -1;
}

void return_error(){
  Serial.println("ERROR!");
}

void loop() {
  if (Serial.available() > 0) {
          // read the incoming byte:
         int incomingByte = Serial.read();
          serBuffer[byteCount] = incomingByte;
          byteCount++;

          if (serBuffer[strlen(serBuffer)-1] == '\r'){
            serBuffer[strlen(serBuffer)-1] = 0; //remove the last carriage return

            int charIdx = seekChar(' ');
            char value[32] = {0};
            byteCount = 0;
            Serial.flush();

            if (charIdx != -1){
              memcpy(value, serBuffer + charIdx + 1, sizeof(value));
              memset(serBuffer + charIdx, 0, sizeof(serBuffer) - charIdx);
            }

            if (strcmp(serBuffer, "run") == 0){
              if (ready_freq_enable == true){
                test_running = strcmp(value, "true") == 0;
                if (test_running){
                  decision = 0;
                }
              } else {
                return_error();
              }

            } else if (strcmp(serBuffer, "reset") == 0){
              cur_cavity_address = 0;
              decision = false;
            } else if (strcmp(serBuffer, "decision") == 0){
              decision = strcmp(value, "true") == 0;
            } else if (strcmp(serBuffer, "enable") == 0){
              ready_freq_enable = strcmp(value, "true") == 0;

            } else if (strcmp(serBuffer, "address") == 0){
              if (abs(atoi(value)) > 8){
                return_error();
              }
              cur_cavity_address = abs(atoi(value));
            }

            memset(serBuffer, 0, sizeof(serBuffer));
            memset(value, 0, sizeof(value));

          }
  }

  test_running &= ready_freq_enable;
  update_io();
  check_status();
}

void check_status(){
  unsigned long currentMillis = millis();
  bool new_debounce =  digitalRead(10);
  if (new_debounce != last_debounce){

    if (currentMillis - previousMillis_debounce >= interval_debounce) {

    // save the last time you blinked the LED
      previousMillis_debounce = currentMillis;

      Serial.print( new_debounce );
      last_debounce = new_debounce;
    }

  } else {
    previousMillis_debounce = currentMillis;
  }
}

void update_io(){
  //digitalWrite(48, !digitalRead(48) );

  digitalWrite(7, test_running);

  digitalWrite(3, (cur_cavity_address & 0b001) != 0);
  digitalWrite(2, (cur_cavity_address & 0b010) != 0);
  digitalWrite(4, (cur_cavity_address & 0b100) != 0);

  unsigned long currentMillis = millis();
  //Serial.println(ready_freq_enable);
  if (currentMillis - previousMillis_enable >= interval_online) {
    // save the last time you blinked the LED
    previousMillis_enable = currentMillis;
    digitalWrite(5, !digitalRead(5) & ready_freq_enable);
    if (ready_freq_enable == false){
      cur_cavity_address = 0;
    }
  }

  digitalWrite(6, decision & ready_freq_enable);
}

Do you have more than one .ino file in the same folder?

Include some of the actual error messages in your question.

There doesn't appear to be anything wrong with the code you have posted, so its a problem with the build environment.  What environment are you building with?

Apparently I had a duplicate ino file on my same folder. Must of happened accidentally when I was creating a copy as backup. Thanks Chris!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Receive an array of characters using SIM900 module
I tried to receive an array of characters using SIM900, but I couldn't. I can receive just one character like 'G', but I want to receive a string "abcd". When I used char* to save the SMS, I failed.
Does anyone know how?
My code:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

void setup()
{
    pinMode(3,OUTPUT);
    Serial.begin(19200); // for serial monitor
    SIM900.begin(19200); // for GSM shield
    SIM900power(); // turn on shield
    delay(20000); // give time to log on to network. `
    SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
    delay(100);
    SIM900.print("AT+CNMI=2,2,0,0,0\r");
    // blurt out contents of new SMS upon receipt to the GSM shield's serial out
    delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button24
{
    digitalWrite(9, HIGH);
    delay(1000);
    digitalWrite(9, LOW);
    delay(7000);
}

void loop()
{
    // Now we simply display any text that the GSM shield sends out on the serial monitor
    if(SIM900.available() >0)
    {
        char *in = SIM900.read();
        if (in =="abcd") digitalWrite(3,HIGH);
        if (in == "00") digitalWrite(3,LOW);
    }
}

It solved . I used another library that manipulated . And just support sim900
U can get it in this below link and include to your arduino IDE
This library written by digispark group

How was that  solution?

Right and stable@Aiapaec

I meant, Could you post the code of the solution?

No.The solution codes are in the library in answer . You should download library and include it in your arduino ide @Aiapaec

#use this code and then inform me"
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

void setup()
{
    pinMode(3,OUTPUT);
    Serial.begin(19200); // for serial monitor
    SIM900.begin(19200); // for GSM shield
    SIM900power(); // turn on shield
    delay(20000); // give time to log on to network. `
    SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
    SIM900.write(0x22);
    SIM900.write(0x0D);
    SIM900.write(0x0A);
    delay(100);
    SIM900.print("AT+CNMI=2,2,0,0,0\r");
    // blurt out contents of new SMS upon receipt to the GSM shield's serial out
    delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button24
{
    digitalWrite(9, HIGH);
    delay(1000);
    digitalWrite(9, LOW);
    delay(7000);
}

void loop()
{
    // Now we simply display any text that the GSM shield sends out on the serial monitor
    if(SIM900.available() >0)
    {
        char *in = SIM900.read();
        if (in =="abcd") digitalWrite(3,HIGH);
        if (in == "00") digitalWrite(3,LOW);
    }
}

Hi.  Thank u . But these didn't work. I need to choose memory and save sms in side and open it (to this we have need to  use AT commands)

An explanation of what you changed would be useful.

It solved . I used another gsm library and worked.@gre_gor

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
How to rotate two or more steppers simultaneously by giving ARRAY of angles?
The following is the code that I am trying but the problem is steppers rotate one after each other. However, I want to rotate steppers simultaneously.
This code for two stepper motors.
int pulse=3;

int direc=4;

int pulse1=5;

int direc1=6;

int i,j,k;

float angle[5][3]={{360,360,3},{7,8,9},{11,12,13},{14,15,16},{17,18,19}};

float steps;

void motor1(){

  for(k = 0; k<=4; k++){

    Serial.println(angle[k][0]);

    steps = (1600*angle[k][0])/360;

    Serial.println(steps);

    for(j = 0; j<=steps;j++){

      digitalWrite(3,HIGH);

      delayMicroseconds(100);

      digitalWrite(3,LOW);

      delayMicroseconds(100);
        }

}

}

void motor2(){

  for(k = 0; k<=4; k++){

    Serial.println(angle[k][1]);

    steps = (1600*angle[k][1])/360;

    Serial.println(steps);

    for(j = 0; j<=steps;j++){

      digitalWrite(5,HIGH);

      delayMicroseconds(100);

      digitalWrite(5,LOW);

      delayMicroseconds(100);

        }

}

}

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

  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop(){
    motor1();

    motor2();

   //while(1);
}

Hello and welcome. Your question needs more detail and might be closed. Please read [ask] and How to ask a good question for Arduino Stack Exchange

So you are outputing the steps to monitor, but how are you controlling your steppers? what controllers are you using? what is your schematic?

(Half a year ago, but what the hey...)
Your motor1() and motor2() are currently written as:
do until done:
  take a step
  wait
end

, so yeah, one finishes before the next one even starts.
Each motor function needs to do:
if motor's current-position is not the final position,
   if it is time to take a step,
      take a step
      calc when to take another step
      calc motor's new current-position
   end
end

Now call your motor functions as frequently as possible. Notice that either if test can cause the function to return without doing anything - that is intentional.
This is non-blocking programming - coding in such a way that nothing keeps control while waiting for something to happen (clock ticks, in this case), it just does something, or does nothing, right now, if there is or is not something to do right now, but it does release the processor (the function returns immediately) whether it did something or not.
I call these functions "maybe-do" functions:

maybe step a motor (if, and only if, a certain interval has passed, step the motor);

maybe light an LED (if, and only if, the button is being pressed and it wasn't pressed the last time we looked, turn on the LED;

maybe read the terminal keyboard (if there is at least one character in the Serial input buffer, collect a character).

Then your loop() function should do nothing but call each maybe-do function, in sequence, as fast as possible. And it follows from the above that your maybe-do functions need to execute as quickly as possible and do no more than is necessary to (1) decide whether to act, and if so, (2) to carry out its action, and (3) in either case, return immediately.

And - Bang-Boom! - right there is a half-semester course in non-blocking programming, and without using interrupts!

This is a valuable reference answer, that could be useful for sooo many questions.

I can't understand clearly what you want, but maybe you want to drive your two servos simultaneously. To do this, after you determine the angle of servos, you can drive them without delay between their commands.
Like you use above, you can't drive them at the same time, there are loops and they have to be completed before the next instruction is run so your servos wait each other.
Here is a good example code for you:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo

float angle[5][3]={{360,360,3},{7,8,9},{11,12,13},{14,15,16},{17,18,19}};

void setup() {
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(10);  // attaches the servo on pin 10 to the servo object
}

void loop() {
  for(k = 0; k<=4; k++){
    pos = (1600*angle[k][0])/360; //Calculate the angle which you want

    //The most impportant part, there shouldn't be a delay between them
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'

    delay(1000);                       // waits 1000ms for the servo to reach the position
  }
}

Thank you sir for your answer but i want to rotate motor 1 for this loop,
pos = (1600angle[k][0])/360; and motor 2 for this loop  pos = (1600angle[k][1])/360;

Then, add pos2= (1600angle[k][1])/360 below pos = (1600angle[k][0])/360. And, change the myservo2 command to myservo2.write(pos2). So your first motor rotates x degree while your second motor rotates y degree without any delay.


text:
how to simplify code
I am as new as new can be to the Arduino world and have been playing around with them.  I have a few "Arduino Uno" boards that I purchased and have successfully loaded sketches to them.  However I am having problems figuring out how to write code in a simple manner.
I am  using a LED strip of WS2812 LEDs (similar to this). Here is what I would like to achieve:
I would like to be able to light  "lets say"  LEDs  1, 3, 5, 7.  Then light LEDs 2, 4, 6, 8  or any other combination of "multiple LEDs", by that I mean maybe LEDs 0, 14, 15, 36, 37, 52, 54.  I am sure you get the idea.
Can I write a single line code to light these LEDs or do I have to write out each line.
Sorry if this is a simplistic question, but I have searched and have not seen anything that may accomplish this, or I just over looked it.
Thanks in advance for your help

Oh I guess I should say they are strip led(s) ws2812

please post code

Please edit your question to add the important information that you're using WS2812. It's better to have all the info in the question rather than expecting that people will read the comments.

Most times you would set the states of the LEDs in a for loop, while checking the rule with which they should light up. Please state clearly the rule behind this

if you want to use a single command to light multiple LEDs, then you will have to write a function that accepts multiple parameters ..... each of the parameters would be the LED number to light

I have to say that I do not have any experience with the ws2812 led strip but basically it is used with the Adafruit_Neopixel library where you have the function pixel_obj.setPixelColor(pixel_number,pixel_obj.Color(R,G,B)
and the function pixel_obj.show().
Now you basically want to make the code in void loop() clean and there is a wide choice of possibilities and techniques to use. The simplest is not to do it, but if you want you can write a library to do it or write a function that takes the number of the pins and light 'em up (all with the same color), like this
void light_pixel(int pixels[],int Red,int Green,int Blue){
    for(int i=0;i<NUMPIXELS;++i){
        pixel_obj.setPixelColor(pixels[i],pixel_obj.Color(Red,Green,Blue));
    }
    pixel_obj.show();
}
This works assuming you have declared pixel_obj in the outermost scope, and you will call the function like this:
#include <Adafruit_NeoPixel.h>
#define PIN //Whatever you pin is
#define NUMPIXELS //Thenumber of the pixels in your strip
Adafruit_NeoPixel pixel_obj = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// You may have to modify the third parameter Rationale: You didn't
// specified anything about your led strip
void setup(){
pixel_obj.begin();
pinMode(PIN, OUTPUT);
}
void light_pixel(int pixels[],int Red, int Green, int Blue){
for(int i=0;i<NUMPIXELS && pixels[I]!=-1 ;++i){
    pixel_obj.setPixelColor(pixels[i],pixel_obj.Color(Red,Green,Blue));
}
pixel_obj.show();
}
void loop(){
int my_pixels[NUMPIXELS]={1,3,5,7,-1}; // Using -1 as terminator
// Initialize the array . Disclaimer: this is not optimised and you might use
// new opearator or better pass the reference of a vector to the function so
// that you can modify the range of the vector and have a more concise function
light_pixel(my_pixels,255,255,255);
delay(1000);
light_pixel(my_pixels,0,0,0);
}

Then you can change the number of my_pixels with a smile array assignment
This function is just a sample to get the job done but I'd recommend you to study further the C/C++ programming language in general in order to write better code
Good Luck!

sizeof(pixels)/sizeof(*pixels) won't work here, as at this point pixels is a pointer, not an array.

@EdgarBonet This should work, I just set a fixed value for both the array sizes


text:
Trying to use NodeMCU ESP-12e, a 5v relay AND a solenoid lock on same 12v power wall-wart
Noob here, so be gentle.
Using a 12v-5/3.3v power board, NodeMCU powers relay fine, 100% of the time. Add in the solenoid by soldering a line from the wall wart into the COM spot on the relay, and then 10-15% of the time, the activation of the solenoid resets the NodeMCU. Common ground for all of them obviously.
It should be possible to run them all, yes? But what do I need to add into the chain to keep the reset from happening? A capacitor? Magic? Help.

Can you edit your question to draw a circuit diagram using the schematic tool?

do you have a flyback diode on your coils? if not, get ASAP. a cap might help if undervoltage is what resets the MCU

What is your power board?


text:
Send out a short signal every 10 seconds to an arduino
In order to reduce power consumption, I want to resume my Arduino from standby mode every 10 seconds. For this a hardware interrupt is necessary.
Is there such a device that can create a quick impulse to trigger that interrupt? It can be anything from 10ms to 2 seconds; doesn't matter. My first thought was to use a 555 timer, but this one can only be on for 10 seconds and off for the same amount of time.
The best solution for me would be an already assembled device that I just have to wire with my Arduino since my knowledge in electronics is very low. Or a detailed assembly plan, then I would be able to build it myself I guess?
UPDATE: I was now able to put the Arduino into standby-mode using the Low-Power library. At first it seemed like it didn't work, because I wanted to print out a text over the serial connection. Instead, I tried to let the internal LED blink every 8 seconds, and this works perfectly.

Your question doesn't say why you don't simply program a second Arduino to do it. This indicates to me that your question may be lacking some vital details about your requirements.

Well the general purpose would be to reduce power consumption. So a second arduino wouldn't be very suitable hence it uses the same amount of power while the other one is in idle state.

You should update the question to include this information.

Yeah that's an important aspect. I updated it

Look into connecting an RTC quartz for use as the wake-up timer, see e.g.: https://steemit.com/science/@techlife/how-to-use-a-quartz-clock-for-real-time-clock-in-avr-microcontroller

While not the subject of the question, keep in mind that a typical "Arduino" will require modification and removal of unneeded parts to achieve low standby power consumption.  You may be better starting with an ATmega and building exactly what you need.

that's a good point.. do you mean something like a bareduino?

A 555 doesn't have to generate a 50% duty cycle. Even if you do want to use a 50% duty cycle, the edge can be RC coupled into the interrupt to reduce the pulse width.
An Arduino can use a slow clock like a 32kHz watch crystal, then it's very low power indeed. This slow one can be used to wake-up your more power-hungry Arduino.
The lowest power and tidiest external solution would be to use a CD4060. These are designed to be very low power, very long period timing devices.
The correct way to do it is to use the internal Watchdog Timer to wake itself up from sleep. This uses an independent internal hardware 128kHz low power oscillator. The longest this can be programmed to wait is 8s. However, if you program it to 5s, then the Arduino can choose to do work, or go straight back to sleep again, on each interrupt.

Well the CD4060 seems promising, but the Watchdog timer solution looks way easier. I always tried it with just that one line to wait 8 seconds: LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); But doesn't this libary automatically set the watchdog timer or do I have to do this by myself?

@The_javascript_King who knows? How about you ask that specific question on the Arduino forum.

Yeah, your're right. Gonna ask it there. Thanks for your hint with the watchdog timer, I think I'm on the right way

@Maple a valid sub-multiple of 10 then, does it do 2, or 1 second? You can point out problems, or point out solutions.

The best solution for you is to use LowPower library which does not require any external parts. It supports up to 8 seconds sleep. If you need exactly 10 seconds you can write a loop with 5 cycles and call powerDown with 2 seconds sleep.
If you still want to use external interrupt, see this for some chip options.
Also, see this article for some good ideas on reducing power consumption, and this article on how to run Arduino for a year on coin cell.

Well at first I had the same idea, but somehow it doesn't work on my arduino micro. In some forums they said, that even if you use this command: LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
You still have to use an interrupt to start it again. Do you know any working examples?

UPDATE: I managed to get it to work with the LowPower libary. I let the internal LED blink and then put it into sleep mode. Before that I always tried to print a strin over the serial port but that doesn't work rigtht after standby. But the LED does :) so problem solved I guess. But still it would be great if serial also works after standby, andy idea how that would be possible?

Along the lines of mr_sunshine's answer, another chip you could use is commonly known as a 556 timer - it's two 555 timers in a single package.  Run one timer on the normal 50% duty cycle (astable), and have it trigger the other timer in monostable mode to send a short pulse of voltage.  Look for a schematic for a servo controller based on a 556 or two 555's, and change the values to get your 10s delay.  Here's a link to one such page, found with a google search: Servo Exerciser

No, for two reasons.  First the asker is mistaken, a dual timer is not needed, a single 555 could do that job.  But more importantly, even in a CMOS version this will consume 10-25 times more power than appropriate solutions.   That LTC2956 is single digit microamps, this would be 100 uA or worse.


text:
Arduino - Raspberry Pi serial communication
I need to connect a Raspberry Pi and an Arduino Uno through serial communication and decided to follow this guide, which mentions the use of a voltage divider.
I understand the connection to the Raspberry Pi GPIO requires 3.3V but I also plan to power the Raspberry Pi from the Ardunio's 5v output pin.
What's the safest approach to achieve this and the recommended current? Thanks.

Are you talking about powering the PI via its 5v pin, or powering the it from the Arduino 5v pin?  Yes you need a voltage divider, you might get away with a resistor network, but a proper one would be better.

I mean powering the pi from the Ardunio's 5v output pin. The real question here is how I'm supposed to establish connections between pi-arduino when the gpio pins require 3.3v and I need to power the pi with 5v

Depending on what pi it is you need 2.5A, which an Arduino can not provide.  You need to connect the gnd pins to provide a common ground to allow them to communicate.  The Arduino will send 5v signals into the voltage divider and these will be dropped to 3.3v for the pi, and then the process will be reversed.  AliExpress or eBay will have loads for sale, they cost about $0.5 each.

Thanks alot. You've made a couple of things clear to me. If I have a 5V, 2.5A power source to be connected to a pi pin and I also need to connect the 3.3v from the voltage divider to a pin, is it safe to have two voltage sources into the pi?

Yo should connect the 5v 2.5A PSU via the power input micros USB socket on the Pi rather than the 5V pin.  I don't know for certain, but the chances are that the socket is better protected against over/under voltage, reverse polarity, etc.  If you use the power in pins of the GPIO connector (if there are any) then you need to be 100% certain you are correct otherwise you will fry your Pi, and fried Pi smells bad.  If you use the power socket the 3.3V will also be provided by the circuitry and all will be good.

You CAN NOT reliably power any model Pi from the Arduino 5V output.
You can interconnect the Arduino serial to the Pi using a voltage divider or (preferably) a level converter, as suggested in the linked article. (I might add that the linked article contains a number of errors which will not work on recent Pi models).

Better still you can use a USB connection, to provide serial communication to the Arduino, AND you can power the Arduino from the Pi (I often do this).

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Can't reset Arduino Pro Micro
I'm trying to reset an Arduino Pro Micro with a new code and it is not allowing me to. I'm using an empty sketch to upload to the pro micro but I get different error messages every time. I think the reason why it doesn't allow me to upload code is because it is programmed to start on boot. As soon as it's plugged in to a USB port the code runs, and causes this issue.
Some of the errors I get is
Arduino: 1.8.2 (Linux), Board: "Arduino/Genuino Micro"

Sketch uses 3602 bytes (12%) of program storage space. Maximum is 28672 bytes.
Global variables use 147 bytes (5%) of dynamic memory, leaving 2413 bytes for local variables. Maximum is 2560 bytes.
avrdude: ser_open(): can't open device "/dev/ttyACM0": Device or resource busy
Problem uploading to board.`

Does anyone know how I can fix this?

Did you try pressing the reset button twice?

Sounds like ModemManager is locking the port.

https://hackingmajenkoblog.wordpress.com/2016/08/24/diagnosing-arduino-problems-in-linux/

@IgnacioVazquez-Abrams Yeah I have tried pressing the reset button twice and then uploading the empty code quickly as soon as the port is identified but no luck

@Majenko That blog post seems like it's about accessing ports, I have access to my COMPORT and I can get my board info from the ide, so the ports aren't the issue.

Trust me. Look at the modem manager part.

You plug the board in (or it is reset to enter the bootloader). Immediately modem manager opens the port and tries to configure it, which means you can't since it's busy. It fails, since it isn't a modem, and releases the port. From that point you can access it, but it's too late for programming by then.

@Majenko I plug the board in and within 500 miliseconds it starts typing several strings onto the computer which is I programmed it to be. Now from my understanding to completely reset the board I need to have an empty sketch on the ide, press the reset button on the board and click on upload on the ide but by the time It resets and connects to a port it's already typing things onto the computer so it's almost impossible to click reset before 500 miliseconds.

It typing things won't make the port be busy. Only software running in Linux can do that, and the only software that is normally doing that is ModemManager.

@Majenko I will try to reset it on MacOsx see if I get the same error.

managed to fix it @Majenko using the Mac OSX Arduino IDE even after my code executed it seems it is modernmanager on Linux, every time I would hit upload on Linux it would rerun my code on the board almost as if it it was hitting the reset button. But on mac all I did was wait until the code finished running, and then I hit upload and it worked!

@Majenko: you should have mentioned modemmanager, save the poor guy some time...

@dandavis You think? ;) Maybe I should have mentioned modemmanager instead.

haha post an answer I will accept it


text:
How to use the eclipse arduino scope?
I am quite new to the Arduino stuff. I have got the Arduino IDE installed side by side with Eclipse. I am using Eclipse with the Arduino plugin, which is working well for me, including the SerialMonitor.
If you're using Eclipse with the Arduino plugin, it'll also add two new views. One is the serial monitor, the other one is called scope. Scope is a 6 channel Oscilloscope. But I don't know how to get values displayed there.
I am just curious how to use the scope there. I can't find any tutorial for this.
Can somebody explain how to show something inside the scope?

What type of scope you are talking about?Add more explanation to your question.!

Well, if you're using eclipse with the arduino plugin, it'll also add two new views. One is the serial monitor, the other one is called scope. Scope is a 6 channel Oscilloscope. But i dont know how to get values displayed there.

I don't know about eclipse scope, but there is a software Proteus, it has an option of virtual oscilloscope. You can use that.!

Thanks for the hint, but that doesn't answer my question ;)

http://blog.baeyens.it/#post12 may help.

@yeti Thanks, i found this link also during my own search. Unfortunately it doesn't help at all

Can you post the link to the instructions you are using for the scope?
I have used Eclipse with Arduino, but I never noticed such thing.

@IgorStoppa there is not any manual, just use the adruino menu from eclipse to open scope, its just beside the serial monitor

The simplot library (referenced below) is an excellent example of how to use the scope which works as advertised.
Firstly, readers should note that there are two different Arduino plugins for Eclipse ("Eclipse C++ IDE for Arduino" and "Arduino Eclipse plugin named Sloeber V3"). Only the latter has a scope and a seriel monitor that allows data to be sent.
Getting simplot and the scope to work, however, can be a problem depending on the platform. On a Mac, with the latest version of Eclipse (Neon.2 Release Candidate 2) and the Sloeber V3 plugin, the default path to the Private Library is Users/yourname/Arduino/libraries. Unfortunately, this path doesn't (necessarily) exist.
One could spend hours trying to figure out how and where to import a library when the critical library folder doesn't exist.
The solution (at least on a Mac):

Create a folder (arbitraily) named "Users/yourname/Eclipse/libraries".
Include this folder in Eclipse - Preferences - Arduino - Private Library Path
Download jantje's entire Github Arduino Library, unpack it and move the "simplot" folder into your Private Library Folder. "simplot" should now show up in the libraries.
Use: Arduino - Add a Library to the Selected Project
Or build a project using the simplot.ino example.

It should work beautifully.

Given that two bytes are short, you send:

SCOPE_START_DATA short flag: 0xCDAB
short number of following bytes to read (for example, 0x0002 for only one channel)
one short per channel

P.S. This is shamelessly stolen from it.baeyens.arduino.monitor.views.ScopeListener

The plugin FAQ links to a defunct website. However the internet wayback machine reveals some good info (https://web.archive.org/web/20150321054307/http://www.negtronics.com/simplot). In particular a link to the arduino forums that has some code samples: http://forum.arduino.cc/index.php?topic=58911.0

Try the simplot library.
It is from the author of the plugin and works with both 32 and 8 bit processors. There is an example included that should get you going.
The plotter itself automatically connects to the first serial connection so there is no connect needed for the plotter like there is for the serial connection.

Does this help the user use the scope, which is apparently within Eclipse, when the Arduino plugin is used? Seeing as you have a GitHub repository for the arduino-eclipse-plugin, and you are the author of the Arduino plugin, presumably it does. If you could expand upon your answer that would be very helpful. :-)

Honestly, I don't know how to extend more on this.
And downvoting -with no clear remark on what is should be fixed- does not help my appetite to be active on this site.
Sounds like "it doesn't work"


text:
Arduino Uno doesn't work as Manchester code receiver
I'm sending some data from ATTINY85 to Arduino UNO using 433Mhz modules. Coding is Manchester using Manchester.h library from here.
Transmitting data works perfectly, 433 receiver gets data alright.
But Arduino UNO does not seem to receive data! Here is the code of the receiver:
/*
  Manchester Receiver example

  In this example receiver will receive one byte of payload and 4 bit sender id per transmission
  message also contains a checksum and receiver can check if the data has been transmitted correctly
  try different speeds using this constants, your maximum possible speed will
  depend on various factors like transmitter type, distance, microcontroller speed, ...
  MAN_300 0
  MAN_600 1
  MAN_1200 2
  MAN_2400 3
  MAN_4800 4
  MAN_9600 5
  MAN_19200 6
  MAN_38400 7
*/
#include <Manchester.h>

#define RX_PIN  4  //pin where your receiver is connected

uint8_t moo = 1;
uint8_t data;
uint8_t id;

void setup() {

//  pinMode( RX_PIN, INPUT );
  man.setupReceive(RX_PIN, MAN_600);
  man.beginReceive();
  Serial.begin(9600);
}

void loop() {
  if (man.receiveComplete()) { //received something
    uint16_t m = man.getMessage();

    Serial.write(m);
    man.beginReceive(); //start listening for next message right after you retrieve the message
  }

}

Transmitter code:
/*
  Manchester Transmitter example

  In this example transmitter will send one byte of data and 4bit sender ID per transmission
  message also contains a checksum and receiver can check if the data has been transmitted correctly
  try different speeds using this constants, your maximum possible speed will
  depend on various factors like transmitter type, distance, microcontroller speed, ...
  MAN_300 0
  MAN_600 1
  MAN_1200 2
  MAN_2400 3
  MAN_4800 4
  MAN_9600 5
  MAN_19200 6
  MAN_38400 7
*/
#include <Manchester.h>

#define TX_PIN  4  //pin where your transmitter is connected
#define SENDER_ID 5

uint8_t transmit_data = 0;

void setup() {
  man.setupTransmit(TX_PIN, MAN_600);
}

void loop() {
  //SENDER_ID can be ID of the sender if you have multiple transmitters so receiver knows who sent it
  //OR it can be receiver ID if you have multiple receivers so receiver knows it's for him
  //OR it can by just any arbitrary 4 bit number
  man.transmit(man.encodeMessage(SENDER_ID, transmit_data));
  transmit_data++;
  delay(200);
}

Anyone got idea what's the problem?

Might want to use Serial.println(m) instead of Serial.write(m) in the receiver sketch.

What clock is used on the ATtiny85? Did you burn the fuses correctly? I.e. is the timing correct?

@MikaelPatel I use 8MHz internal timer. By "burning fuses" you mean settings that I use while uploading program to microcontroller? For example Tools/B.O.D or Tools/Clock?

See "Configuring the ATtiny to run at 8 MHz" in http://highlowtech.org/?p=1695

check that the chip is receiving data at all, and if it works THEN add the manchester code.

Does it work from an Arduino Uno to another Arduino Uno? Does it work when you wire link them together?


text:
'AttachPinChangeInterrupt' was not declared in this scope
I am a beginner trying to upload the SimpleExample328.ino sketch on my Arduino Uno. When I verify my sketch however, I run into the error:

'AttachPinChangeInterrupt' was not declared in this scope.

I would assume the header file PinChangeInt.h is not in the correct location; currently the PinChangeInt folder (that contains PinChangeInt.h) is placed in the Arduino IDE libraries folder, which I believe is the correct location.
Did I place the header file in the wrong location or does this error result from another cause? Thanks :)

Please edit your question, and post the sketch you are attempting to compile (or, if it is long, post a link to where you found it). Please copy and paste the error messages. Use Ctrl+K on both blocks to indent them so they appear as "code" in the post.

Do you mean this sketch: SimpleExample328.ino? I think that library is made for Arduino 1.0, and not the latest 1.6.

Oh, yes I do! Where would I find the latest library for PinChangeInt and examples for me to try? Thank you :)

Did you take a look at the README? “This library is deprecated [...] users are encouraged to migrate to the EnableInterrupt library [...]”.

You don't have the library installed. To install:

Go to https://github.com/GreyGnome/PinChangeInt
Click the green Clone or Download button
Select Download ZIP

The .ZIP file will download to your computer. Take note of the location.

Open up the Arduino IDE
Go to Sketch > Include Library > Add .ZIP library...
Browse to the download location
Select the PinChangeInt ZIP file

Its done! Compile your program and all should work!

@sa_leinand, what do you do? the library was already deprecated in the time the question was asked in 2015

Agreed that the library is depreciated. That doesn't mean it doesn't work. The sketch that the OP is trying to run is actually one of the examples from that library. To get that sketch to run you need to install the library.

The library was deprecated and completely rewritten as the EnableInterupt library. The main reason was so that the library is "for all versions of the Arduino", not just the few that PinChangeInt worked for. The OP has tagged the Arduino Uno, which works fine with PinChangeInt.


text:
SIM808 module GSM working fine, GPS not working (No GPS ready message on power on)
I powered on my SIM808 module. It showed me following output:
RDY
+CFUN: 1
+CPIN: READY
Call Ready
SMS Ready

It supposed to show GPS ready also.
I sent AT command and return ok.
However AT+CGPSPWR=? returns error. All GPS command showed error.
I think GPS is not initialized at all as i didn't see GPS message when module powered on.
Why is the GPS not working?

GPS Power On Command: AT+CGNSPWR=1 Get location: AT+CGNSINF

I am using sim 868 but when i give command AT+CGPSSTATUS, Its give me +CGPSSTATUS: Location Unknown
I tried to reset it to factory default and follow the command AT&F or ATZ
AT+CMGF=1
AT+CGPSPWR=1
type AT+CGPSRST=0
but still getting that error.
Why is the GPS not working?

You have a version2 module. Use AT+CGNSxxx instead of AT+CGPSxxx

AT+CGNSPWR=? workinf but AT+CGNSRST=? not working throwing error. similarly AT+CGNSSTATUS=? retunring error but AT+CGNSINF=? returning +CGNSINF: 1,0,19800106001337.000,,,,0.00,0.0,0,,,,,,0,0,,,,, which is wrong.

The version 2 module has a different instruction set so there are no AT+CGNSRST or AT+GNSSTATUS, see this pdf with the instruction set.

reference to code or datasheet could make this a good answer which could lead to upvotes and the ability to comment. Please consider adding to this to make it that little bit better. Thanks for your contribution!

Use AT+CGNSxxx instead of AT+CGPSxxx commands
ATGNSPWR=1 and ATCGNSINF to get location.
if you get following output
1,0,19800106001337.000,,,,0.00,0.0,0,,,,,,0,0,,,,,
It means your GPS is not set.
Try to put GPS antenna outside your room, on open space for 10-15 minutes.
GPS bulb will start blinking to confirm it is now ready for use.
Then use AT+CGNSINF.
Good luck.

Had the same problem with a Simcom868: AT+CGNSPWR=1 (for the GLONASS) and the most common AT+CGPSPWR=1 didn't work giving me back an ERROR. The Simcom808 needs 2A peak current so check if your power supply unit can reach that power and in case replace it;
then try the AT+CGNSPWR=1 or AT+CGPSPWR=1 again.


text:
Ethernet Controlled Arduino Arm
Good day, I am currently attempting to write code that will allow a user to connect to an Arduino Mega via IP address and control a robotic arm on the X and Y axis as well as open and close the claw. I am facing 2 issues and hope someone can help me

when it connects for the first few seconds the servos twitch and I'm not sure why
In my current code i am reading in the URL of the button pushed and moving the arm 5 degrees each time, but i would like to be able to hold the button down and have the arm move instead but I'm not sure how to go about that

/*
 Jamil Gaufr and Eva Santos
 Bridges Project @ SUNY Purchase
 Robotic Arm Control & Interface
 */

#include <SPI.h>
#include <Ethernet2.h>
#include <Servo.h>

//Represents servo to open/close claw
Servo microservo;
//Represents servo to move forward/away
Servo Yax;
//Represents servo to swivel left/right
Servo Xax;

int pos = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
EthernetServer server(80);                             //server port
String readString;
String x = "x =";
String y = "y = ";
String cl = "claw  = ";

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Yax.attach(4);
  Xax.attach(5);
  microservo.attach(6);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  //Initializes every axis to start at the 45 degree position
  Yax.write(100);
  Xax.write(60);
  microservo.write(90);
  //1 second delay
  delay(1000);
}

void loop() {
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {
          //Serial.println(readString); //print to serial monitor for debuging

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();
          //begins html code
          client.println("");
          client.println("");
          client.println("<TITLE>Bridges Program </TITLE>");
          //CSS style code for buttons
          client.println("");
          //end of CSS code
          client.println("");
          client.println("");
          //Page header
          client.println("
Welcome to Robo-Farm!
");
          client.println("
");
          client.println("
");
          //Sub-heading
          client.println("
Robotic Arm
");
          client.println("
");
          //Creates buttons and corresponding URL extension
          client.println("Close Claw");
          client.println("Open Claw
");
          client.println("
");
          client.println("
");
          //Creates buttons and corresponding URL extension
          client.println("Move forward");
          client.println("Move Away
");
          client.println("
");
          client.println("
");
          //Creates buttons and corresponding URL extension to IP address
          client.println("Swivle left");
          client.println("Swivle right
");
          client.println("
");
          client.println("
");
          //Footer text
          client.println("
Created by Gafur & Santos.
");
          client.println("
");
          client.println("");
          client.println("");
          //end of html file
          delay(1);
          //stopping client
          client.stop();
          //controls the Arduino if you press the buttons
          //parses the URL for the corresponding extension
          if (readString.indexOf("?button1on") > 0 && microservo.read() <= 175) { // button1 on is close claw
            microservo.write(microservo.read() + 5);  // tell servo to go to position in variable 'pos'
            delay(15);                        // waits 15ms for the servo to reach the position
            Serial.println(cl + microservo.read());
          }
          if (readString.indexOf("?button1off") > 0&& microservo.read() >= 95) { // close claw
            microservo.write(microservo.read() - 5);  // tell servo to go to position in variable 'pos'
            delay(15);                                // waits 15ms for the servo to reach the position
            Serial.println(cl +microservo.read());
          }
          if (readString.indexOf("?button2on") > 0 && Yax.read() < 150 ) { // button2 on is move forward on y ax (towards the servo on the claw)
            Yax.write(Yax.read() - 5);                // tell servo to go to position in variable 'pos'
            delay(15);                                // waits 15ms for the servo to reach the position
            Serial.println(y + Yax.read());
          }
          if (readString.indexOf("?button2off") > 0&& Yax.read() > 70 ) {
            Yax.write(Yax.read() + 5);                // tell servo to go to position in variable 'pos'
            delay(15);                // waits 15ms for the servo to reach the position
            Serial.println(y + Yax.read());
          }
          if (readString.indexOf("?button3on") > 0 ) { // button3 is swivle in direction of sticker
            Xax.write(Xax.read() - 3);                // tell servo to go to position in variable 'pos'
            delay(15);                                // waits 15ms for the servo to reach the position
            Serial.println(x + Xax.read());
          }
          if (readString.indexOf("?button3off") > 0) {
            Xax.write(Xax.read() + 3);                // tell servo to go to position in variable 'pos' S
            delay(15);                // waits 15ms for the servo to reach the position
            Serial.println(x + Xax.read());
          }
          //clearing string for next read
          readString = "";

        }
      }
    }
  }
}

If you are using a webpage, obviously you cannot implement it with links (since links work by "reloading" the page). You will need to use AJAX and write some functions in Javascript to send multiple requests.

Question 1 will need more information about your code and your wiring of the arm to offer any reasonable answer.
Question 2: There really isn't much to go on but I'll take a guess that you're sending a single message to the arm server on each button press - ? I'd try instead, sending another message every 't' starting at (.75 * t) from message-1, where 't' is the time taken for the arm to move 5 degrees. That's a totally wild guess based on unfounded assumptions of what's happening now, and what fraction of 't' I guess would make sense, but that would be my first, very experimental approach. And even so, given the non-determinism of internet packet arrival times, I wouldn't bet on getting very smooth motion, nor instant stopping on button release.
My next experiment would be send start moving/keep moving commands to the arm on button-press, stop moving on button-release, with the arm controller being smart enough to 1) stop anyway after some short period of no messages or it reaches its limit, and 2) not let commands accumulate (or the arm will keep driving until it limits).
Update:
Yes, if you're using a terminal emulator that has the ability to send each keystroke rather than line-by-line, and doesn't suppress key-repeat. As above, don't accumulate incoming keystrokes but when you're looking for another, drain the buffer first then watch for an incoming one. If you don't find it within <TIMEOUT>, stop moving. <TIMEOUT> should be slightly longer than the key-repeat interval.
(I like my second way better - winging it at the keyboard, heh! - but if it were me, I'd probably try both anyway just for what I could learn from either one).

For wiring it on a keyboard is there any way to read in data/keystrokes and have a live stream being implemented in the arduino; Example press up the the hand moves up until i let it go?

In case I used an unfamiliar idiom, "Winging it" means doing something without a great deal of fore-thought or research, similar to "off the cuff", if that helps. In this case I meant I was thinking and forming new ideas, even as I was typing the first idea I had thought of.

gotcha, sorry for that


text:
upload real time ultrasonic sensor data to pubnub using arduino and esp8266
I want to upload the real time data of ultrasonic sensor attached to my Arduino  Uno and I have been using esp8266 module for the WiFi connection.
I want to upload to PubNub but I don't know how to start writing the code for PubNub and where do I have to write the code.
I have the code working on my Arduino using the ultrasonic sensor in C++ language, printing the readings on the serial monitor. However, the code will be definitely changed in order to upload the sensor readings to PubNub.
On PubNub the most used SDK is JavaScript and I'm not very familiar to it. For C++ the most used SDK is Posix but it seems way more difficult more than JavaScript. So how I have to translate the code from C++ to JavaScript to get it published on PubNub?
Sorry, I am completely new to this stuff therefore I don't know much about it.

The PubNub website has a link to an Arduino library:
https://github.com/pubnub/arduino
Although it doesn't have specific support for the ESP8266 per se, it does support the Arduino Ethernet Shield, Arduino Wifi Shield and Arduino Wifi101 Shield, so I would imagine it wouldn't be hard to adapt the code.
Be aware that for the Arduino Uno, the SRAM will be fairly limited, where as the  ESP8266 contains 96 KB of DRAM.


text:
Is Arduino IDE enough to program with C or C++?
I am using Arduino IDE to program my ATmegas with bootloaders. I can directly manipulate ports, use timers, interrupts, PWM pins and timers, etc. Everything is working.
But this question arises: Does the Arduino IDE differ from AVR Studio in terms of using C or C++ on an ATmega chip?
I know AVR Studio has some features or something. My question is not about that. My question is that I am coding everything, not using extra libraries, features etc.

In terms of the core language features, there's virtually no difference. In the background, the Arduino IDE and Atmel/AVR Studio both use GCC to compile the code.
GCC is an excellent toolset which supports all the core language features of C++. Admittedly, the version which currently comes with the Arduino IDE is a little old, so it doesn't support C++11 onwards. However, a lot of C++11 features are not very relevant or useful for microcontroller programming anyway (e.g. threading).
You're also likely to use the same standard library for both, which is AVR Libc. It provides pretty much all the standard C functionality that you're likely to use in an AVR project. It doesn't include the C++ stuff though, such as streams, containers, and algorithms. These tend to be very resource-hungry though, so are best avoided anyway.
The major difference is basically flexibility. Atmel/AVR Studio is designed to let you work on a wide range of projects and customize the build to suit very specific needs. You can also use alternative libraries with it more easily. In theory, the Arduino IDE can be modified in similar ways, but it's a major hassle because it provides no GUI to do it.
It's also important to note that the Arduino IDE does a number of non-standard things, such as re-organising declarations and including libraries in strange ways. It's designed to be more user-friendly, but often ends up just getting in the way. There are usually ways to work around those issues though.

I absolutely got the point. I got the answer I am looking for. Thank you.

It is unclear exactly what you are asking. The Arduino is different to most computers - it has NO OS (if you exclude the bootloader).
You can use a c/c++ compiler which translates your code to machine code. If you include libraries this may include machine code which someone else has compiled into a library.
You could write 100% of your code in assembler and produce exactly the same result.
Even in the good (bad?) old days of the 1970s before we had compilers on microprocessors it was common to have prewritten code (libraries) for common functions.
You haven't lived until you have written your own assembler (hand coded).

For my type of projects, assembly would be too complicated.

@milliways - I've written only parts of a hand coded assembler (never finished), BUT I started programming in machine language on a 6800 (6802 mostly). ie no assembler - write mnemonics, compile "in head", hand calculate relative branches, key in code from hand drawn listing with hex keypad (occasionally binary switches). Creed 7B baudot printer "after a while". I submit for your valued consideration that that qualifies as "having lived" in this context :-). No?. [As you might expect, I recently had my 1,000,000 th birthday].

1,000,000th birthday in binary isn't that old :)


text:
Pause code untill a button is pressed
I need some code to pause the Arduino code until a button is pressed. I have a long program and at point I need a condition that if a Button on pin A2 is pressed then go forward, otherwise wait.
I tried using if with a condition but it failed for my purpose. I think this is because when if(...) detects that the button is not pressed, it moves to next lines (as usual). But I have a long program and I want to wait forever until the button is pressed.

Is it active high or active low (are you using pullup or pulldown resistors)?

See my edit please. I am just using a Pushbutton with a resistor. I tested the button with different programs. It all works fine.

You haven't answered my question though.  Is the resistor connected to +5V or to GND? It makes a big difference to the code snippet I will spoon feed you.

The resistor is connected to Ground. Help me

The construct you are looking for is called while.
Instead of doing "If the button is pressed then continue" you need to do "while the button is not pressed do nothing".
Assuming you have an "active low" button (that is, a resistor pulling it up to +5V when not pressed, so digitalRead(A2) == LOW is "pressed"), you can do:
while (digitalRead(A2) == HIGH) {
  // Do nothing
}

So while it's not pressed (digitalRead(A2) == HIGH) don't do anything.  As soon as digitalRead(A2) returns LOW (so it is not == HIGH any more) the while loop will finish and your sketch can continue.
I write all about the while loop in an article here.

will it continue right from where it has stopped..? Lets say if my motor is at 67 degrees it should resume from the same. Is it doing the same..?

I need a code to pause arduino code until a button is pressed.

I wrote a simple function to do this.
Usage:
buttonWait(<pin_number>);

Code:
/* the function */
void buttonWait(int buttonPin){
  int buttonState = 0;
  while(1){
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH) {
      return;
    }
  }
}

void loop() {
  buttonWait(2); // wait for button press on pin 2
  // do something
  // ...
}

This code assumes that you have a pulldown resistor, but you can easily modify it to work with a pullup resistor instead, if you feel the need:

simulate this circuit – Schematic created using CircuitLab
See example code here!

Thank you rahuldottech!! I had been fussing with my code for several months on and off and tonight...I hit gold!!

@Osprey That's great to hear! :)

The battery doesn't make sense in that circuit. you have it wired to use +5V from VCC, which is correct, but why have a battery hooked to +5V? (Unless you are planning to bypass the internal regulator and the battery is really a regulated 5V supply?)

Here are two ways you might have wired the button. If you wired it with a pullup, you will need to test for LOW (the button will ground its output when pressed). If pulldown, the button will raise its output when pressed and you would test for HIGH.
If you will be testing the button again within less than a second, don't forget to debounce it. Switches send a bunch (technical term :) of pulses for a significant fraction of a second during a make or bread. See Nick Gammon's "Switches" page for a thorough discussion.

Pausing a program can be accomplished using Light Sleep mode as demonstrated in given URL: https://www.youtube.com/watch?v=GIbSt5mJ5VY

Welcome to Arduino! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.


text:
Dot Matrix Display with Arduino UNO (PROBLEM)
I faced a problem in my graduation project and I hope you can help me to solve it :)

My project is connecting Arduino Uno to 16x32 Dot Matrix Display(DMD) and display messages on it from VB.net program. I wrote my VB.net program to convert the input text into 2D binary array. The number of columns depend on the text width.
as we know Arduino Uno SRAM is too small just 2 KBytes, so can't receive all the columns and display it.
I tried to receive 100 columns in the Arduino code and display it, then send star * to computer to receive the second 100 columns and display it and so on but it didn't work. I see the RX and TX of Arduino LEDs flicker but then nothing gets displayed on the DMD.
Can anyone tell me where is the error part in the code, or if you have another idea to solve this problem :)
VB.net Code for sending the 2D array ar(,)
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        SerialPort2.Open()
        Dim la As String
        If CheckBox1.Checked Then
            la = "arabic"
        Else
            la = "english"
        End If
        SerialPort2.Write("#" + cols.ToString + "#" + "*" + la + "*")
        Dim INDEX As Integer = 0

        While INDEX <= cols
            Dim see As String = SerialPort2.ReadLine().ToString()
            If see = "*" Then
                Dim BUFFER(16) As Byte
                For I = INDEX To INDEX + 100
                    If I < cols Then
                        For J = 0 To rows - 1
                            BUFFER(J) = ar(I, J)
                        Next
                        SerialPort2.Write(BUFFER, 0, 16)
                    End If
                Next
                INDEX += 100
            End If
        End While
        SerialPort2.Close()
End Sub

C++ Code for receiving 100 columns and display them:
#include <SPI.h>
#include <DMD2.h>

SoftDMD dmd(1,1);
void setup() {
  Serial.begin(9600);
  dmd.setBrightness(255);
  dmd.begin();
}
long Wid;
void loop() {
  if(Serial.available()){
    String st = String(Serial.readString());
    Wid = (st.substring(st.indexOf('#')+1, st.lastIndexOf('#'))).toInt();
    //String Language = st.substring(st.indexOf('*')+1, st.lastIndexOf('*'));
  }
  long ind = Wid ;
  while(ind >= 0 ){
    Serial.println("*");
    if(Serial.available()>1 ){
      boolean pixls[16][100];
      getArray(pixls);
      displayArray(pixls);
      ind-=100;
    }
    if(ind >=Wid){
      ind = wid ;
    }
  }
}

void getArray(boolean arr[16][100]){
  byte serialData[16];
  for(int k = 0 ; k < 100 ; k++){
    Serial.readBytes(serialData,16);
    for(int i = 0 ; i < 16 ; i++){
      arr[i][k]= serialData[i];
    }
  }
}

void displayArray(boolean arr[16][100]){
  for(int h = 0 ; h <= 100-33 ; h++){
    for (int i = 0 ,g=h; i < 32 ,g<h+32; i++ ,g++){
      for (int j = 0 ; j < 16 ; j++){
        dmd.setPixel(i,j,(arr[j][g] == 1) ? GRAPHICS_ON : GRAPHICS_OFF);
      }
    }
    delay(100);
  }
}

This VB code works for me when sending just 100 columns of the array:
SerialPort2.Open()

        Dim BUFFER(16) As Byte
        For J = 0 To 100
            For I = 0 To rows - 1
                BUFFER(I) = ar(J, I)
            Next
            SerialPort2.Write(BUFFER, 0, 16)
        Next
        SerialPort2.Close()

C++ code:
#include <SPI.h>
#include <DMD2.h>
SoftDMD dmd(1,1);

void setup() {
  Serial.begin(9600);
  dmd.setBrightness(255);
  dmd.begin();
}
void loop() {
    boolean pixls[16][100];
    for(int i=0 ;i<100 ; i++){
      for(int j=0 ;j<16 ; j++){
        pixls[j][i]=0;
      }
    }
    if(Serial.available()>0){
      getArray(pixls);
      for(int i=0 ; i<100 ; i++)
      {
        displayArray(pixls);
      }
    }
}
void getArray(boolean arr[16][100]){
  byte serialData[16];
  for(int k = 0 ; k < 100 ; k++){
    Serial.readBytes(serialData,16);
    for(int i = 0 ; i < 16 ; i++){
      arr[i][k]= serialData[i];
    }
  }
}

void displayArray(boolean arr[16][100]){
  for(int h = 0 ; h <= 100-33 ; h++){
    for (int i = 0 ,g=h; i < 32 ,g<h+32; i++ ,g++){
      for (int j = 0 ; j < 16 ; j++){
        dmd.setPixel(i,j,(arr[j][g] == 1) ? GRAPHICS_ON : GRAPHICS_OFF);
      }
    }
    delay(100);
  }
}

but it didn't work. - what happens? Does anything get displayed?

nothing get displayed but there is flicker in RX and TX of arduino leds

I make some edit on my post please read it again :)

I suggest some debugging displays. It seems weird to me to convert characters into pixels and send them one byte at a time from one processor to another. Can't you at least send as 8 bits in one byte? I'm not going to guess what is being generated on one end, and how that is being processed on the other. That is why you put debugging "prints" inside your code. To find out for yourself.

  boolean pixls[16][100];

You are running out of RAM, amongst other possible problems.
That array alone takes 1600 bytes out of 2048 on the Uno. Since you are using Serial that also takes:

34 bytes for the HardwareSerial instance (Serial)
64 bytes for the Serial transmit buffer
64 bytes for the Serial receive buffer
4 bytes for the Serial transmit buffer head and tail pointers
4 bytes for the Serial receive buffer head and tail pointers

That's another 170 bytes.
SoftDMD dmd(1,1);

I presume that also uses RAM.
You need to rework. You don't need to store 100 bytes before displaying. How about reading each byte and displaying it? That saves almost 1600 bytes.

i tried to receive just 100 columns and displaying them ,and it works well

@HaithamAL-Cigeary I suggest sending the ASCII text to the Arduino and then letting the font library within SoftDMD convert it to pixels.

You have likely run out of RAM.
The following use up large chunks of your SRAM:

pixls array = 1600 bytes
Serial = 170 bytes
DMD > 64 bytes

This is in addition to all your other variables and function calls.
The problem is that the compiler promotes boolean variables to bytes. So where you need 1600 pixels it takes 1600 bytes. Alternatively, you could pack 8 pixels into that byte. This method would only consume 200 bytes instead of 1600.
Also, I don't understand why you have a 16 by 100 array. From the code I can see that you are using a single DMD which has 32 pixels wide by 16 pixels high. Why send/buffer more pixels than needed? A single DMD would only need an array of 64 bytes.
The Arduino Uno only has 2KB of SRAM.
Solutions:

I suggest sending the ASCII text to the Arduino and then letting the font library within SoftDMD convert it to pixels. That is why you are using the DMD2 library.

However if you want to stick to the approach you have taken:

Pack 8 pixels into every byte in the array. This will save 1400 bytes of precious SRAM.
Only send one DMD word of data at a time. This will save 1536 bytes of precious SRAM.
You could use an Arduino with a greater amount of SRAM.

Arduino Mega  - 8KB SRAM
Arduino ZERO  - 32KB SRAM
Arduino Due   - 96KB SRAM
Arduino MKR 1000/1010/1400/ZERO - 32KB SRAM


text:
Program an ATMega328P and use it without Arduino board
I'd like to use an ATMega328P for my project, I hope to do it without the Arduino board.
I know with the Arduino IDE and an Arduino board I can program the microcontroller. However, would it be possible once I've programmed and debugged the program with Arduino IDE + Arduino board, to take away the microcontroller from the Arduino board and to use the ATMega328P separately, without the board?
If yes, what additional configurations I should do the ATMega328P to work correctly on the breadboard?

Use ATMEGA328 P-PU with Arduino UNO bootloader....you can find it in hobby stores and online and stuff ☺

Using the bare chip is absolutely feasible and no problem whatsoever.

This is not the same question as your but you might get some bits of information from it.  https://arduino.stackexchange.com/questions/32970/sense-checking-arduino-uno-barebones-schematic

You can follow answers of This Question

Yes you can use ATMega328P without arduino board. I always use the IC without arduino. There are two ways of doing it.

You can use arduino board with the IC. Program the IC and then take it out and use it in your circuit. You will have to use 16MHZ Oscillator with capacitors.
If you don't have arduino board, you can use other programmers like USBasp to program your Atmega328p. In this case, do not use the direct upload button instead use the upload using programmer options from file menu. Do not forget to select board as Arduino Pro or Pro Mini (5v, 16mhz) With ATmega328 and programmer as USBasp.

NOTE: Refer to Atmega328p Pin Mapping and program your device accordingly. Enjoy!

You can remove an ATMEGA from an Arduino and use it in your own board, however when used on a typical Arduino board the chip will be fused for an external crystal as a clock source, rather than the (simpler but less accurate) internal clock.
You cannot change the clock source over ISP unless the clock source the chip is currently expecting is operational, so if you want to change the clock selection you will want to do that before removing the chip from the Arduino.
However, you can also provide a clock crystal and its two capacitors (or a substitute resonator which often has this built in) on your external board.
Typically chips (even those pre-flashed with a bootloader as a convenience) are cheaper than boards, so it's unclear why you would want to move the same chip off the Arduino as opposed to using another.  You will want a USB-logical level serial adapter anyway, and once you have that you can do development on the bare chip on your board, even if you do initial testing on the Arduino.  In a pinch if you don't have the USB converter you can either pull the chip out of an Arduino board and run wires from its D1 and D0, or hold the on-board chip in reset to allow you to borrow those serial lines without interference.

My idea is to use only a microcontroller without a board. As it is easy to program an Arduino, I thought I may chose an ATMega. So, I have an Arduino uno, my idea is to buy only one ATMega and to program it and debug it using the uno board. However, I've just reaslised that if I separate the ATMega from the Arduino, I would need to add components(crystal, pull up resitances..). Can you please explain what you mean in the last paragraph of your post? Is there a simple way to program directly an ATMega(or any other microcontroller) without using the arduino IDE? Thanks.

While you can skip the IDE, using it or not is essentially irrelevant to the complexity of your circuit, as you can either use the IDE or not with a circuit that either has or doesn't have an external clock and either using a USB-serial on your target board, on a cable, or by programming your sketch with an ISP programmer.  Yanking a chip off a board gets you nothing compared to just buying a chip either with a bootloader or without and loading one yourself, potentially using your intact Arduino as an ISP programmer, or using ISP to directly load your sketch without a bootloader.

Search for "Build an Arduino" - you'll find tons of how-to articles about doing just that. You'd need to be able to solder connections on a printed-circuit board (and not even that if you wanted to use a solderless breadboard), but it's really straightforward. You can even build it first and program the MCU on the PCB using an FTDI cable. I use an Arduino board and a solderless breadboard to experiment with unfamiliar parts, but I usually go immediately to a hand-built board once I'm familiar with all of the components I'll be using.
Prototyping with the Arduino board lets you throw together a bunch of parts and get something working quickly, and if the Arduino is more capable than your final target - f/ex, a Mega 2650 - you can temporarily ignore the memory and I/O constraints of the smaller device.


text:
Arduino Upgrading from 1.0.6 to 1.6, code doesn't work anymore
I'm using Arduino UNO, and today I upgraded my IDE from 1.0.6 to 1.6, just to upgrade, nothing special.
I got my libraries again but I got an error with a code that was working OK.
The error was:
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:223:0,
                 from C:\Program Files (x86)\Arduino\libraries\ModbusMaster-master\ModbusMaster.h:53,
                 from C:\Program Files (x86)\Arduino\libraries\ModbusMaster-master\ModbusMaster.cpp:32:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h: In member function 'HardwareSerial& HardwareSerial::operator=(const HardwareSerial&)':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ubrrh', can't use default assignment operator
 class HardwareSerial : public Stream
       ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ubrrl', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ucsra', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ucsrb', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_ucsrc', can't use default assignment operator
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:83:7: error: non-static const member 'volatile uint8_t* const HardwareSerial::_udr', can't use default assignment operator
C:\Program Files (x86)\Arduino\libraries\ModbusMaster-master\ModbusMaster.cpp: In member function 'void ModbusMaster::begin(uint16_t)':
C:\Program Files (x86)\Arduino\libraries\ModbusMaster-master\ModbusMaster.cpp:139:16: note: synthesized method 'HardwareSerial& HardwareSerial::operator=(const HardwareSerial&)' first required here
       MBSerial = Serial;
                ^

I couldn't find the real error, can someone help me?

Can you share the whole sketch?

Libraries for 1.0 aren't automatically compatible with 1.5 or 1.6. You can just comment out all the assignments like MBSerial = ... and replace all calls to MBSerial.whatever to Serial.whatever in ModbusMaster.cpp.

Thanks Gerben, I tried changing the ModbusMaster.cpp but it still does not work. But the IDE haven't change the things that I was expecting, so the easy way for me is to go back to the 1.0.6 version. But thanks man.

Judging by the error messages you were using a ModbusMaster library from GitHub such as this one and the HardwareSerial library from the Arduino IDE.
I think the key is in the statement:

I got my libraries again

I would suggest that you have downloaded a different library to what you originally used. Even if you did get the same repository, these libraries are also constantly changing and your code sometimes has to evolve with the library.
You have several errors (with the SoftwareSerial library): non-static const member, can't use default assignment operator. Essentially the program is trying to assign a value to a const or perhaps assigning a constant pointer to non-const data. Find more information on the error here and here. All of these errors stem from line 83 of HardwareSerial.h.
The last line(s) give the clue. You are assigning your instance of your Serial object to you MBSerial object.

You should not have added libraries to the Arduino files in the "C:\Program Files (x86)\Arduino" folder in the first place.
That is only for the Arduino program files and standard libraries that are included with the Arduino IDE.
Could you uninstall the Arduino and serial drivers. Remove also the "C:\Program Files (x86)\Arduino" folder, to be sure that absolutely nothing is left behind, because that will interfere with a new version that will be installed. Remove also the hidden "arduino15" folder(s).
Do you know the location of your sketches, it is in the preferences and is often "Documents\Arduino". Go to that folder and go into the "libraries" folder. Remove unused libraries or libraries that have been included in the Arduino files.
Do you have Java installed ? Some Java versions are not compatible with the Java files of the Arduino. If you don't need Java, then uninstall it.
Install the newest Arduino 1.8.3 from Arduino.cc Software.
Use the Library Manager in the Arduino IDE, and search for modbus. Install the "ModbusMaster by Doc Walker" with the Library Manager. The modbus library that will be installed is this one: Github 4-20mA ModbusMaster.
There has been a few changes, for example with PROGMEM. All PROGMEM data must now be 'const'. You might have to make a few adjustments.


text:
what voltage level is a digital low for the interrupt mode LOW?
I am learning about interrupts and one of the interrupt modes is LOW which triggers anytime the pin is a digital low.
Can someone tell me what voltage that is for an Arduino nano? I did a google search and it said a LOW can be anywhere from 0 to 2V.
I am making a project using a nano and I am powering it with batteries. It would be great if I could set up an interrupt to turn on an LED when the batteries were getting weak so I would know when to change them.

triggers anytime the pin is a digital low ... this is bad thinking ... it should be triggers anytime the pin transitions from high to low ... there is a vast difference between the two

It would be great if I could set up an interrupt to turn on an LED
when the batteries were getting weak

That won't work. The thresholds for the pin registering LOW or HIGH
depend on the supply voltage. Very roughly:

a pin in guaranteed to register LOW if its voltage is below ⅓ Vcc
it is guaranteed to register HIGH if it's above ⅔ Vcc
nothing is guaranteed between ⅓ and ⅔ of Vcc.

For the exact voltage levels, you should check the datasheet.
Note also that those are guaranteed levels. The actual thresholds are
closer to ½ Vcc, with an hysteresis of roughly Vcc/10.
For detecting a low battery condition, you should use the ADC, combined
with either a voltage divider on Vcc or the internal bandgap reference.

Thank you Edgar! I didn't think it would work the way I was wanting it to. That is why I reached out to you folks who are much smarter than I am. I appreciate you answering my question.


text:
How can I program an arduino in pure C/C++?
I am a beginner and I want to learn AVR C/C++. Can I do this using an Arduino?  (I'm asking this because I already have one).
If so, could someone tell me using which IDE can I write code in pure C/C++ and then flash it to the Atmega328P on the Arduino?  Or, should I get an AVR and a programmer instead?
I've searched all over the internet and I'm really confused by all the terminology. Could someone explain it to me?

So in order to program the 328 I believe you need to install atmel studio to compile your code and then use the command line command avrdude to put your compiled code onto the arduino.

@Treesrule14 that's a possibility, but not the only one, so it's untrue to say that it is necessary.  If the Arduino IDE is installed, then so is the avr-gcc compiler on which it depends.

@Treesrule14 I have the atmel studio installed. I just cannot find any resources that might help me flash a program to the chip on the arduino using a bootloader (without a programmer). Is this even possible?

I believe you need a programmer. : (

You don't need any IDE. You can compile and upload using the toolchain that comes with Arduino. Look at Arduino.mk for example.

@Treesrule14 - wrong again, you do not need a programmer.  Avrdude will talk to the bootloader on the arduino just as readily to upload a hex file compiled from a stand alone C program as it will to upload one built by the Arduino IDE.

@ChrisStratton totally didn't see your first post sorry about that. Have you tried programming with avr-gcc over usb?

avr-gcc is a compiler, not a download tool. But anyone who has every used to the Arduino IDE with a USB-connected arduino has done so, yes.  And I and many others have done it with plain C programs built from the command line with avr-gcc and flashed from the command line with avrdude (which is, after all, what the Arduino IDE quietly does on behalf of its user).  There are many writeups online, it's a task beyond trivial summary in an SO answer.

Yes, get an AVR programmer instead.
1) You can flash your arduino board with avrdude/avr-gcc. Install these tools, find the datasheet of atmega328 (google it), use the board pinouts to connect to your programmer (stk500v2/ISP) and voila!
2) Keep in mind that by "manually" flashing your atmaga on arduino board you're removing bootloader that is needed to load your sketches from ARDUINO IDE.
3) Use your favourite C/C++ IDE

you should be able to find and reflash the bootloader for the arduino look here http://arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader

No! You do not need a programmer, or to remove the bootloader.  The Arduino bootloader has zero dependence to the IDE or libraries - you are every bit as free to use it with stand alone C programs as with Arduino sketches.  Doing it that way is not only cheaper, but lets you use the same board for both styles of development with no configuration changes.

The author wanted to learn AVR in pure C. He didn't ask - hey guys, how to play with arduino IDE or someth. but how to reuse the atmega on board he already has.

@ChrisStratton since you disagree with the other answers Submit an Answer please

If you're a beginner, I suggest you write C in the Arduino IDE. The libraries are very useful and I think the Arduino/Wiring/Processing environment will cover all your needs.
Check out the Lightblue Bean (http://punchthrough.com/bean/) it is a good example of the power of that platform. Even experienced embedded programmers can use it, since the underlying register are still accessible.
I am now programming on the Ti MSP430, and while I can appreciate the possibilities, I miss the simplicity of Arduino; much easier to get started with Arduino.
Go to http://arduino.cc/en/main/software to download the 1.0.6. IDE software, plug your Arduino, go to Tools->Board to select your Arduino, select the appropriate "tty" port in the Tools->Serial_Port.
Then write in pure C and download. There are tons of examples included with the IDE.

An Arduino is programmed in C/C++. There is a common misconception that Arduino has its own language. See this link C++ vs. The Arduino Language? for a full discussion on Arduino being C/C++ and the simplifications Arduino offers. Further more, you can see the Arduino core code here.
From the Arduino website:

Can I program the Arduino board in C?
In fact, you already are; the Arduino language is merely a set of C/C++ functions that can be called from your code. Your sketch undergoes minor changes (e.g. automatic generation of function prototypes) and then is passed directly to a C/C++ compiler (avr-g++). All standard C and C++ constructs supported by avr-g++ should work in Arduino. For more details, see the page on the Arduino build process.

Arduino offers an easy learning curve for beginners through to experts. So simply download the latest Arduino IDE, install it and enjoy.

Another common misconception is that C is a subset of C++. Arduino core library is written in C++, so it's impossible to program in C using it.

I think this is the answer.


text:
a code to implement a simple traffic signal and also display on LCD which color is ON?
I have tried code given below for simple traffic signal and also display on LCD which color is ON, but it didn't work. Please me to make it work.

int red = 10;
int yellow = 9;
int green = 8;
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
    pinMode(red, OUTPUT);
    pinMode(yellow, OUTPUT);
    pinMode(green, OUTPUT);
}

void loop(){
    changeLights();
    delay(1500);
}

void changeLights(){
    lcd.print("red");
    digitalWrite(yellow,LOW );
    digitalWrite(red, HIGH);
    digitalWrite(green,LOW );
    delay(3000);
    lcd.print("yellow");
    digitalWrite(yellow,HIGH );
    digitalWrite(red,LOW );
    digitalWrite(green,LOW );
    delay(3000);
    lcd.print("green");
    digitalWrite(yellow,LOW );
    digitalWrite(red,LOW );
    digitalWrite(green,HIGH );
    delay(3000);
    //if(
}

What is not working? What should it be doing?

The LCD won't work unless you begin it...

You need to provide more information. What doesn't work? Have you tried a simple sketch that just turns on one of your lights, then edit it to turn on the next, and then the last? (You need to use the simplest possible code to rule out hardware problems)

Write a sketch to test your LCD.
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 4, 2);
void setup(){
    lcd.begin();
    lcd.print("Hello World!");
}
void loop() {
    lcd.setCursor(0, 1);
    lcd.print(millis() / 1000);
}

Make sure the R/W pin is connected to GND on your breadboard. You may need to connect the contrast pin to 5V. Ideally it should be connected to the wiper of a 10KOhm trimpot with either end connected to GND & 5V (so you can vary the contrast).
Once that set-up works change your code
 void setup(){
     lcd.begin();
     lcd.print("Traffic signals");
     delay(500);
     pinMode(red, OUTPUT);
     pinMode(yellow, OUTPUT);
     pinMode(green, OUTPUT);
 }

 void loop(){
     changeLights();
     lcd.setCursor(0,0);
 }

A small update to your code

Added lcd.begin(); function
added lcd.clear(); function so that old characters will be removed before adding new display

Here is the complete code
int red = 10;
int yellow = 9;
int green = 8;
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green, OUTPUT);
}

void loop() {
  changeLights();
  delay(1500);
}

void changeLights() {
  lcd.clear();
  lcd.print("red");
  digitalWrite(yellow, LOW );
  digitalWrite(red, HIGH);
  digitalWrite(green, LOW );
  delay(3000);
  lcd.clear();
  lcd.print("yellow");
  digitalWrite(yellow, HIGH );
  digitalWrite(red, LOW );
  digitalWrite(green, LOW );
  delay(3000);
  lcd.clear();
  lcd.print("green");
  digitalWrite(yellow, LOW );
  digitalWrite(red, LOW );
  digitalWrite(green, HIGH );
  delay(3000);
  //if(
}

The output would look like this:

Here is the link to the Arduino simulator example