message:
Arduino on battery getting unstable if temperature falls

i am building an outdoor sensor with a combination of a custom Arduino board and a battery (+solar charging). I experience strange behavior when the temperature falls below a certain value (i can reproduce it by putting it in the freezer), regardless which type of battery i am using. The custom Arduino runs without power-regulation, straight from the 3.7volts the battery can provide.
How can i prevent this to happen? I guess a little heating would be not really a solution as i am trying to consume as less energy as possible.
Would a (step up) regulator possibly help? Any other ideas?

---Update---
Thanks to your comments here i figured out, that the AVR 328p should not be operated below a voltage of 3.7v if run at 16Mhz. As i am running with a 3.7v LiPo Battery that could easily explain my problem i guess. My first try to decrease the processor speed to 8Mhz with a Prescaler worked, but the GSM Fona does not seem to like it. So i would like to try something in between like 10Mhz or 12Mhz. As the prescaler does not support this, my question is: can i just use another crystal or would i have to modify something in the code/bootloader as well?

body:
To answer your modified question:

Running the ATmega328p at 16Mhz with 3.7v is out of spec - see [this EESE answer][1] for reference or the ATmega datasheet - so the obvious solution would be to lower its speed to 8Mhz.

But since you also mentioned that there is an additional GSM breakout board involved (Adafruit Fona), which expects UART (in auto-baud mode) Rx/Tx connection, it might not be that trivial. Further exploration of the Fona library's source code reveals that it has several hard-coded delays (see `Adafruit_FONA.cpp::begin`, for example), but its core seems to be implemented inside the `Adafruit_FONA::readline` method, which uses an underlying `Stream`, which in turns comes from a Software/Hardware serial object, as shown in the `FONAtest.ino` example that comes with the library.

From my experience, Software/Hardware serial should work fine on 8Mhz, except maybe when [using high baud rates][2], which is solvable.
The hard-coded delays doesn't look like they should cause actual damage except for delay, but you could cut them in half just to see if you can make the library work.

Additional aspect that you should consider is the comment from Adafruit's Fona product page, regarding pin **Vio**:

> This is the pin that you MUST drive with an external voltage from
> 3V-5V to set the logic level converter

So, despite that from the datasheet, the Fona seems to have a voltage regulator, you might still want to consider adding a decoupling capacitor between Vcc and Gnd of your battery, to  mitigate transient current draws from any component in your circuit.

  [1]: https://electronics.stackexchange.com/questions/58818/programming-3-3v-atmega328-running-at-16mhz
  [2]: http://forum.arduino.cc/index.php?topic=212962.0


sender: user

message:
Interfacing Hex keypad with arduino

I was trying to interface my hex keypad with Arduino. I declared rows as input and columns as output. When I initialize three of the four columns as HIGH and one as LOW, and detect the button pressed as LOW in the corresponding row, it works fine. That is, it detects the button when its corresponding row and column is LOW. But, when I reverse the condition, i.e. when I try to detect the button pressed when its corresponding row and column is high while others are low, it does not work as expected.

I really want to know why is this happening?

The code that works:-

    int row[]={6,7,8,9};
    int col[]={10,11,12,13};
    int i,j;
    int col_scan;
    void setup()
    {
       Serial.begin(9600);
       for(i=0;i<=3;i++)
       {
          pinMode(row[i],OUTPUT);
          pinMode(col[i],INPUT);
          digitalWrite(col[i],HIGH);
       } }
    void loop()
    {
       for(i=0; i<=3; i++)
       {
          digitalWrite(row[0],HIGH);
          digitalWrite(row[1],HIGH);
          digitalWrite(row[2],HIGH);
          digitalWrite(row[3],HIGH);
          digitalWrite(row[i],LOW);
          for(j=0; j<=3; j++)
          {
      col_scan=digitalRead(col[j]);
      if(col_scan==LOW)
      {
         keypress(i,j);
         delay(300);
      }}
       }}
    void keypress(int i, int j)
    {
       if(i==0&&j==0)
          Serial.println("1");
       if(i==0&&j==1)
          Serial.println("2");
       if(i==0&&j==2)
          Serial.println("3");
       if(i==0&&j==3)
          Serial.println("A");
       if(i==1&&j==0)
          Serial.println("4");
       if(i==1&&j==1)
          Serial.println("5");
       if(i==1&&j==2)
          Serial.println("6");
       if(i==1&&j==3)
          Serial.println("B");
       if(i==2&&j==0)
          Serial.println("7");
       if(i==2&&j==1)
          Serial.println("8");
       if(i==2&&j==2)
          Serial.println("9");
       if(i==2&&j==3)
          Serial.println("C");
       if(i==3&&j==0)
          Serial.println("*");
       if(i==3&&j==1)
          Serial.println("0");
       if(i==3&&j==2)
          Serial.println("#");
       if(i==3&&j==3)
          Serial.println("D");
    }

the code that doesn't work:-

    int row[]={6,7,8,9};
    int col[]={10,11,12,13};
    int i,j;
    int col_scan;
    void setup()
    {
       Serial.begin(9600);
       for(i=0;i<=3;i++)
       {
          pinMode(row[i],OUTPUT);
          pinMode(col[i],INPUT);
          digitalWrite(col[i],LOW);
       } }
    void loop()
    {
       for(i=0; i<=3; i++)
       {
          digitalWrite(row[0],LOW);
          digitalWrite(row[1],LOW);
          digitalWrite(row[2],LOW);
          digitalWrite(row[3],LOW);
          digitalWrite(row[i],HIGH);
          for(j=0; j<=3; j++)
          {
      col_scan=digitalRead(col[j]);
      if(col_scan==HIGH)
      {
         keypress(i,j);
         delay(300);
      }}
       }}
    void keypress(int i, int j)
    {
       if(i==0&&j==0)
          Serial.println("1");
       if(i==0&&j==1)
          Serial.println("2");
       if(i==0&&j==2)
          Serial.println("3");
       if(i==0&&j==3)
          Serial.println("A");
       if(i==1&&j==0)
          Serial.println("4");
       if(i==1&&j==1)
          Serial.println("5");
       if(i==1&&j==2)
          Serial.println("6");
       if(i==1&&j==3)
          Serial.println("B");
       if(i==2&&j==0)
          Serial.println("7");
       if(i==2&&j==1)
          Serial.println("8");
       if(i==2&&j==2)
          Serial.println("9");
       if(i==2&&j==3)
          Serial.println("C");
       if(i==3&&j==0)
          Serial.println("*");
       if(i==3&&j==1)
          Serial.println("0");
       if(i==3&&j==2)
          Serial.println("#");
       if(i==3&&j==3)
          Serial.println("D");
    }

sender: assistant

body:
To use unipolar switches as inputs, you need pulling resistors to give the input pin a defined value when the switch is open.

The ATmega has software configurable internal pullups.  Even if these are not configured, implementation detail may (or may not) yield a very weak *unreliable* pullup effect.

There is no configurable pulldown on the ATmega.  To operate in that direction (with a switch to high) you would need external pulldown resistors.

A few matrix keyboards include diodes, to combat some of the confusion which results when multiple keys are pressed in a simple matrix.

Also, you should add a tiny delay between driving and reading, in order to allow for capacitive delay.


message:
Simultaneous input output in arduino mega

I need to read 5 analog pins simultaneously , is it possible?

note that:

analogRead(1);

analogRead(2);

analogRead(3);

will not work this case

body:
No, it is not. The ADC in the MCU is only capable of sampling a single analog channel at a time.

If you require sampling more than one channel at a time then you will need to use one or more external ADCs that are capable of sampling multiple channels, or multiple ADCs each dedicated to a single channel.


message:
Random(min,max) Function only giving ~50 range no matter what the values?

I can't get the min,max range to function properly. Monitoring the serial, only gives out ~50 difference from the min. I then added truerandom.ino to try to fix, but no help.

    const int ledPin = 13; // the number of the LED pin
    // Variables will change:
    int ledState = LOW; // ledState used to set the LED
    long previousMillis = 0; // will store last time LED was updated
    // the follow variables is a long because the time, measured in miliseconds,
    // will quickly become a bigger number than can be stored in an int.
    //long interval = random(800, 8000); // interval at which to blink (milliseconds)
    void setup() {
    // set the digital pin as output:
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
    }
    void loop()
    {
    // here is where you'd put code that needs to be running all the time.
    // check to see if it's time to blink the LED; that is, if the
    // difference between the current time and last time you blinked
    // the LED is bigger than the interval at which you want to
    // blink the LED.
    long interval = random(800,8000);
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
    ledState = HIGH;
    else
    ledState = LOW;
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
    Serial.println(interval);
    }
    }

Added truerandom.ino still ~50 range:

    // TrueRandomSeed.ino
    //   This example sketch shows how to provide a truly random seed value to the built in
    //   library pseudo random number generator.  This ensures that your sketch will be
    //   using a different sequence of random numbers every time it runs.  Unlike the
    //   usually suggested randomSeed(analogRead(0)) this method will provide a much more
    //   uniform and varied seed value.  For more information about the basic technique used
    //   here to produce a random number or if you need more than one such number you can
    //   find a library, Entropy from the following web site along with documentation of how
    //   the library has been tested to provide TRUE random numbers on a variety of AVR
    //   chips and arduino environments.
    //
    //   https://sites.google.com/site/astudyofentropy/project-definition/
    //           timer-jitter-entropy-sources/entropy-library
    //
    //   Copyright 2014 by Walter Anderson, wandrson01 at gmail dot com
    //

    #include <avr/interrupt.h>
    #include <avr/wdt.h>
    #include <util/atomic.h>
    // The following addresses a problem in version 1.0.5 and earlier of the Arduino IDE
    // that prevents randomSeed from working properly.
    //        https://github.com/arduino/Arduino/issues/575
    #define randomSeed(s) srandom(s)

    volatile uint32_t seed;  // These two variables can be reused in your program after the
    volatile int8_t nrot;    // function CreateTrulyRandomSeed()executes in the setup()
                             // function.
    const int ledPin = 13; // the number of the LED pin
    // Variables will change:
    int ledState = LOW; // ledState used to set the LED
    long previousMillis = 0; // will store last time LED was updated

    void CreateTrulyRandomSeed()
    {
      seed = 0;
      nrot = 32; // Must be at least 4, but more increased the uniformity of the produced
                 // seeds entropy.

      // The following five lines of code turn on the watch dog timer interrupt to create
      // the seed value
      cli();
      MCUSR = 0;
      _WD_CONTROL_REG |= (1<<_WD_CHANGE_BIT) | (1<<WDE);
      _WD_CONTROL_REG = (1<<WDIE);
      sei();

      while (nrot > 0);  // wait here until seed is created

      // The following five lines turn off the watch dog timer interrupt
      cli();
      MCUSR = 0;
      _WD_CONTROL_REG |= (1<<_WD_CHANGE_BIT) | (0<<WDE);
      _WD_CONTROL_REG = (0<< WDIE);
      sei();
    }

    ISR(WDT_vect)
    {
      nrot--;
      seed = seed << 8;
      seed = seed ^ TCNT1L;
    }

    void setup()
    {
      CreateTrulyRandomSeed();
      randomSeed(seed);
      pinMode(ledPin, OUTPUT);
      Serial.begin(9600);
      // The preceeding two function calls will take approximately 0.5 second to execute if
      // nrot is set to 32 ... the rest of your setup code should FOLLOW from here.
    }

    void loop()
    {
      long interval = random(800,8000);
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
    ledState = HIGH;
    else
    ledState = LOW;
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
    Serial.println(interval);
    }
    }

body:
I suspect it actually is generating other values and it's your program logic that's at fault.

Here's what I think you meant your program to do:

 1. Generate a random interval.
 2. Wait until that interval has elapsed.
 3. Start again with a new interval.

Here's what's actually happening:

 1. Generate a random interval.
 2. Check if that interval has elapsed.
 3. Whether or not it has elapsed, generate a new random interval anyway.

Note that you're generating a new random interval **every time round `loop()`**. This means your condition just keeps trying new random intervals until one happens (by chance) to be less than the amount of time that's elapsed since the last interval. You're only outputting the interval when that occurs, and evidently it happens on average at least every 50ms.

You can test this theory by outputting `interval` to serial as soon as you've generated it (i.e. before the `if` statement). I think you'll find it will flood the serial monitor with a huge range of values.

Fixing the problem should be pretty easy. Just generate your first `interval` value during `setup()`. After that, only generate a new random `interval` value when the old interval has elapsed (i.e. inside the `if` block). Don't do it every time round the main loop.


body:
I had the same problem (random, milliseconds), and in my case what I needed to make was a toy, able to Blink its eye (LED) in a more human way, with variable intervals, so I used the basic "blink without delay" and tweaked until I got a result I wanted.
This is my first post here so I hope I'm doing it correctly. Here is the code that worked for me:

    const int ledPin =  13;      // the number of the LED pin
    unsigned long previousMillis = 0;        // will store last time LED was     updated

     long interval = 4000;           // starting interval at which to blink   (milliseconds)

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

    void loop()
    {
    digitalWrite(ledPin, HIGH);

    unsigned long currentMillis = millis();

    if(currentMillis - previousMillis >= interval)

    {
      // save the last time you blinked the LED
      previousMillis  = currentMillis;
      interval = random((3, 14) * 1000);

    Serial.println("Blink");
    Serial.println(interval);  // Just so I can confirm if the effect seems natural
    digitalWrite(ledPin, LOW);
    delay(250);
    digitalWrite(ledPin, HIGH);
     }
    }


message:
How can I speed up reading of an SD card?

I am working on a project using an Arduino as a web server.

Code:

    webFile = SD.open("index.htm");
    if (webFile) {
      while(webFile.available()) {
        client.write(webFile.read());
      }
    webFile.close();

This sends data line by line, leading to a long time to load the webpage. Is there a faster way to load this page?

body:
Well I have two ideas on the SD card side, though neither really seem *great* to me they could still help you. I read on the Arduino forum that the SD card R/W speeds generally come out to 600kB/s, I'm not really sure why, the Arduino SPI can go up to 8 MB/s and I didn't think there would be that much protocol/data-handling in SD.

 1. Sector R/W - As Chris Stratton said, this is an obvious method, it's probably much faster to do sector reads. You may have to greatly change your code to implement it, but I imagine you'd see performance increase in the end. Apparently there's an [unofficial library][1] for it, though it seems to impart some potentially serious limitations.
 2. RAM - This is the second thing that came to mind when thinking about the problem is that you could use external RAM, when not handling network transfers (Idling, should be most of the time) the Arduino transfers data to external SRAM which you add. [SPI RAM][2] is most likely the easiest to implement, but not likely to be any faster than an SD card. [Parallel RAM][3] is going to be difficult to implement, you'll likely need to write your own class/library, but it could be much faster than SPI RAM or an SD card.

I'm not actually sure if either of these would be any faster, it's all just theory and I hope others will share their thoughts. If you have trouble finding the download link for the SD Card library, it's right [here][4]. In that ZIP folder there's a file called *SDCARD*, just move that folder into your Arduino libraries folder on your computer.

  [1]: http://forum.arduino.cc/index.php?topic=52871.0
  [2]: http://www.mouser.com/ProductDetail/Microchip-Technology/23LC1024-I-P/?qs=sGAEpiMZZMt9mBA6nIyysHsFd6bhl6Edtfzw23Aiprk=
  [3]: http://www.mouser.com/ProductDetail/Alliance-Memory/AS6C4008-55PCN/?qs=sGAEpiMZZMtm4RFapVkzrPhqi0UYYSDeBu6Rrbtf4UA=
  [4]: https://code.google.com/p/mysudoku/downloads/detail?name=SDCARDsectors.zip&can=2&q=


body:
maybe you should use SdFat library; a library which is almost the same as the standard SD library, but also it can support Long Filenames.

I did some tests with read and write; it is most of the times > 60% faster!!
https://github.com/greiman/SdFat


message:
How do I replace a burnt atmega328 with a new atmega328(bootloaded) in arduino?

I have an arduino UNO with atmega 328 whose microcontroller got burnt. I bought a new atmega328. I have another working arduino with atmega8. I followed the instructions in http://arduino.cc/en/Tutorial/ArduinoToBreadboard but I got a little confused.

I burnt the bootloader into my new atmega328 using atmega8 arduino as described in the link above. Now, can I replace my old atmega328 with this new bootloaded atmega328 to upload sketches to it? Or should I follow the steps described in the link to upload sketches?

body: Once the bootloader has been burned to it, the chip can replace the one that is currently on the Arduino board. Simply follow normal DIP removal and insertion procedures to replace it.


body:
You can use the 328p as usual (for an Arduino), once the bootloader is burned.

Background: You just used your Atmega8 as an ISP (In-System-Programmer) to get a bootloader onto your new 328p. The bootloader now enables the 328p to be programmed via serial port.


message:
Using 555 as an external Watchdog

I would like to use a 555 circuit as an external watchdog for my Arduino project. The project is a cellular tracker that goes to sleep for an hour, wakes up and does some measurements, uploads them and then goes to sleep again. The 555 should take care that the active period does not take too long because the systems hangs, and in that case trigger a reset. My first thought was to power the 555 circuit with a PIN of the Arduino so that it only goes on when the system is awake and is turned off while sleeping.
But this does not work as the reset line has to stay high even while sleeping and if i turn the 555 off reset would also go low. Could a Mosfet help? Any other ideas?

body:
ok guys - found the answer: this post here at electronics-stackexchange gave the right hint: [Watch-Dog Timer][1]. And my gut feeling was right as well - i simply use a NPN-Mosfet that is being triggered by an Arduino-PIN (which easily can be done while sleeping as well as sleeping means waking up every 8seconds anyway) that connects the capacitor to ground and therefore discharges the guy. Awesome.
This solution can be used as a real fallback in case of whatever happens, while operating the system with built in watchdog-functions while everything is ok.

  [1]: https://electronics.stackexchange.com/questions/18/watch-dog-timer-arduino


message:
Arduino Uno + Ethernet shield stability question

i have a climate control software which reports data back through the web browser.  Everything seems to be working however I am running into an issue where

1 - after a bit it seems the page doesnt refresh completely and instead displays a long list of the same webpage, so i have like 30 pages of the same thing as you scroll down

2 - when i woke up in the morning i could not load the page at all

What i am wondering is how can i get this to be stable and reliable so that the climate control software / sensors can run non-stop.

Currently as long as i dont use the ethernet shield reporting everything else seems to work great, i leave it on for 12 -20 hours and it still runs, but not with the ethernet reporting.

any help wold be apreciated thanks.

this is my code:

    //Define Start
    #define NOTE_D2  73 //sound note for beep
    #define DHTPIN 2
    #define DHTTYPE DHT22
    #define DHT2PIN 3
    #define DHTTYPE2 DHT22
    #define MAGENTA //Define a color for screen
    #define sclk 8 //screen pin
    #define mosi 5 //screen pin
    #define cs   6 //screen pin
    #define dc   7 //screen pin
    #define rst  rstpin  // you can also connect this to the Arduino reset
    #define ANALOG_IN 0 // for cds light sensor

    //Define End
    //Include start
    #include <DHT.h>//dht sensor library
    #include <Adafruit_GFX.h>    // Core graphics library
    #include <Adafruit_ST7735.h> // Hardware-specific library
    #include <SPI.h>//needed to run screen
    #include <Wire.h>
    #include "RTClib.h"
    #include <Ethernet.h>
    //Include end
    //declare start
    DHT dht2(DHT2PIN, DHTTYPE2);
    DHT dht(DHTPIN, DHTTYPE);
    int powerswitch1 = A0;
    int powerswitch2 = A1;
    const int ledPin =  A2;
    const int ledPin2 =  A3;
    Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk);
    char* myString = { "OFF" };//relay1 on / off status
    char* myString2 = { "OFF" };//relay2 on / off status
    const int chipSelect = 4;
    RTC_DS1307 RTC;
    byte mac[] = {
      0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36 }; //MAC address found on the back of your ethernet shield.
    IPAddress ip(192,168,1,40);
    //decalare end
    EthernetServer server(80);

    void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(ledPin2, OUTPUT);
    tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
    tft.fillScreen(ST7735_RED);//make screen red
      pinMode(powerswitch1, OUTPUT);
      pinMode(powerswitch2, OUTPUT);
      Serial.begin(9600);
      Wire.begin();
      RTC.begin();
    if (! RTC.isrunning()) {
        Serial.println("RTC is NOT running!");
        // following line sets the RTC to the date & time this sketch was compiled
     //   RTC.adjust(DateTime(__DATE__, __TIME__));
      }

    // get time to display "sensor up time"
      uint16_t time = millis();
     // tft.fillScreen(ST7735_BLACK); //black screen
      time = millis() - time;

    Serial.println(time, DEC);

      Ethernet.begin(mac, ip);
      server.begin();
      Serial.print("server is at ");
      Serial.println(Ethernet.localIP());
    }
    void loop(){
      //Tone Start
     tone(9, NOTE_D2);
     delay(65);
     noTone(9);
    //Tone End

    //clock start
      DateTime now = RTC.now();

        Serial.print(now.year(), DEC);
        Serial.print('/');
        Serial.print(now.month(), DEC);
        Serial.print('/');
        Serial.print(now.day(), DEC);
        Serial.print(' ');
        Serial.print(now.hour(), DEC);
        Serial.print(':');
        Serial.print(now.minute(), DEC);
        Serial.print(':');
        Serial.print(now.second(), DEC);
        Serial.println();

     //hour conversion to 12 hour start
       int x;
       int timeresult;
       x = (now.hour());
       if (x > 12) {
       timeresult = x - 12;
       }
       else
       {
        timeresult = x;
       }
       Serial.println(timeresult);
        //hour conversion to 24 hour start
    //clock end
    //sensor 1 start
     //Serial.println("read DHT22 #1");
     float h = dht.readHumidity();
     float t = dht.readTemperature();
     float f = dht.readTemperature(true);
     //sensor 1 end
     //sensor 2 start
     //Serial.println("read DHT22 #2");
     float h2 = dht2.readHumidity();
     float t2 = dht2.readTemperature();
     float f2 = dht2.readTemperature(true);
     //sensor 2 end
     //temp average begin
     //Serial.println("average calculation");
     float havg = (h + h2) / 2;
     float favg = (f + f2) / 2;
     float tavg = (t + t2) / 2;
     //temp average end

    //Relay 1 Start
     if (h < 42) //top threshold
     {
      if (h < 39) //bottom threshhold
      {
       digitalWrite(powerswitch1, HIGH);
       // Turn the Powertail on
       Serial.println("Switch ON");
    digitalWrite(ledPin, HIGH);
       myString = "ON";
      }

     }
     else
     {
                    myString = "OFF";
      digitalWrite(powerswitch1, LOW);    // turn the Powertail off
    digitalWrite(ledPin, LOW);
      Serial.println("Switch OFF");

     }
    //Relay 1 End
    //Relay 2 Start
     if (f < 60) //top threshold
     {
      if (h < 60) //bottom threshhold
      {
       digitalWrite(powerswitch2, HIGH);
       // Turn the Powertail on
       Serial.println("Switch ON");
    digitalWrite(ledPin2, HIGH);
       myString2 = "ON";
      }

     }
     else
     {
                    myString2 = "OFF";
      digitalWrite(powerswitch2, LOW);    // turn the Powertail off
    digitalWrite(ledPin2, LOW);
      Serial.println("Switch OFF");

     }
    //Relay 2 End
    //Screen start

    delay(500);

    tft.fillRect(20,19,80,140, ST7735_RED);//clear text
    //(left wall,top wall px from top,right wall,bottom wall px from top)
    tft.drawRect(20,19,80,140, ST7735_RED);//cleartext
    //active text
    tft.setCursor(35, 20);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(f);
    tft.setCursor(35, 40);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(t);
    tft.setCursor(35, 60);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(h);
    tft.setCursor(25, 120);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(timeresult);
    tft.setCursor(50, 120);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(now.minute(), DEC);
    tft.setCursor(75, 120);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(now.second(), DEC);

    //static text

    tft.setCursor(105, 20);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println("F");
    tft.setCursor(105, 40);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println("C");
    tft.setCursor(105, 60);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println("%");
    tft.setCursor(52, 80);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(myString);
    tft.setCursor(105, 80);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println("H");
    tft.setCursor(52, 100);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(myString2);
    tft.setCursor(105, 100);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println("T");
    tft.setCursor(52, 140);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(millis() / 1000);
    tft.setCursor(105, 140);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println("-");

    tft.print(millis() / 1000);
    //Screen end

     EthernetClient client = server.available();
      if (client) {
        Serial.println("new client");
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;
        while (client.connected()) {
          if (client.available()) {
            char c = client.read();
            Serial.write(c);
            // if you've gotten to the end of the line (received a newline
            // character) and the line is blank, the http request has ended,
            // so you can send a reply
            if (c == '\n' && currentLineIsBlank) {
              // send a standard http response header
              client.println("HTTP/1.1 200 OK");
              client.println("Content-Type: text/html");
              client.println("Connection: close");  // the connection will be closed after completion of the response
       client.println("Refresh: 5");  // refresh the page automatically every 5 sec
              client.println();
              client.println("<!DOCTYPE HTML>");
              client.println("");
              client.println("");
              /////CSS
                client.println("");
              ///CSS

              client.println("
");
              client.println(""); //how to change color adruino version

                client.println("
");
                client.println("<text4>");
                client.print("Sensor 1");
                client.println("</text4>");
                client.println("
");
                client.println("<text1>");
                client.print(h);
                client.print(" %\t");
                client.println("</text1>");
                client.println("
");
                client.println("<text2>");
                client.print(f);
                client.println(" °");
                client.println("F");
                client.println("</text2>");
                client.println("
");
                client.println("<text2>");
                client.print(t);
                client.println(" °");
                client.println("C");
                client.println("</text2>");
                client.println("
");
                client.println("
");
                client.println("
");
                client.println("<text4>");
                client.print("Sensor 2");
                client.println("</text4>");
                client.println("
");
                client.println("<text1>");
                client.print(h2);
                client.print(" %\t");
                client.println("</text1>");
                client.println("
");
                client.println("<text2>");
                client.print(f2);
                client.println(" °");
                client.println("F");
                client.println("</text2>");
                client.println("
");
                client.println("<text2>");
                client.print(t);
                client.println(" °");
                client.println("C");
                client.println("</text2>");
                client.println("
");
                client.println("
");
                client.println("
");
                client.println("<text5>");
                client.print("Humidifier: ");
                client.println("</text5>");
                client.println("<humidifier>");
                client.print(myString);
                client.println("</humidifier>");
                client.println("<text5>");
                client.print("Heater: ");
                client.println("</text5>");
                client.println("<heater>");
                client.print(myString2);
                client.println("</heater>");
                client.println("<text6>");
                client.println("
");
                client.print(millis() / 1000);
                client.println("</text6>");
                client.println("<text6>");
                client.print(timeresult);
                client.print(":");
                client.print(now.minute(), DEC);
                client.print(":");
                client.print(now.second(), DEC);
                client.println("</text6>");
                 client.println("
");
                  client.println("
");
              client.println("");
              client.println("");
              break;
            }
            if (c == '\n') {
              // you're starting a new line
              currentLineIsBlank = true;
            }
            else if (c != '\r') {
              // you've gotten a character on the current line
              currentLineIsBlank = false;
            }
          }
        }
        // give the web browser time to receive the data
        delay(1);
        // close the connection:
        client.stop();
        Serial.println("client disonnected");
      }

    delay(3000);

    }

body:
I would go for a memory issue - try to rewrite your code in a way that consumes less memory, the easiest first step is to avoid any Serial.printl("String"); and replace that with Serial.println(F("String"));. But in general you are using a lot of String objects which should be avoided if possible (try to use char() instead).

To check memory consumption of your sketch you can use a function like this and log the values from specific points in the code:

    int freeRam () {
   extern int __heap_start, *__brkval;
   int v;
   return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
 }


body: I used to encounter weird issues, e.g. starting a new instance of a program with Arduino Yun. The issue in the end was power supply, a large capacitor before the voltage regulator has solved the problem. What do you use for power supply?


body: I have had to program in a reset for the network connection on quite a few of my ethernet projects.  I am not entirely sure the cause, but adding a close connection; open connection to run every x minutes seems to have helped prevent both the duplicating content and the timeout issues.


message:
How to remove Adafruit Pro Trinket bootloader flashing startup sequence

From what I understand, the Pro Trinket has "Optiboot" which allows it to detect which boot loader you are trying to use, one for USB and one for FTDI. When it's in this "bootloader state" the red LED on pin 13 buses for 10 seconds before it starts to run the program I've programmed.

Can I remove this Optiboot functionality? Would that entail permanently choosing a single boot loader/interface?

One problem I have with this is that along with the LED on 13, it causes the LED strip I have attached to pins 9, 10, 11 to blink. I would also really like to not have to wait 10 seconds to start running code.

Here's the page on Adafruit's site that talks about the [bootloader\[s\] on the Pro Trinket][1].

Thanks!

  [1]: https://learn.adafruit.com/introducing-pro-trinket/starting-the-bootloader

body:
You could take the [Pro Trinket bootloader source code][1] and tweak it to your needs, [burn it][2], and make sure you have patience and debugging skills.

From the author's (Frank Zhao) source code, it seems that this is the 10 seconds loop you are referring to, located in **main.c**, line #456:

    if ( ((usbHasRxed != 0) && (timeout > USBBOOTLOADER_TIMEOUT)

The `USBBOOTLOADER_TIMEOUT` variable which is defined to `10` at the top of that file, line #70:

    #define USBBOOTLOADER_TIMEOUT 10

 and is progressed after 'roughly' 1 second, at line #496:

    // roughly 1 second
 #if (F_CPU == 12000000)
  if (t1ovf > 183) {
  #elif (F_CPU == 16000000)
  if (t1ovf > 244) {
  #endif
   t1ovf = 0;
   timeout++;
  }

  [1]: https://github.com/adafruit/Adafruit_ProTrinket_Bootloader
  [2]: http://arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader


body: I'd be careful to remove that section because these ten seconds are not only where the board detects which bootloader to use but also when it is accepting a new sketch at all. So if you'd get rid of that, you wouldn't be able to upload new sketches anymore i guess.


body:
Just program the pro trinket using ISP. (not using the USB connector). For example by using an [Arduino as a ISP-programmer](http://arduino.cc/en/Tutorial/ArduinoISP).

If you are brave, you could change the bootloader to only run when the reset button was pressed, and not at power-up. I've done exactly that for the regular trinket ([see my github](https://github.com/beargun/Adafruit-Trinket-Gemma-Bootloader/commit/4451cecf7ebcce8abb9f5a1e9c8c9ab3fe591a3d))


body:
**It is actually much simpler than the other answers suggest. There is no need to remove/overwrite the bootloader.** You can just disable the bootloader by setting the appropriate fuse bit.

In order to do so, you need an ISP programmer. As you might know, you'll loose the ability to upload code though USB/FTDI. But you can restore that ability at any time, just by resetting the appropriate fuse bit to its original value.

## Step 1: Connect your trinket through an ISP programmer

There is no ISP header on the trinket, but you can easily build one or just use jumper wires to connect the individual pins directly to the programmer. [Pinout can be found at learn.adafruit.com](https://learn.adafruit.com/introducing-pro-trinket/pinouts). You need to connect MISO, MOSI, SCK, RST, VCC and GND.

## Step 2: Determine current fuse configuration

    avrdude -c usbtiny -p m328p

*If you're using a different programmer than the USBTinyISP, replace `usbtiny` with the appropriate identifier. List possible values by specifying a bogus identifier, eg. `avrdude -c foo`.*

Among some other things, avrdude should return a line containing the current fuse values. It should look similar to the following:

> avrdude: safemode: Fuses OK (E:FD, H:D0, L:FF)

We're interested in the *high* fuse (H:D0). `D0` indicates that the bootloader is enabled. Actually, any even number means the bootloader is enabled.

## Step 3: Calculate new fuse value

We want to set the `BOOTRST` bit of the *high* fuse. It is the least significant bit of the fuse, which equals the number 1. So all we need to do is increment the value by 1.

In the example, the new fuse value is `D1`.

*If you are unsure how to calculate the fuse value, you can use the [Fuse Calculator](http://www.engbedded.com/fusecalc/). Choose ATMega328P as your device, enter the fuse values as reported by avrdude at the very bottom under "Current settings", then click apply. Uncheck `BOOTRST` in the "Manual fuse bits configuration" section, then you will see the new fuse value in the bottom section, where you entered the original value.*

## Step 4: Program new fuse value

    avrdude -c usbtiny -p m328p -U hfuse:w:0xd1:m

Again, replace `usbtiny` with the identifier of your programmer. If you calculated a different value than `D1`, replace `0xd1` with your approriate value. **However, if your original value for the high fuse was `D0`, then your new value _is_ `D1`.**

## Done!


message:
Smaller version of the Mega

I'm currently working on a Arduino Mega (GPS + IMU + SD card logging + BT). I need the Mega for extra memory and serial port.
I would like to transition to something with a smaller form factor now. I need help with suggestions for a smaller form factor board/version of Mega.

Any suggestions?
I can't really find anything.

The only small size yet meeting requirements (in terms of memory) option seems to be a [Microduino][1] -
but I'm not whether all the libraries (SDfat etc.) will work on this.

  [1]: https://www.microduino.cc/module/view?id=53d7037cb6c69d00003ede53

body:
The ATmega1284P provides 128kB of flash, 16kB of SRAM, 4kB of EEPROM, and 2 USARTs in a 40/44/49-pin package. Mighty 1284P provides Arduino support for the '1284P.

There aren't too many actual boards that feature it, but it can be used very easily on a breadboard or custom PCB with a programmer.


body: The link uses the same chip that Ignacio recommended.  The libraries will need some minor edits, but many of the standard ones do have a 1284P fork.  It is mostly just redoing pin assignments, or adding the 1284P to the board definitions.  I am working on a similar project and have gotten the 1284P to work with SDfat, a bunch of standard GPS libraries, and TinyGPS++ .


body:
Look for "Mega2560-CORE" on ebay.

Some information:
http://www.inhaos.com/product_info.php?products_id=88


message:
Freeduino avrdude stk500_getsync() not in sync

I have a Freeduino USB 1.1 board with atmega 8l-8pu microcontroller on it. When I try to upload program, it shows error:

    avrdude stk500_getsync() not in sync: resp 0x00

I have tried reset and the red led blinks which I think suggest bootloader is working fine.

On Arduino IDE, I have set Arduino Uno and correct port which is shown in device manager.

One weird problem that I noticed is that no matter which USB port I connect to, it says COM9 on device manager. Is that something to look into?

Any ideas?

body:
There could be many reasons for the problem you have got.

1) Try to program your Board with any other device you have got. If you are trying to program it with PC try to do it using Laptop.

2) Plug your board to any other port. Then Right Click My Computer and Select Manage--> Device Manager and find the port where your Freeduino is connected. Then Select that port in  your Arduino IDE.

Solution 1 worked for me!


message:
Proxy and Authentication in Arduino Uno

I am using the Ethernet Shield on top of the Arduino Uno. I want to use this setup to access  webpages. But I am unable to access because the ethernet connection is present in a University which requires a proxy server with authentication. I am unsure of what extra code to include so as to get past the proxy which requires authentication.
Can anyone help in solving this problem?

body:
Any semi-reputable authentication mechanism would be performed over HTTPS, which is an encrypted connection - this would require an SSL library to be installed for use along with the normal Ethernet and HTTP libraries, and I don't believe the arduino really has the processing capability to make connections like this feasible.
Unfortunately this is one of those cases where a more sophisticated device may be more appropriate.... (like a Beaglebone Black, or a Raspberry Pi.)

It is possible that you could add headers into the HTTP connection packet to either bypass proxy authentication, or include a cookie that has already undergone authentication and is cached by the proxy. How you do this is almost entirely down to how your proxy works. You may also find this doesn't work unless you spoof the MAC address of your device to match that of the machine used to fulfill the authentication.

It is entirely possible to set up a system to share the internet connection (act as a router) between two adapters - so you end up making connection requests to webpages, but the authenticated proxy only sees requests coming from your system (this is kind of how mobile phone tethering works, when you access the internet on a laptop or tablet through your smartphone's internet connection).

**If** the proxy supports unencrypted authentication, it may be possible to pass through username/password details in plaintext (or Base64 encoded) in [Basic access authentication][1], which is what HTTP (and HTTPS) often uses - but this is unsafe on HTTP and is **VERY** unsafe when any part of the connection is publicly transmitted - like when using wifi, for example. (Doesn't matter if the wifi is encrypted - as on a university network, everyone who can connect to the wifi can see your wifi traffic (typically).)

If you're going to be using your own personal university login credentials to do this, make sure you always use ethernet to do it, not wifi, and if possible, obtain a second username/password explicitly for connecting this way - you don't want to have to hard-code your own personal username and password into source code that you have to give to anyone.

Here's a few links to get you started:

 - [HTTP Spec: Proxy-Authorization and Authorization headers][2]
 - [How to use authentication in an HTTP Proxy?][3]
 - [Wikipedia: X-Forwarded-For][4]

  [1]: http://en.wikipedia.org/wiki/Basic_access_authentication
  [2]: https://stackoverflow.com/questions/10023636/http-spec-proxy-authorization-and-authorization-headers
  [3]: https://superuser.com/questions/334912/how-to-use-authentication-in-an-http-proxy
  [4]: http://en.wikipedia.org/wiki/X-Forwarded-For


message:
Works on Uno but not on Yun

I found some code that works to transmit the required signal to an RX-2B RC receiver, the code works great from my Uno but when I tried to run it from my Yún nothing happens.

The code has definitely uploaded as I tested with an LED and the pin is getting a HIGH voltage written to it.

Does anyone have any idea what the issue might be? Code below.

Thanks.

    /**
    * Control Realtek RX2 (RX2 -G) RC Receiver with Arduino
    *
    * @author Mircea Diaconescu, Octomber 28, 2013
    * @source https://github.com/dimircea/
    * GPL v3 License
    *
     * Many cheap RC toys are based on TX2 / RX2 transmitter / receiver ICs.
     * This Arduino sketch allows to replace the TX2 based Remote Control with Arduino.
     * Just one single pin is used from the Arduino board.
     *
     * Connect Arduino pin 10 to the solder point where the toy antenna is connected or         to the toy antenna cable.
     * One can replace pin 10 with other free digital pin available on the Arduino board.
         *
     * TX-2B/RX-2B datasheet: http://www.datasheetarchive.com/dl/Datasheet-    035/DSA0017137.pdf
     */

    /** Functions (aka W1) - as defined by the IC datasheet */
    #define COMMAND_ENDCODE         4
    #define COMMAND_FORWARD        10
    #define COMMAND_FORWARD_TURBO  16
    #define COMMAND_TURBO          22
    #define COMMAND_FORWARD_LEFT   28
    #define COMMAND_FORWARD_RIGHT  34
    #define COMMAND_BACKWARD       40
    #define COMMAND_BACKWARD_RIGHT 46
    #define COMMAND_BACKWARD_LEFT  52
    #define COMMAND_LEFT           58
    #define COMMAND_RIGHT          64

    //output pins
    #define ANTENNA_PIN 9

    /** Initialize the Arduino data and pin */
    void setup() {
     pinMode( ANTENNA_PIN, OUTPUT);
    }

    /** Loop code */
    void loop() {
     // add here your commands to control the RX2 module...
     // for test purposes, here a continuous forward command is sent

     sendCommand( COMMAND_FORWARD);

    }

    /** Send command to the RX2 IC */
    void sendCommand( int command) {
     int w1 = 0, w2 = 0;

     /** start code sequence 4 x W2, ~625Hz, Duty Cycle 75% */
     for ( w2 = 0; w2 < 4; w2++) {
       digitalWrite( ANTENNA_PIN, HIGH);
       delayMicroseconds( 1200);
       digitalWrite( ANTENNA_PIN, LOW);
       delayMicroseconds( 400);
      }

     /** function code sequence, n x W1, ~1.25KHz, Duty Cycle 50% */
     for ( w1 = 0; w1 < command; w1++) {
       digitalWrite( ANTENNA_PIN, HIGH);
       delayMicroseconds( 400);
       digitalWrite( ANTENNA_PIN, LOW);
       delayMicroseconds( 400);
     }
    }

body:
A Yun is like a Leonardo with a CPU running GNU/Linux at its side. If your sketch works with a Leonardo, it's likely to work with a Yun.

Uno has a different MCU and thus not every sketch will just work, especially those using the hardware serial. You'll have to convert them.


message:
Arduino Uno + Wifi Shield + PS2 Keyboard + LCD Display

I'm new in the Arduino Community and I'm facing a problem when I try to use a PS2 Keyboard and an LCD Display (16x2) on an Arduino Uno with a Wifi shield.

I would like to write something with the keyboard and display it in the LCD before sending it to a webservice.

Here is my problem:

- When I use the keyboard and the display on my Arduino WITHOUT the wifi shield --> All is OK. I can write on the display the key that has been pressed.
- When I use the keyboard and the display on my Arduino WITH the wifi shield --> All is OK until I write something on the display. As soon as I write on the display with the function lcd.print(), the keyboard does not work anymore (it detect the character '2' every time I press a key).

It's very surprisingly because if I dont use lcd.print(), the keybord works without any problem.

Here is a part of my code:

    #include <LiquidCrystal.h>
    #include <PS2Keyboard.h>

    LiquidCrystal lcd(12, 11, 2, 5, 6, 8);
    PS2Keyboard keyboard;

    const int DataPin = 9;
    const int IRQpin = 3;

    void setup(){
      keyboard.begin(DataPin, IRQpin);
      lcd.begin(16, 2);
    }

    void loop(){
      checkKeyboard();
    }

    void checkKeyboard(){
      if (keyboard.available()) {

        char c = keyboard.read();

        // check for some of the special keys
        if (c == PS2_ENTER) {
          Serial.println();
        } else if (c == PS2_TAB) {
          Serial.print("[Tab]");
        } else if (c == PS2_ESC) {
          Serial.print("[ESC]");
        } else if (c == PS2_PAGEDOWN) {
          Serial.print("[PgDn]");
        } else if (c == PS2_PAGEUP) {
          Serial.print("[PgUp]");
        } else if (c == PS2_LEFTARROW) {
          Serial.print("[Left]");
        } else if (c == PS2_RIGHTARROW) {
          Serial.print("[Right]");
        } else if (c == PS2_UPARROW) {
          Serial.print("[Up]");
        } else if (c == PS2_DOWNARROW) {
          Serial.print("[Down]");
        } else if (c == PS2_DELETE) {
          Serial.print("[Del]");
        } else {
          Serial.print(c);
          displayText(c);
        }
      }
    }

    void displayText(char c){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Pressed key:");
      lcd.setCursor(0,1);
      lcd.print(c);
    }

Does somebody know how to solve this problem?

Thank you very much in advance :)

Edit: Here are the pins that I use on the board :

- Arduino pin 2 -> LCD pin 11
- Arduino pin 5 -> LCD pin 12
- Arduino pin 6 -> LCD pin 13
- Arduino pin 8 -> LCD pin 14
- Arduino pin 11 -> LCD pin 6
- Arduino pin 12 -> LCD pin 4
- Arduino pin 3 -> Keyboard IRQ
- Arduino pin 9 -> Keyboard Data

body:
You must verify which pins the wifi shield is using and see if they aren't used also by the LCD.
Can you provide further details on the wifi shield ?


body:
As you say, I can't use pins 10, 11, 12, 13 because they are used for the SPI.

-> So, I tried to use the pins 4 and 7 instead of 11 and 12.

The problem is that the pin 7 is used by the Wifi shield (Handshake) and I have no other free digital pin.

-> So, I tried to use an analog pin instead of the pin 7 and ..... it works very well.

Here is my final solution :

- Arduino Pin 2 -> LCD Pin 4 (RS)
- Arduino Pin 3 -> Keyboard IRQ
- Arduino Pin 4 -> LCD Pin 11 (D4)
- Arduino Pin 5 -> LCD Pin 12 (D5)
- Arduino Pin 6 -> LCD Pin 13 (D6)
- Arduino Pin 7 ->
- Arduino Pin 8 -> LCD Pin 14 (D7)
- Arduino Pin 9 -> Keyboard Data
- Arduino Pin 10 ->
- Arduino Pin 11 ->
- Arduino Pin 12 ->
- Arduino Pin 13 ->
- Arduino Pin 14 (= Analog 1) -> LCD Pin 6 (E)


body:
Sorry I do not have enough reputation to place a comment.

@Valentin from the link, you provided, to the wifi shield it states that it uses pins 11 ,12 and 13 on the UNO which will give you a conflict on pins 11 and 12 with the LCD. Not sure why that manifests as an apparent keyboard error though:

From the linked page:
>Arduino communicates with both the Wifi shield's processor and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Uno and pins 50, >51, and 52 on the Mega. On both boards, pin 10 is used to select the HDG204 and pin 4 for >the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, >53, is not used to select either the HDG204 or the SD card, but it must be kept as an output or the SPI interface won't work.

Again sorry this is not a full answer but thought it may help.


message:
Arduino Yun, pass int data true REST

Would it be possible to instead of passing a state via a REST browser:

    digital/13/1

to set an int value? For example, if in the sketch if I would name an int: 2, could I set this to 48 via REST?

If so, how?

body:
Check out the [TemperatureWebPanel][1] example: you'll see that you can make your own REST APIs and pass any values your sketch can handle.

  [1]: http://arduino.cc/en/Tutorial/TemperatureWebPanel


message:
Arduino board not recognized by Linux (dmesg, lsusb, etc.)

I just received my first [Arduino board][1] which is essentially a Leonardo (ATmega32U4) customized to include a NFC reader (PN532).

When I plug it in, the PWR LED comes on steady, the D13 LED flashes a few times, and then the STA LED blinks once and only the PWR LED is left on. I can upload a basic sketch to the correct Serial Port, but the Serial Monitor is always empty.

I have noticed that, when uploading the sketch, the RX/TX LEDs stay off (which I thought was a sign of uploading/downloading data). I figured this was the root of my issue so I tried to look into it further. Running `lsusb` does not find the device and `dmesg` does not show any information when (un)plugging the device.

I also tried on a Windows install, but couldn't install the Leonardo drivers since Device Manager wouldn't register any unknown USB/Arduino devices.

Do you think my board is dead on arrival or am I doing something wrong?

---

**Update:**

I just uploaded the Blink tutorial sketch and it uploaded "successfully" but I noticed no differences. Please note that I don't have an external LED attached, but am looking at the board's LED on pin 13. This pin already flashes a few times (as mentioned above) on a reset, so I modified the delay times and still noticed no change.

![uploaded sketch][2]

I am uploading using board Leonardo, as recommended for my hardware, and the serial port /dev/ttyS0. I thought this was the right port because I remember not seeing it at first, but on second thought I had a permission issue at first (which is now resolved) causing me to not see the port.

*So it looks like my board is* ***not*** *detected by my computer and I'm successfully uploading sketches to a meaningless port.* Any troubleshooting options for me? I've tried different USB ports and am, as of recently, plugging my board into external power (9V). The only thing I can think of that on my end is that I'm using a Y-cable for my USB connection (I have a normal Mini-USB coming tomorrow via Amazon) since it is all I had. I can also confirm that this USB connection ***does*** power the board when plugged in.

  [1]: http://www.elecfreaks.com/wiki/index.php?title=NFC_Bridge
  [2]: https://i.stack.imgur.com/bbb6n.png

body:
So, to summarise the comments trail; the blinking lights at power-up are the normal boot sequence for the Leonardo,  indicating the processor is good, and that power is reaching the board; the device seen should be /dev/ttyACM0 or some other number; dmesg wasn't recording a plug-in event as the cable was not good.

We still don't quite know why the IDE thought it had sent a program to /dev/ttyS0, but presumably the level of interaction is much less (ie, none) via RS232 serial? Which explains why it said it had uploaded a test program when, in fact, it hadn't!

And replacing the USB cable has solved the problem - excellent news!


message:
How can I make pinMode calls faster?

I'm trying to use 3 pins as capacitive pins along side the [Mozzi][1].

I had several attempts and so far the closest I had was using code from the [ADCTouch library][2] straight into the main code, but with the current implementation (removing averaging and taking less samples to speed things up) it's only fast enough to process 1 pin and I'd like to use 3.

Here is my implementation so far:

    /*  Based on the Gain Example changing the gain of a sinewave,
        using Mozzi sonification library.

        Demonstrates the use of a control variable to influence an
        audio signal.

        Circuit: Audio output on digital pin 9 on a Uno or similar, or
        DAC/A14 on Teensy 3.0/3.1, or
        check the README or http://sensorium.github.com/Mozzi/

        Mozzi help/discussion/announcements:
        https://groups.google.com/forum/#!forum/mozzi-users

        Tim Barrass 2012, CC by-nc-sa.
    */

    #include <MozziGuts.h>
    #include <Oscil.h> // oscillator template
    #include <tables/sin2048_int8.h> // sine table for oscillator

    // use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
    Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);

    // control variable, use the smallest data size you can for anything used in audio
    byte gain = 255;

    //ADC Touch setup
    int sampleCount[3] = {0};
    int values[3] = {0};

    void setup(){
      startMozzi(); // start with default control rate of 64
      aSin.setFreq(4200); // set the frequency
    }

    void updateControl(){
      if(gain > 3){
        gain = gain - 3 ;
      }else{
        gain = 0;
      }
      //begin ADCTouch
      pinMode(A4, INPUT_PULLUP);

      ADMUX |=   0b11111;
      ADCSRA |= (1<<ADSC); //start conversion
      ADCSRA |= (1<<ADIF); //reset the flag

      pinMode(A4, INPUT);

      values[0] = mozziAnalogRead(A4);
      sampleCount[0]++;
      //end ADCTouch

      if(sampleCount[0] == 64){//wait for 64 samples
        if(values[0] > 500) {//did we get a touch with all these samples ?
          gain = 255;//amp it up
        }
        sampleCount[0] = 0;//reset count
      }

    }

    int updateAudio(){
      return (aSin.next()* gain)>>8; // shift back to STANDARD audio range, like /256 but faster
    }

    void loop(){
      audioHook(); // required here
    }

The issue is as soon as do the pinMode calls for the second pin I'd like to use (A5) so I'm guessing pinMode needs to work faster. To use `pinMode(INPUT_PULLUP)` and `pinMode(INPUT)` calls for pins A4,A5 and digital 10, now can I write this using direct port manipulation ?

(I'm new to avr/arduino internals and slowly getting the grips with this).

  [1]: http://sensorium.github.io/Mozzi/
  [2]: http://playground.arduino.cc/Code/ADCTouch

body:
First, figure out which port and pin you're using. Then, manipulate them.

    DDRC &= ~_BV(PC5);
    PORTC |= _BV(PC5);

...

    DDRF &= ~_BV(PF5);
    PORTF |= _BV(PF5);

...

    DDRF &= ~_BV(PF0);
    PORTF |= _BV(PF0);


message:
W5100 module hookup help - Not a shield

I recently purchased a W5100 based ethernet shield for my arduino Uno, and looks like [this][1]. I had been following the guide [here][2], and connected the pins accordingly - 5V to 5V, GND to GND, MOSI to 11, MOSO to 12, SCK to 13, and SS to ten.

 I booted up a default sketch (webServer, under Ethernet), and plugged in and ethernet cable. - PWR, LINK, SPD,and FDX all lit up, with Rx blinking for first 10 or so seconds. I then go to the IP specified on the arduino sketch, and nada. Also, my router doesn't show the shield under the attached devices.

Therefore, I figure it's a problem with my connections. Can anyone help me? Googling has only brought my lots of info about shields, and little info on these modules.

  [1]: http://yourduino.com/sunshop2/images/products/large_243_Ethernet-W5100-3-1024.jpg
  [2]: http://arduino-info.wikispaces.com/Ethernet

body:
First, if you cannot connect to arduino by ethernet, use Serial Monitor and add some Serial.println to your code to log what is going - what part of program Arduino is executing.

W5100 module has no automatic reset module as opposed to Ethernet shield.
So try to connect W5100 RST pin to for example D8 and reset module in setup.

Here you are example from my (working) project:

    const int W5100_RESET_PIN = 8;

 void setup() {
   Serial.begin(SERIAL_SPEED);
   Serial.println();
   Serial.println(F("node starting..."));
   pinMode(W5100_RESET_PIN, OUTPUT);
   digitalWrite(W5100_RESET_PIN, LOW);
   delay(100);
   digitalWrite(W5100_RESET_PIN, HIGH);
   // give the Ethernet shield a second to initialize:
   delay(3000);
 #ifdef USE_DHCP
   Serial.println(F("DHCP..."));
   while (Ethernet.begin(mac) == 0) {
  Serial.println(F("DHCP failed."));
  delay(10000);
   }
 #else
   Serial.print(F("static IP..."));
   Ethernet.begin(mac, IPAddress(MY_IP));
 #endif
   Serial.print(F("local IP:"));
   Serial.println(Ethernet.localIP());
   Serial.println(F("node started."));
 }

Also after setup if your arduino lost ethernet connection and cannot get it again, you can try to reset w5100 and initialize Ethernet again.


message:
Arduino Nano -- cannot download, no /dev/tty*** device

It appears to me that each Arduino has (should have?) a unique /dev/tty...USB... number assigned. Why this isn't explained anywhere (that I can find) is a mystery. When I plug my problem Nano into a USB port on my iMac no /dev/tty... for it appears. It used to work. Have I fried it? Can this be fixed?

body:
This is probably a duplicate question and duplicate answer, but ...

Flip the board over, look at the bottom. If it says "FTDI" then this answer doesn't apply. But many cheap clones have moved to the CH340G chip for USB serial communication, it's a tenth of the cost with a tenth of the (unused) features.

You can find CH340/341 drivers from the manufacturer at [WCH.CN][1] or linked at the bottom of [this post][2].

Or, skip the USB altogether and search for "ISP" on [Tindie][3] and grab a USBASP or TinyISP programmer.

  [1]: http://WCH.CN
  [2]: http://www.ardueasy.com/2014/10/different-varieties-of-arduino-nano.html
  [3]: https://Tindie.com


message:
uBlox Neo 6M GPS module not responding

I started recently working with a uBlox Neo 6M GPS module (data sheet [http://www.u-blox.com/images/downloads/Product_Docs/NEO-6_DataSheet_(GPS.G6-HW-09005).pdf][1]). I connected it to an Arduino Uno as shown:

GPS  Arduino
VCC-- 3.3V
RX -- D11
TX -- D10
GND-- GND

I tried this example code from TinyGps++ (of course, changing the pins and the gpsbaud to 9600, which is the gps' default).

<!-- language: c -->

    #include <TinyGPS++.h>
    #include <SoftwareSerial.h>
    /*
       This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
       It requires the use of SoftwareSerial, and assumes that you have a
       4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
    */
    static const int RXPin = 10, TXPin = 11;
    static const uint32_t GPSBaud = 9600;

    // The TinyGPS++ object
    TinyGPSPlus gps;

    // The serial connection to the GPS device
    SoftwareSerial ss(RXPin, TXPin);

    void setup() {
      Serial.begin(115200);
      ss.begin(GPSBaud);
      Serial.println(F("DeviceExample.ino"));
      Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
      Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
      Serial.println(F("by Mikal Hart"));
      Serial.println();
    }

    void loop() {
      // This sketch displays information every time a new sentence is correctly encoded.
      while (ss.available() > 0)
        if (gps.encode(ss.read()))
          displayInfo();
      if (millis() > 5000 && gps.charsProcessed() < 10) {
        Serial.println(F("No GPS detected: check wiring."));
        while(true);
      }
    }

    void displayInfo() {
      Serial.print(F("Location: "));
      if (gps.location.isValid()) {
        Serial.print(gps.location.lat(), 6);
        Serial.print(F(","));
        Serial.print(gps.location.lng(), 6);
      } else {
        Serial.print(F("INVALID"));
      }

      Serial.print(F("  Date/Time: "));
      if (gps.date.isValid()) {
        Serial.print(gps.date.month());
        Serial.print(F("/"));
        Serial.print(gps.date.day());
        Serial.print(F("/"));
        Serial.print(gps.date.year());
      } else {
        Serial.print(F("INVALID"));
      }

      Serial.print(F(" "));
      if (gps.time.isValid()) {
        if (gps.time.hour() < 10) Serial.print(F("0"));
        Serial.print(gps.time.hour());
        Serial.print(F(":"));
        if (gps.time.minute() < 10) Serial.print(F("0"));
        Serial.print(gps.time.minute());
        Serial.print(F(":"));
        if (gps.time.second() < 10) Serial.print(F("0"));
        Serial.print(gps.time.second());
        Serial.print(F("."));
        if (gps.time.centisecond() < 10) Serial.print(F("0"));
        Serial.print(gps.time.centisecond());
      } else {
        Serial.print(F("INVALID"));
      }
      Serial.println();
    }

However, I do not get the GPS LED to blink, as well as my Arduino's RX LED, so the module is not transmitting any data. This is the output from the code:

    A simple demonstration of TinyGPS++ with an attached GPS module
        Testing TinyGPS++ library v. 0.92
        by Mikal Hart

        Location: INVALID  Date/Time: 0/0/2000 00:00:00.00
        Location: INVALID  Date/Time: 0/0/2000 00:00:00.00

Thanks!

  [1]: http://www.u-blox.com/images/downloads/Product_Docs/NEO-6_DataSheet_(GPS.G6-HW-09005).pdf

body:
Try to connect your GPS module with an FTDI cable directly to the Serial-Port of your computer (and read it with screen or any other terminal program). Once that works, proceed with the Arduino.
And check what your GPS-module not blinking does mean. Usually it says there is no 'fix', which means it does not see enough satellites. The output you showed would fit into that theory. Which would mean everything is ok, except your module is not seeing the sky...


body:
The Neo 6M takes a bit of time to fix when first powered on. If your board is fitted with a small battery it will most probably be flat and will take an hour or two to charge up. It is there to provide charge to the EEPROM and the onboard RTC.

Also check that the leads on the battery are not shorting.

You do not get a valid data sentence out of the GPS until the RTC can sync time.

The Error message that you got from Mike Hart routine first says that there is not enough data to do a FIX and second the Date Time is not syncing.


body:
1) Try outside or near the window.
because the signal may not reach inside a house.

2)Check the connection.

3) Print the number of satellites connection to know the device is connectied by
```
Serial.println(gps.satellites.value());
```
Good luck!!!


body:
After 2 days of troubleshooting I found the solution

 1. Use 3.3 volt external supply
 2. Use voltage dividers to make 3.3 volt compatible to module
 3. go outside(open space)

That's it


message:
Is it wise to use analog input pins to read digital buttons?

I am thinking about building a circuit that is literally going to take 11 of the 14 digital pins of an `UNO` to communicate with an SD card and an external EEPROM chip (EEPROM programmer).

Using 4 shift registers and the SD card, I will have 1 digital pin left.  Well, I'm also reserving pins 0/1 for serial communication.

Anyway, I need to read some external buttons and I have the 6 analog pins that I haven't touched.

I will only need about 4-5 push buttons in my design so they should fit nicely on A0+.

So, my question is, will I run into any issues doing this?  Or, are the analog inputs better left for true analog reading?

Thanks.

body: If you have no use for analog pins there is no problem. A5/A6 are used for I²C (on the Uno).


body:
The Analog pins are essentially identical in functionality to digital pins when used as digital I/O.

If desired you could "be clever" and use an analog input in analog mode to read multiple keys using one pin. eg using 10k, 22k, 39k, 82k, 150k in series with 5 buttons from V+ to pin and a say 4k7 to ground would result in 5 voltages which were easily distinguished using an analog read. This is a very very old technique indeed and allows far more than 5 keys on one input pin. THere are limitations which can be discussed if required.

R1 ... R5 correspond to buttons 1...5

Vout = V+ x Rb / (Rb + Rbutton)

Example only

Rb = 39k
R1 = 10k
R2 = 22k
R3 = 39k
R4 = 82k
R5 = 150k

Gives

 - The % of V+ in column 2 when a button is pressed.

 - The voltage in column 3 with V+ = 5V

Delta-V is the difference between that key and the one below - very ample clearance.

![enter image description here][1]

![enter image description here][2]

  [1]: https://i.stack.imgur.com/F9KCN.jpg
  [2]: https://i.stack.imgur.com/Cq9kc.jpg


message:
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.

body:
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][1] 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][2]. 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.

  [1]: https://gcc.gnu.org/
  [2]: http://www.nongnu.org/avr-libc/


message:
Can I program AVR Microcontrollers using Arduino Development board with AVR Studio?

I know and I can program any AVR microcontroller with Arduino IDE and Arduino Uno board. Can I use Arduino board with AVR Studio? Or I have to buy an AVR Development board?

body: You can use Atmel Studio to write code for the MCU(s) on the Arduino boards. If the IDE itself does not support *uploading* the code to the Arduino then it is still possible to use AVRDUDE or BOSSA to upload it via the command line.


body:
There is an [Arduino plugin](http://www.visualmicro.com/) available for AVR Studio, which allows you to upload sketches to an Arduino, just like you would with the Arduino IDE. I think this also enables you to upload plain C/C++ files created with the standard AVR tools.

Alternatively, if you have an AVR ISP programmer, you can use this to upload compiled C/C++ to the Arduino from AVR studio without needing the Arduino plugin.


message:
US-100 Ultrasound sensor doesn't work on Arduino mega 2560

Im using a Arduino Mega 2560, and I tried to connect a us-100 ultrasonic sensor for distance measurement.

I connected it as shown in the image ![connection][1]

 The code I used was:

    const int trigger=6;
    const int echo=7;
    float distance;
    void setup(){
    Serial.begin(9600);
    pinMode(trigger,OUTPUT);
    pinMode(echo,INPUT);
    }
    void loop(){
    // Trigger US-100 to start measurement
    // Set up trigger
    digitalWrite(trigger,LOW);
    delayMicroseconds(5);
    // Start Measurement
    digitalWrite(trigger,HIGH);
    delayMicroseconds(10);
    digitalWrite(trigger,LOW);
    // Acquire and convert to mtrs
    distance=pulseIn(echo,HIGH);
    distance=distance*0.0001657;
    // send result to UART
    Serial.println(distance);
    delay(50);
    }

But It won't work, as in the only output i get is 0.00 cm as shown in the image ![sm][2]

 Can someone tell me if I'm doing something wrong(also, i tried putting two probes between the vcc and one of the gnd pins, and a resistance was shown.This should mean the sensor isn't broken.yes?)? this is my first time using arduino and I greatly appreciate help to fix this.

  [1]: https://i.stack.imgur.com/SfgzB.jpg
  [2]: https://i.stack.imgur.com/jjsjG.jpg

body:
Have you removed the "Serial Data Mode" shunt to put the device in "Pulse Width Mode"?

On the other hand, perhaps the "Serial Data Mode" would actually work better for your application?

Where I work, we have a coding style that strongly encourages
all "magic numbers" to be documented
with a link to the website it came from
or a reference to the book and page it came from.

Would something like this work for you?:

    void loop(){
        // Trigger US-100 to start measurement
        // at least 50 us high, then set it low,
        // as recommended by
        // https://www.bananarobotics.com/shop/US-100-Ultrasonic-Distance-Sensor-Module
        digitalWrite(trigger,HIGH);
        delayMicroseconds(50);
        digitalWrite(trigger,LOW);
        // Acquire
        unsigned long echo_microseconds = pulseIn(echo,HIGH);
        // debugging
        serial.println( echo_microseconds );
        Serial.println(F(" microseconds"));
        // conversion factor from
        // https://www.bananarobotics.com/shop/US-100-Ultrasonic-Distance-Sensor-Module
        unsigned long distance_mm = echo_microseconds * 34 / 100 / 2;
        Serial.print(distance_mm);
        Serial.println(F(" mm"));
        delay(50);
    }

It might be easier to use the Ping library as described at
[Arduino-Info: UltraSonic Distance Measurement][1].

You might find the
[Arduino Forum: Measuring Distances with Ultrasonic Sensors][2]
thread educational.

  [1]: http://arduino-info.wikispaces.com/UltraSonicDistance
  [2]: http://forum.arduino.cc/index.php?topic=130925.0


message:
Unstable system when controlling power to serial peripheral devices and sleeping

In the process of trying to make a small system that will last a while on 4 AA batteries, I've reduced my Arduino project to a barebones system that when asleep draws a tiny amount of current from the batteries.

However, to achieve this, I found it would be necessary to cut power to the two attached peripheral devices (connected to an ATMega328P-PU). One of them is an I2C device, and the other is a serial device, and both are attached to the hardware serial/I2C pins as appropriate.

In terms of powering the peripherals, the bases of two transistors are connected to two of the digital pins, and power to them is controlled from code via these transistors. Both devices are 5V, and when the system is running the total current draw is around 200mA.

Basically this setup works, however I'm getting "random" system hanging and essentially an unreliable project. Sometimes when I power it up it will work as normal, but then hang and not sleep. Other times, it will sleep, but then freeze after waking or just get stuck during waking (which I can tell because the serial device powers up first and does nothing, but the I2C device remains off).

My best guess is the root of the cause is either something to do with the serial communication being interrupted by sleeping the MPU (I'm using the maximum power saving sleep, which is woken by an external interrupt on pin 2), or possibly some sort of power problem (sudden current draw from battery?) that occurs when the peripherals are powered on in code (though I don't know how I should test this).

So far, I've tried calling `Serial.end()` before sleeping the MPU, and `Serial.being(9600)` on waking, and have scattered `delay(1000)`s throughout to ensure everything has enough time to get running, but the problem still remains.

Does anyone have any pointers on things I could change/test, or an alternative approach I could take to make the same power savings?

EDIT: Some more details

The transitors used are TIP 120's. The connections are essentially an exact copy of the image here: https://ctheds.files.wordpress.com/2007/10/tip120.jpg, except the resistors used are 560 Ohms (just what I had to hand, no other reason, didn't think it would change anything).

The I2C peripheral is a 20x4 LCD (which I believe is HD44780 compliant). The serial device is an GT511C3 fingerprint sensor. I don't believe either of them have any automatic power saving features, though I haven't looked for such things in the documentation explicitly.

The exact code I use to call sleep is

    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_mode();

which I'm lead to believe is the lowest power mode, and aside from this problem works well for my system.

body:
I hear great things about the cosa core for Arduino. It's a fantastic alternative Arduino core and exposes the power management capabilities of the micro-controller that are not exposed by the standard Arduino core.

You might find it is too different for your experience but then again it is excellent and worth a look.

[https://github.com/mikaelpatel/Cosa][1]

  [1]: https://github.com/mikaelpatel/Cosa


body:
Using an NPN transistor to control power to a peripheral may be problematic.

An NPN transitor would presumably be used as a `low-side switch` interrupting the peripheral's ground line, however, even when turned on this will have a non-trivial voltage drop.

Most logic level definitions are asymmetric, ie, the maximimum legal voltage for a logic "0" is relatively low. If you insert the voltage drop of a bipolar transistor into a peripheral's ground line, then it may be borderline unable to drive a fully legal '0' to the ATmega, which is reference to the lower true ground and would see the peripheral's ground difference added to its output voltage.

A better approach would be to use either a high-side switch (as there is typically more room between the minimum legal '1' and the supply) or else to use an FET switch which would have a much lower voltage drop.

Also keep in mind that most IC's are not specified to tolerate lasting I/O voltages much outside of the range of their power suppliers, and in fact their protection diodes may mean that application of such voltages effectively powers them through the I/O pin.  So before turning off power to a peripheral, you probably want the ATmega software to assert all shared I/O lines towards the side of the peripheral supply which is not being disconnected, ie, for a low side switch drive everything high and for a high side switch drive everything low.

Finally, the process of power cycling could potentially confuse peripheral interface engines and it is possible that some error flags set in this process might never be cleared.  So you may want to clear the flags of and generally re-initialize your USART, I2C, etc on resume.


message:
Pressure Sensor and Arduino

I am currently working on reading pressure values using a tekscan a201 sensor. The sensors I have are limited to 25lbs.

My plan is to use eight on these sensors of them with a arduino Mega. Since I am measuring the resistance, I am thinking of making a 8 similar voltage divider circuits and grabbing the voltage reading via arduinos analog pins.

At the moment, I am not sure how to convert these readings to engineering units. Any ideas?

body:
I have not previously met the Flexscan sensors but from the datasheet it appears that there are versions of the A201 rated at 100 pounds are you committed to the 25 lbf version?

[**A201 datasheet here**](https://www.google.co.nz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CEkQFjAC&url=http://www.tekscan.com/pdf/FLX-A201-force-sensor.pdf&ei=cszJVOrPJZLN8gWU_4Bw&usg=AFQjCNGNy5nCyCNgagOzaIMfsUIpSFlRGg&sig2=_D791hWWRz5tzqHSp0zcxg&bvm=bv.84607526,d.dGY&cad=rja)

Here is a [**15 page user manual**](https://www.google.co.nz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&ved=0CFUQFjAE&url=http://www.tekscan.com/pdf/FLX-FlexiForce-Sensors-Manual.pdf&ei=cszJVOrPJZLN8gWU_4Bw&usg=AFQjCNGCYZTma0vkXT0e2BsH7Y07yQ_tcw&sig2=ZMxG630bjh44caLTmokRJg&bvm=bv.84607526,d.dGY&cad=rja) thatexplains how to produce a voltage output using a single opamp per sensor - bottom of page 9.

[Many idea starters **here**](https://www.google.co.nz/search?q=tekscan+a201&biw=1745&bih=977&source=lnms&tbm=isch&sa=X&ei=cszJVOrPJZLN8gWU_4Bw&ved=0CAYQ_AUoAQ)

_____________

What is your application and why do you wish to use these sensors. These seem to be a low accuracy alternative to eg load cells and seem to be expensive for what you get. If you need 8 for your task a loadcell based solution may e cheaper.


body:
I decided go with the voltage divider approach as it seemed simple enough. The sensors themselves needed to be calibrated, which took me a while as I didn't have the required weights.

After the calibration, I used the line of best fit approach to find an equation that translated voltage to force.


message:
Programming an Array of ATTiny

I am designing a board for my electronics project and i am using a number of ATTiny85 for it. The ATTiny's will be SMD so i will not be able to remove them for programming.

Moreover all of the pins of my uCs will be used for connections (apart from reset).

Is it possible in this case to achieve that, any ideas and suggestions are welcome

EDIT: Well, Vcc and Ground will be common, i will be using an external oscillator for all of them, the reset pin will be free, the other three pins will be used for gpio communication between the attinys.
I am connecting about 10 attiny in a daisy chain kind of thing

body:
As long as whatever you're connecting the MISO, MOSI, and SCK pins to doesn't mind being driven externally, you can still program the ATTiny in-circuit - just break out those pins with reset to a standard 6 pin header and program them that way.

If one or more of those pins can't be driven externally (eg, because they're connected to another device that drives them and has no output disable), you'll need to add a tristate buffer IC between the MCU and the other device, or some jumpers you can remove when you want to program them.


message:
Chain of, or one big if sentence

(This might be more of a common C question)

I want to test several conditions in an IF-sentence

    if(variable) {            // fastest check
      if(register) {          // a bit slower
        if(read_peripheral) { // very slow check
          // [do something]
        }
      }
    }

It seems obvious that I want to start with the fastest check, and move on to the slower ones afterwards, potentially avoiding to check them if the above was false.

Now since I need to check quite a few conditions, I'd like to know if the following is the same, or if all conditions will be evaluated prior to making a decision?

    if(variable && register && read_peripheral) {
      // [do something]
    }

body:
Putting them all in a single condition like that is absolutely fine. C/C++ uses "short circuit evaluation" which means it will stop as soon as it's determined the outcome. If everything is combined using logical AND operators (&&) then that means it will stop as soon as one of them evaluates to false.

For example:

     if (blah() && foo()) { ... }

If `blah()` returns false, it will never call `foo()` at all because it already knows the overall outcome is false.

The reverse happens with the logical OR operator (||):

     if (blah() || foo()) { ... }

If `blah()` returns *true* in this case, it won't call `foo()`. That's because it already knows the overall outcome is true.


message:
Can't program Arduino via Bluetooth (HC-06) with a Mac

I bought a HC-06 Module for my Arduino Uno the other day, yesterday it arrived and I'm having trouble using it with the Arduino IDE.

I set it up, connecting 5V, GND and RX/TX crossed. After a bit of searching, it shows up on the bluetooth settings on the macbook. When I click "connect", it fails, after I click "Options", then set the Pin to 1234 it says "Connected". The LED on the HC-06 is still blinking (which is OK I guess, since I'm not yet communicating).

I have a Sketch running on the Uno that prints out some text. When I open the serial monitor (after connecting like above) it works, displaying the values I expect. However, after closing the serial monitor the HC-06 changes to "not connected" on the mac.

Also, if I try to upload code via the Arduino IDE it states: `avrdude: ser_open(): can't open device "/dev/tty.HC-06-DevB": Resource busy
ioctl("TIOCMGET"): Inappropriate ioctl for device` or throws a `processing.app.SerialException: Fehler beim Öffnen des seriellen Ports "/dev/tty.HC-06-DevB".` (German for "Error while opening Serial Port "/dev...." ").

Do I have to configure the HC-06 or the Arduino IDE in any way to make this work, and, if so, how can I do that?

**Edit:**
I've also connected TX and RX uncrossed, though that alone doesn't solve the problem.

Thanks in advance for your Support!

body:
If I remember correctly, you do not want to cross TX and RX.

Usually, you cross TX/RX because you are looking at it from the opposite side - the PC's TX is the Arduino's RX and vice-versa.

However, in the case of BlueTooth, the HC-06 has the same perspective as the Arduino - TX (transmit) is TX on the HC-06, since that is what the HC-06 transmits (over Bluetooth).

Also, if you are connect your Arduino via USB, the TX & RX are also connected via USB; I don't know if this would cause cross-talk. It shouldn't (so long as you don't send to your Arduino using Bluetooth AND USB at the same time), but it may. Also, as you're programming the Arduino using Bluetooth, you may get the Arduino's responses coming back to you via Bluetooth.

ADDITIONAL:

Go read http://arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader - this is all about the bootloader.

It seems from that that current bootloaders run at 19200, some older ones run at 9600. There are commands to program the speed on HC-06 - instructions can be found at http://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/ (this covers the hc-06 too).

Based on the bootloader tutorial, I think you have "less than a second" (only two specific boards are mentioned, so this is a best guess; I am amazed that it is this long, I expected a few milliseconds). If you have a USBISP, you could compile and upload a new firmware, with settings more to your liking - this is outside the scope of this article.

Another option is to create a completely separate uploader - an AtTiny could do it. Connect the AtTiny to the serial port, and then get the AtTiny to reset and program the board, or even program it via ICSP. This is a lot of work, and also outside the scope of this article.


body: Regarding the ability to upload, that is correct - you won't be able to upload code via Bluetooth. In addition to providing a serial connection, the USB connection does something extra (hold reset, I think), when you upload via serial-over-usb.


body:
The on-board USB-to-serial pulses the reset line to start the bootloader. HC-0x don't have the extra signal available that USB uses for that so you'll have to manually reset the Arduino just as - or very slightly after - you click to start the upload on your Mac; you may need to experiment to get the timing right, but once you know it, it isn't hard to do. Keep Rx & Tx crossed as you do for Bluetooth terminal communication. And even with all that, I've never achieved anything like USB upload speeds (baud rate for baud rate) using Bluetooth.

Update:<br>
In brief, it could be timing, baud-rate, or pairing.

I find it easy to get the timing: hold reset / click (and let go) the upload button / release reset. It doesn't need to be so fast that it's a challenge to coordinate but do it faster than counting seconds.

Your HC-06's baud rate will have to match the baud-rate your boot-loader expects. It looks like Uno's bootloader's use 19200 baud (and there are some way older ones that used 9600). My bare, pre-programmed chips' boot-loaders from Adafruit.com use 57600 baud. Your `preferences.txt` file should contain a line like 'atmega328o.upload.speed=115200'; assuming you're able to upload via USB, then use this baud rate for the HC-06. (The path to your preferences file is displayed on the Arduino IDE's preferences dialog.)

The 'Resource busy' message sounds like your Mac isn't paired with your HC-06. In the MacOS Bluetooth System Preferences pane, pair the Mac with the HC-06 and be sure HC-06's LED is on steady (not blinking).


body:
After dealing with the problem for several hours I unexpectedly solve the problem.

The HC-06's LED keep blinking after I entered the "1234" code. In my case (I'm using Windows 10), the HC-06 status changed to "connected" for few seconds and then changed to "Paired". Once I opened the correct COM port to receive data from the HC-06 to my PC computer, the LED changed to solid ON. Then I was able to catch data from my Arduino UNO. As soon as I closed the COM port in my PC (I used CoolTerm), the LED changed to blinking back again. The COM port I used to receive the data was the one indicated with direction "Outgoing" in the PC's Bluetooth settings. So, I was expecting the HC-06 to behave as my Bluetooth speakers or my Bluetooth headphones: Always connected. I was wrong and it cost me several hours of testing.

In my firsts tests I focused opening the COM port with direction "Incoming". Nothing happened here and I lost a lot of time. I tested my wiring between the arduino and the HT-06 module by changing the device name from "HC-06" to "ArduinoBT01" and it worked.

This is the sketch I used to receive data form the Arduino via Bluetooth:

[![enter image description here][1]][1]

This is the CoolTerm's window capture:

[![enter image description here][3]][3]

Mysteriously, the CoolTerm speed setting is 14400bps but the speed in the device manager for COM34 is 9600bps. After triying opening many times the COM34 port with 9600bps I got this error in CoolTerm:

"An error occurred while attempting to open the port".
"1168: Error 1168"

So, it only works with 14400 bps. Crazy!!

I hope this helps.

Sorry for bugs in my English.

  [1]: https://i.stack.imgur.com/HKL3M.jpg
  [2]: https://i.stack.imgur.com/3J3A6.jpg
  [3]: https://i.stack.imgur.com/XOD8q.jpg
  [4]: https://i.stack.imgur.com/5laAg.jpg


message:
What are the environmental requirements of an Arduino?

I'd like to use an Arduino Yún in a somewhat outdoor environment (in a metal box on a truck).  I think I've seen that the temperature requirements of the Uno are -40 °C to +85 °C, but I can't find that information about the Yún.  It would be nice to know where to find information about the temperature and humidity safe working requirements for every Arduino model.

body:
The AtMega32u4 (the chip that drives the Arduino Yun) has an operating requirement of -40 to +85, so if you go outside that range, you will definitely void warranty (which is not to say it will break, of course!). See datasheet at http://www.atmel.com/devices/atmega32u4.aspx

A datasheet for the AR9331 seems to say that it only works down to 0°C ( http://www.eeboard.com/wp-content/uploads/downloads/2013/08/AR9331.pdf page 305, "Commercial Case Temperature") - this seems awfully high for a minimum temperature.

While that does not mean that, inside that range, you are safe, I would *GUESS* that you probably are - I would guess that the AtMega32u4 or AR9331 is going to be the most delicate part in there.

Of course, to get a definitive answer, you (or someone) would have to check the specs on each part.


message:
Adafruit CC3000 jumper pads

if I solder the jumper pads on the adafruit cc3000 for use with the Arduino Mega will it still work fine with the Uno?

body:
**This module is designed to be "plug in and go"** without access to anything except the connector pads at the board edge. While there are a number of pads on the face of the board these are for "experts only" access and are unneeded for normal operation.

The only soldering required should be the addition of a 9 pin row of pins to allow the CC3000 module to be plugged into a solderless breadboard or a socket. If this is all you do then the module will work directly and interchangeably with  Arduino Uno, Leonardo/Micro & Mega. These are the only Arduino versions that a full library is available for so far. ADAFruit promise more versions will be supported "sometime".

Additional information is available from
 [WIRELESS / WIFI / ADAFRUIT HUZZAH CC3000 WIFI BREAKOUT WITH ONBOARD ANTENNA](http://www.adafruit.com/product/1469)

Solder on connector and go ...

[**Larger version of photo here** makes pin use clear - + see link above](https://i.stack.imgur.com/9uoaZ.jpg)

![enter image description here][1]

_____________________

Example use [**weather station**](https://learn.adafruit.com/wifi-weather-station-arduino-cc3000)

[**Low power use tutorial**](https://learn.adafruit.com/low-power-wifi-datalogging)

  [1]: https://i.stack.imgur.com/9uoaZ.jpg

Example use [**wireless lamp**](https://learn.adafruit.com/wireless-power-switch-with-arduino-and-the-cc3000-wifi-chip)

[**Library**](https://learn.adafruit.com/adafruit-cc3000-wifi/cc3000-library-software)


message:
I am looking for the source and/or proper definition for the int() function

.
I have searched through the source in Arduino.app, without much success.

The reference gives a terse explanation

 int(x)
  x: a value of any type
  Converts a value to the int data type

Passing 1, '1' or 49 returns the int 1. I haven't tested other types.

This seems to be an Arduino specific function - it doesn't seem to be in any c/c++ library.

body:
`int(x)` is not a function but **another way to perform an explicit cast** of `x` to an `int`. It is part of the C++ language itself, that is why you could not find it in a library.

This is not Arduino-specific.

In C and C++ you can cast a value to an int by doing this:

    int y = (int) x;

**C++** has extended this notation by allowing to do it this way, which is equivalent:

    int y = int(x);

You can find this [in more details][1] in C++ language reference.

  [1]: http://en.cppreference.com/w/cpp/language/explicit_cast


message:
What is Vin for the EthernetPOE board?

I am working on a project that needs to drive a relay board. I'm looking at the ETHERNET board with PoE and according to the documentation here (http://arduino.cc/en/Main/ArduinoBoardEthernet) the output of the PoE module is 9V.

Is that the voltage to expect out of the Vin pin?

The Relay board that I want to use (http://numato.com/downloads/dl/file/id/29/product/47/user_manual.pdf) specifies that it wants a 7-12V power supply.

I want to confirm that this is the case so I can use the voltage out of the PoE and I don't need to add a separate DC power supply to this system.

body:
I wouldn't expect you to take any power from V-**in**-, but it actually seems like you can!

If you take a look at the [schematic][1] for the Rev.3 Arduino Ethernet, you can see the power rails from Ethernet is connected to Vin. (`V1+`, `V1-`, `V2+`, `V2-` --> `Vin` in the leftmost part of the schematic)

  [1]: http://arduino.cc/en/uploads/Main/arduino-ethernet-R3-schematic.pdf


body:
Your question is a little confusing, so let me give you a couple pieces of information.

First things first - the VIn pin on the Arduino is strictly for power going to the Arduino board, you shouldn't be drawing power from this pin. The documentation in the link you sent is a little misleading on this - it's basically saying 9v is coming OUT of the PoE module, and going IN to the VIn on the Arduino itself. If you wanted to tap into this 9v power, you should connect to the PoE module VOut instead.

PoE by default can deliver 37-57 volts or 42-57 volts, depending on what type of PoE you're using (which 802.3 specification). [Wikipedia](http://en.wikipedia.org/wiki/Power_over_Ethernet#Standard_implementation) has a good overview of this information.

That being said, the Arduino Ethernet board you're using can't handle this voltage by itself - unless these boards have changed, they require an additional [PoE module](http://store.arduino.cc/product/X000002), which is basically just a DC-to-DC buck converter that will convert the high PoE voltage down to 9v or 12v. At this point, the Arduino's built-in converter can consume that 9 or 12v and distribute it at 5v across the board.

Now, to your problem - you want to power a relay that requires 7-12v. You could theoretically connect the relay to the VOut of the PoE module, giving you 12v. However, if the relay draws too much power for too long, you will either get brownouts (and your Arduino will restart) or potentially damage the Arduino board. Unless the relay draws a lot of current or is being powered for extended periods, you should be fine. If you want to be more thorough, you could put a large capacitor between your PoE module and the relay.

You should NOT try to connect the relay directly to the PoE VOut, as the voltage will be far too high.


message:
Issue with PWM output pin

I'm just starting off with using the Arduino and was learning about PWM
(http://arduino.cc/en/Tutorial/PWM).
Below is what my circuit looks like.

![enter image description here][1]

  [1]: https://i.stack.imgur.com/MDY9x.jpg

Below is the very simple code.

    const int pinNine = 9;    // LED connected to digital pin 9

    void setup() {
      // initialize serial communications at 9600 bps:
      Serial.begin(9600);
      // set the digital pins as outputs
      pinMode(pinNine,OUTPUT);
    }

    void loop() {
      analogWrite(pinNine, 0);
    }

I was expecting my LED to not be lighted as its a 0% duty cycle. I even change the pinNine outputValue to (64, 127, etc) but for some reason the LED is always lighted. Any ideas?

_____________________________________________

body:
I have a few things you could try:

 1. Remove `pinMode(pinNine, OUTPUT)`, this is only used for digitalWrite(), the PWM controller might be affected by this.
 2. Did you select the correct Arduino Chip in the IDE? Arduino maps pin 9 to a hardware pin (PB1 for UNO), which is not consistent between different boards
 3. Try inserting a `delay(100)` after `analogWrite(...)`. I'm not sure if the analogWrite call restarts the PWM cycle, resulting in very fast switching that might be seen as 'always on'

Other than that, your sketch seems to be correct. I assume the black wire in the breadboard is wired to Ground, correct?