text:
How to connect relay

How to I connect the pins of one channel relay to control and led which is connected to pin 13 of an arduino uno.can you tell me the steps which pin will go to which pin

Unclear.  Do you mean to use the Arduino pin 13 LED signal to drive the relay?  Or some other LED to be controlled by the relay?

I insert an LED on pin 13 ....so I want to control that

You need no relay to control a LED.  Merely a resistor to limit the current.  See the 220 ohm resistor in series with the LED in the tutorial at https://www.arduino.cc/en/Tutorial/Blink -- they insert a LED in pin 13 in series with a resistor to Ground.

Are you asking which are the outputs and which are the inputs of the relay board?  Look at the bottom of the board and compare it to the datasheet of the relay: http://www.langir.com/pdf/pcb-relay-T73.pdf

But in my relay I don't have any sign like normal connection,command connection and all so I want to know which one is what

I modified my answer a bit -- you can look up the datasheet of the relay and follow the traces on the circuit board.  Us folks on the internet can't do that without better pics/diagrams.  Please be careful attaching your circuit to AC line currents.

I believe that the Arduino ground should be common with the 12v source ground. I may be wrong, though that's the way it works for me. Also be aware that some of these relay cards work when the pin is LOW, others when the pin is HIGH. Mine energises when the pin is HIGH, though all tutorials I had read until the last had the relay switching on with a LOW pin.

This relay has "Normally Open (NO)" and "Normally Closed (NC)" outputs. Applying voltage would "invert" these.

Wiring Diagram to Pin 13 for a single relay? This might help.

It looks like http://www.elesof.com/electronics/product/one_6v_spdt_relay_board  , http://shop.ciseco.co.uk/jqc-3f-t73-5v-pcb-relay/ and it probably works like http://www.electronics-tutorials.ws/blog/relay-switch-circuit.html
I'd bet that the I/P line connects to the center pin on the transistor through one of those resistors.    If so,  I'd put a 5V 100mA source on the GND +5 pins on the side, then I'd use a jumper from the +5 on the end to the I/P on the end, and see if it triggers the relay as expected.
If so, I'd siconnect the jumper and I'd connect the end terminal's GND to the arduino GND, and (maybe?) pin 13 to the I/P line and expect the Blink tutorial that blinks the Arduino's LED to click the relay in time.
If you are asking which are the outputs and which are the inputs of the relay board, I can't tell from the pictures. Look at the bottom of the board and compare it to the datasheet of the relay: http://langir.com/pdf/pcb-relay-T73.pdf  --

I'd bet that screw terminals are the outputs, connecting to the right hand pair of outputs, and the center of the left hand three inputs.   And that the  control terminals are the pin connectors, with the I/P conneting through the transistor to one end of the coil, with the other end of the coil going to the +5V/12V pin connector.  There are likely two sets of pin connectors to provide for a separate coil/relay supply on the GND,5V12V connector versus a signal or signal plus power on the GND,I/P,5V/12V pin connector.  I'd bet the same-named pin connectors are electrically identical.  i.e. GND=GND and 5V/12V=5V/12V.
If you are controlling other than low voltage devices with this, I suggest you make certain you are safe before applying potentially dangerous currents.

Of course I don't need a relay for led but if I want to control an AC bulb..and can you tell me which one is command,normal connection of relay on that image

Common is always in the center, facing the terminals NO will be on the left in most cases and NC on the right.


text:
Posting to EEPROM via HTML - ESP8266 Arduino IDE
For those of you familiar with my somewhat steep EEPROM learning curve...thank you for continuing to share your knowledge.  I see how it's supposed to work and it's falling into place.
I've run into a new problem and I've spent two nights (~15hrs of Googling/trial and error...mostly error) trying to understand where I'm going wrong.
Below is a chunk of code that take user inputs from a webpage and saves it to EEPROM.  It works as intended when only SSID and PASS fields are provided on the form.  I added an "owner" field to add my name to the EEPROM (because why not?) and now the PASS field is ignored and the OWNER information is saved to the PASS and OWNER EEPROM locations.
I think it has something to do with the string.indexof("&") and repeated string.lastindexof("=") but I'm still wrapping my head around what these actually do.  If I understand it correctly, the second string.lastindexof("=") is actually overwriting the PASS which was saved milliseconds earlier.  If this is correct, how do I prevent this?  If I'm wrong, why?
  s += "<form method='get' action='a'>SSID: <input name='ssid' length=32>
PASS: <input name='pass' length=64>
OWNER: <input name='owner' length=32>

<input type='submit'></form>";
  s += "\r\n\r\n\r\n";
  Serial.println("Sending 200");
}
else if ( req.startsWith("/a?ssid=") ) {
  Serial.println("clearing eeprom");
  for (int i = 0; i < 128; ++i) {
    EEPROM.write(i, 0);
  }
  String qsid;
  qsid = req.substring(8, req.indexOf('&'));
  Serial.println(qsid);
  Serial.println("");
  String qpass;
  qpass = req.substring(req.lastIndexOf('=') + 1);
  Serial.println(qpass);
  Serial.println("");
  String owner;
  owner = req.substring(req.lastIndexOf('=') + 1);
  Serial.println(owner);
  Serial.println("");

  Serial.println("writing eeprom ssid:");
  for (int i = 0; i < qsid.length(); ++i)
  {
    EEPROM.write(i, qsid[i]);
    Serial.print("Wrote: ");
    Serial.println(qsid[i]);
  }
  Serial.println("writing eeprom pass:");
  for (int i = 0; i < qpass.length(); ++i)
  {
    EEPROM.write(32 + i, qpass[i]);
    Serial.print("Wrote: ");
    Serial.println(qpass[i]);
  }
  Serial.println("writing eeprom owner:");
  for (int i = 0; i < owner.length(); ++i)
  {
    EEPROM.write(96 + i, owner[i]);
    Serial.print("Wrote: ");
    Serial.println(owner[i]);
  }
  EEPROM.commit();

To summarize, my questions are:
-what is causing the code to skip over my PASS field and save a duplicate of OWNER into both PASS and OWNER?
-is one \r\n pair required for every field on the html form?  If I used 100 fields would I need 100 * \r\n pairs after  tag?
If you're interested in seeing the whole shebang, chriscook8 has graciously posted the Access Point sketch for the ESP8266 here (~250 lines).  There is also a very helpful discussion about this sketch here.

Edit: 3 July 2016
I've amended the code:
s += "<form method='get' action='a'>SSID: <input name='ssid' length=32>
PASS: <input name='pass' length=64>
OWNER: <input name='owner' length=32>

<input type='submit'></form>";
s += "\r\n\r\n\r\n";
Serial.println("Sending 200");
}
    else if ( req.startsWith("/a?ssid=") ) {
      Serial.println("clearing eeprom");
      for (int i = 0; i < 128; ++i) {
        EEPROM.write(i, 0);
      }
      String qsid = server.arg("ssid");
      String qpass = server.arg("pass");
      String owner = server.arg("owner");
    }
    Serial.println("writing eeprom ssid:");
    for (int i = 0; i < qsid.length(); ++i)
    {
      EEPROM.write(i, qsid[i]);
      Serial.print("Wrote: ");
      Serial.println(qsid[i]);
    }
    Serial.println("writing eeprom pass:");
    for (int i = 0; i < qpass.length(); ++i)
    {
      EEPROM.write(32 + i, qpass[i]);
      Serial.print("Wrote: ");
      Serial.println(qpass[i]);
    }
    Serial.println("writing eeprom owner:");
    for (int i = 0; i < owner.length(); ++i)
    {
      EEPROM.write(96 + i, owner[i]);
      Serial.print("Wrote: ");
      Serial.println(owner[i]);
    }
    EEPROM.commit();
    s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\nHello from ESP8266 ";
    s += "Found ";
    s += req;
    s += "
 saved to eeprom... reset to boot into new wifi\r\n\r\n";
  }
  else
  {
    s = "HTTP/1.1 404 Not Found\r\n\r\n";
    Serial.println("Sending 404");
  }
}

I also made the following replacement per your recommendations:
//WiFiServer server(80);
ESP8266WebServer server ( 80 );

...and receive an error on this line:
WiFiClient client = server.available();

'class ESP8266WebServer' has no member named 'available'
I'm sure that there is a simple replacement for this.  Any idea what it might be?
Otherwise, I think I see where you're going with this and it seems much cleaner than I anticipated.
Thank you!

if you're using ESP8266WebServer - it has a function, arg(String name) ... so you'd do something like String ssid = ws.arg("ssid"); to get the ssid parameter from the request - ws in the example is a ESP8266WebServer object

I'll look that up.  Would that replace "String qsid" or "qsid = req.substring(8, req.indexOf('&'))"?

A code snippet for you - will expand later (just got tied up)
ESP8266WebServer server ( 80 );
...

else if ( req.startsWith("/a?ssid=") ) {
  Serial.println("clearing eeprom");
  for (int i = 0; i < 128; ++i) {
    EEPROM.write(i, 0);
  }
  String qsid = server.arg("ssid");
  String qpass = server.arg("pass");;
  String owner = server.arg("owner");

  Serial.println("writing eeprom ssid:");
  ... rest of your code

I will try this tonight.

I amended my OP with the new code and an error I get when I compile.

source: Stack Exchange

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

sort: votes


text:
ESP.deepSleep() - over and over?
Important note: the esp.deepsleep function uses microseconds, not milliseconds.
I posted another question here asking for clarification on how an RTC can be used to put a NodeMCU 12 to sleep for a long time (~24hrs or more).
This question concerns the use of ESP.deepSleep([microseconds]) with the NodeMCU 12 board.  There is a discussion here and I have followed the advice but have been unable to successfully implement the ESP.deepSleep() function using the Arduino IDE and a NodeMCU 12 board.
Initial findings:
-Connecting gpio16 (D0) to the RST pin causes a reset immediately upon entering sleep.  The entire boot process and loop are repeated over and over again.
-Simply using the ESP.deepSleep() function without gpio16-to-RST generates gibberish on the serial monitor and illuminates the red led on the board.
My code is here (I just drop "deepsleep();" where I want the sleep process to begin):
void deepsleep() {
  Serial.println("sleeping hr 1");
  ESP.deepSleep(3600000); //1hr
  delay(100);
  Serial.println("sleeping hr 2");
  ESP.deepSleep(3600000); //2hr
  delay(100);
  Serial.println("sleeping hr 3");
  ESP.deepSleep(3600000); //3hr
  delay(100);
  Serial.println("sleeping hr 4");
  ESP.deepSleep(3600000); //4hr
  delay(100);
  Serial.println("sleeping hr 5");
  ESP.deepSleep(3600000); //5hr
  delay(100);
  Serial.println("sleeping hr 6");
  ESP.deepSleep(3600000); //6hr
  delay(100);
  Serial.println("sleeping hr 7");
  ESP.deepSleep(3600000); //7hr
  delay(100);
  Serial.println("sleeping hr 8");
  ESP.deepSleep(3600000, WAKE_RF_DEFAULT);  //8hr
}

What is wrong with this approach and why am I (apparently) causing an error?

just one point you may not be aware of ... the code you show suggests you think the ESP will continue on from after the deepsleep once it wakes up - that's not the case. after it wakes from deepsleep, it goes through the boot process (with a boot reason that indicates it has woken from sleep) - when you say "the entire boot process are repeated", do you mean immediately? or after 1 hour?

Immediate.  Sorry for the confusion.

well, that's not good - if it were after 1 hour, then the solution is easy, but immediate is problematic

What's the solution for the 1hr error?

Not sure what you mean by that. Seeing as you say that the ESP isn't deep sleeping at all, then the question makes no sense

It's something that people may run into at some point and, if it's a simple answer, we are all better off knowing how to resolve it.  Even a simple explanation may get someone pointed in the right direction.

but that's not your problem - Anyway, the solution I'm speaking of regarding the code you posted is simply knowing that when a ESP awakes from deepsleep, it goes through full boot process, does not continue from where it left off. You can use system_rtc_mem to save some simple "state" so that when you boot, you know if this is an initial boot, or wake from deep sleep (and which deep sleep you've woken from) - the guy with a swiss accent has some nice code examples

Use a resistor between GPIO16 and RST. I usually use a 470 Ohm resistor. Shorting the pins with a wire does not work.
https://www.esp8266.com/viewtopic.php?t=14350#p64510
Maximum deep sleep is about 71 minutes. 3600000 microseconds = 3.6 seconds, not 1 hour. 1 hour in microseconds is 3600000000UL.
As mentioned in the comments, waking from deep sleep on the ESP8266 is a hardware reset so execution begins at the start of the setup function.

Every circuit for deep sleep I've ever seen has no resistor. I think the only issue was the sleep interval

inputs are high-impedance, so adding 470 ohms makes no practical diff

Yes, the linked-to topic is talking about also using an external method for resetting the board. In that case, you'll need a resistor, not when just connecting the GPIO to RST.

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

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


text:
Clearing SRAM in loop()
Very broad question here.  I don't know exactly what the problem is but I'll edit this post as we narrow down the possibilities.
I think I'm running into memory constraints.
I'm running a sketch that records two temperature values every 60 seconds and transmits them to an AWS RDB via wifi.  It works well for about two hours then stops.  I don't know if it's a memory constraint but I suspect that it is.  What other common problems (often overlooked by newbies) can cause a sketch to end after a couple hours of run-time?
Is there a simple way to add an instruction to a loop to clear the SRAM?
Arduino UNO + WiFi 101
Edit #1 12/24/2015:It's the WiFi board.  It happily remains connected to my phone's hotspot but only lasts an hour or two on my home network.  Working on root cause...any ideas are welcome!
Edit #2 12/25/2015:Tried to Wifi.disconnect() and reconnect with no luck.  Why do some networks kick the board off while others work just fine?  Will look into the watchdog.

Sounds like maybe you need to implement watchdog reset.

Do you have a link for a decent tutorial?

Look in the log file in WiFi access point for an error message that might guide your debugging.

The problem was solved with a "soft restart" loop. Posts #10 and #11 are all I needed:
http://forum.arduino.cc/index.php?topic=49581.0

Could you provide your sketch? At the rate you mentioned, 2 hours is merely 240 values and this shouldn't even matter since you are probably reassigning values to the same variables and not storing them in some growing array. Perhaps your WIFI shield merely gets disconnected from the network. How do you mean the sketch stops? Like you no longer receive the values in the database? More info is needed.

Good point. I'll try the simple thing first. I'll let it run on my phone hotspot for a few hrs and report back.  I'd also like to avoid posting the sketch...I don't want a spoon-fed answer.


text:
Signal a LOW level interrupt with an RTC
I'm trying to figure out how to use an RTC to send interrupts to my arduino. I'm using a DS3232. I can get an 'edge' interrupt, with the following toy code (I know the code is silly, it's just a short example to test if I have actually set the RTC to send the interrupt, and that the Arduino receives it):
/*----------------------------------------------------------------------*
 * Minimal example of setting a recurring alarm with the DS3232 RTC     *
 * Attach an LED to pin 7, which will flash when the alarm fires.       *
 *                                                                      *
 * Attach the RTC SQ/INT pin to Uno pin 2, with a 10K pull-up to VCC.   *
 * Ard pin A4 -> RTC SDA, Ard A5 -> RTC SCL, 5v -> vcc, GND -> GND      *
 *----------------------------------------------------------------------*/

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Time.h>             //http://playground.arduino.cc/Code/Time
#include <Wire.h>             //http://arduino.cc/en/Reference/Wire

#define WAKE_PIN 2
#define LED_PIN 7

void setup(void)
{
    pinMode(LED_PIN, OUTPUT);

    // RTC config:
    RTC.squareWave(SQWAVE_NONE);
    pinMode(WAKE_PIN, INPUT_PULLUP);
    attachInterrupt(INT0, wakeUp, FALLING);
    RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 1);
    RTC.alarm(ALARM_2);
    RTC.alarmInterrupt(ALARM_2, true);
}

void loop(void)
{
  if(RTC.alarm(ALARM_2)){
    digitalWrite(LED_PIN, HIGH);
    delay(5000);
    digitalWrite(LED_PIN, LOW);
  }

}

void wakeUp (){
// no-op, just checking if the interrupt fired
}

Why doesn't this work if I set the interupt to "LOW", ie., attachInterrupt(INT0, wakeUp, LOW);?
The reason I ask is I'm trying to use an RTC to wake from low power mode, and I think this doesn't work with a 'falling' interrupt.

So when you use LOW, the LED doesn't blink at all? Have u tried detaching the interrupt in the ISR and re-attaching in the IF block, to prevent multiple firings while the pin is low? Do you have any idea how long the pin remains low before going high again? Perhaps the arduino is too slow to respond

Yes, with LOW the LED does not blink ever. I have tried detaching the ISR and reattaching it without success. However, I've determined that the problem I have been fighting the last hour was due to placing the ISR definition after the loop function - which isn't supposed to matter. I'll update to the latest IDE and see how much of my problem is due to using an old and buggy IDE :/

That page is incorrect, although it reflects what the datasheet says.
The processor can be woken from RISING/FALLING/CHANGE/LOW. I queried this with Atmel and got this response:

Commented by Manoraj Gnanadhas (Atmel)
2015-01-20 06:23:36 GMT
[Recipients: Nick Gammon]
Hello Nick,
Our design team has confirmed that “Note-3 mentioned under Table 10-1” is a datasheet bug. So you can use any type of interrupt (Rising edge/ Falling edge / Low level / Any logical change) to wake up from sleep mode. Sorry for the inconvenience caused.
Best Regards,
Manoraj Gnanadhas

This is mentioned on my page about interrupts.

Why does LOW hang the processor? The LOW interrupt is not an edge interrupt but a continuous one. Thus, while the signal is LOW the interrupt is being continually called, with only one processor instruction being executed after each call to the ISR (which itself takes around 5.125 µs). So, the ISR is not being interrupted, but effectively only one instruction of your code is being executed every 5.125 µs (probably about 1/40th of the usual speed).

and see how much of my problem is due to using an old and buggy IDE

It's nothing to do with the IDE. Change to a FALLING interrupt and your problems should go away. You may also want to clear the interrupt flag (as documented on my page) in case the interrupt event has already happened before you go to sleep. Specifically:
EIFR = bit (INTF0);  // clear flag for interrupt 0

Thanks Nick. I have managed to get a cut-down excerpt of your data logger code working, using the WDT interrupt. I'm going to need to study this further - I have a few different sources like yours that I can get running as-is, but any modifications I try break them quickly! Clearly more study on my part is needed.


text:
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)
I’m sorry if I sound ignorant and naive, but I’m brand new to Arduino;  very keen, but know very little.
I started with a Sainsmart Arduino Uno clone board.  I downloaded the software, which opened OK (or at least seemed to), but the Serial Monitor kept telling me that there was a communication error, and a yellow light kept flashing on the Sainsmart board.
I got hold of a genuine Arduino (from Jameco), uninstalled everything Arduino, and started again from scratch.
Now I get the message:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)
  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

And after enabling the verbose output, got:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)

Tried again, and:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)

I’m using a MacBook Pro, using Yosemite 10.10.5.

Try restarting your computer.

Why are you trying to communicate with a bluetooth modem when the Arduino plugs in through USB?

Is there a /dev/tty.Bluetooth-Modem? @Majenko that's an OSX thing. I have the same thing here on my Mac.

@Gerben I know what it is - I am just wondering why the OP is trying to use it.  It's the equivalent to /dev/rfcomm* on Linux.

Sounds like the wrong port to me. It shouldn't be on the Bluetooth-Modem port.

The Bluetooth Modem port is obviously wrong, but it's there on just about every Mac, so people seem to choose it in desperation when their Arduino (or more commonly clone) is not recognized.  Needless to say it will not work.

You are not selecting the correct port to upload to - hence the strange message about the Bluetooth modem. Start by unplugging your Uno and running Arduino. Select Tools -> Port from the menu bar. You should see a list of options. Now plug in your Uno and do the same again. You should see an extra port listed now - this will be the Uno. Select it. You will need to check this every time you connect a board.
Also, before you click Upload, make sure you have Arduino Uno selected under Tools -> Board in the menu bar.


text:
Arduino Pin won't go LOW
I have something strange going on with an output. When the following code is called the LED goes on, but it stays on, there is no blinking. If I comment out the set HIGH statement the LED never comes on (as expected).
#define devicePin 10

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

void loop() {
    digitalWrite(devicePin, HIGH);
    delay(2000);
    digitalWrite(devicePin, LOW);
}

Could I have damaged the board in some way?

you forgot to add a delay after digitalWrite(devicePin, LOW);
#define devicePin 10

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

void loop() {
    digitalWrite(devicePin, HIGH);
    delay(2000);
    digitalWrite(devicePin, LOW);
    delay(2000);
}

Yes, the pin is going low. I tested it for you:

It went low for 6 µs, once every 2 seconds. :)

Overall, this is the effect:

As you can see, high for most of the time.

Yeh, I can't believe I missed it.
BTW: what did you use to monitor it and create those screens?

My trusty Tektronix TDS 2002 oscilloscope. To get the output I get the scope to output in PCX format through its RS232 port, route it through a RS232 to TTL converter, connect that to a FTDI cable, and capture it on my computer. That scope was made in the days before they had plug-in USB drives.

One more question, what would you recommend now for an entry level scope?

You are probably best off with one of the Saleae Logic scopes/logic analyzers. Something like the Logic 4 is only $109 and has one analog and 3 digital channels. Or one of the higher models if you can afford it. I find the Logic very very useful for decoding SPI/I2C/Serial data streams. You could make this a separate question, others may also want to chip in with their suggestions.


text:
Printing arduino pin numbers to MySQL
I mistakenly posted this on stack overflow first.  The community was kind enough to point me to this forum.  I apologize for the double-post.
I've been working on an Arduino Uno r3 + WiFi Shield project for a few months now building up the complexity as I go. I've hit a wall. I started this project with exactly zero experience writing code of any kind and exactly zero experience working with boards. If you have any doubts as to whether or not I'll understand your response, please dumb it down!
I've made a simple arduino + wifi shield setup that can report a button push to a MySql database. All of the .php stuff on the backend works and the database is managed with phpmyadmin. I'm trying to add a second button but can't seem to make it work and need some help.
I have settled on a four-field database table as the output:

1st column: the key. A sequential, unique identifier for each entry
2nd column: the pin number that the sensor is connected to
3rd column: the sensor value
4th column: the date and time

Notice that I'm not using a dedicated column for each sensor. By using the sensor pin input, I want to simply print the sensor pin number in a column. This (a) saves space in the table and (b) allows the Arduino to use as many sensors as it has pins.
The idea is that each button press (even if two are pressed simultaneously) will get it's own line, sensor pin source, value, and timestamp. No values will be sent unless a button is pressed.
I haven't the foggiest idea of how to implement this! Help!

My question:
How can I ask the sketch to retrieve the pin from which a signal originates and write it to the db as a number in the second column? The 13th line of code is what will write the pin number (I think). The "senseval=" needs to be a variable that reports the source pin.
I don't know how to set this up and google has led to nothing but dead ends. I'd like this thread to answer the questions I'm sure a few more people have/will have!

My sketch is included below and the insert_php_doc below that. I'm using the Silinas/Benoit "Arduino /Post" example from github:
#include <SPI.h>
#include <WiFi.h>

char ssid[] = "linksys";
int status = WL_IDLE_STATUS;
WiFiClient client;
IPAddress server(xxx,xxx,xxx,xxx);

int inPin_0 = A0; // choose the input pin (sensor #1)
int inPin_1 = A1; // choose the input pin (sensor #2) //ADDED FOR SECOND BUTTON//
int sensorSense_0 = 0; //variable
int sensorSense_1 = 0; //variable //ADDED FOR SECOND BUTTON//
String SensorVal = "senseval=";// "yourdata="
String senseval;//yourdata //MUST KEEP sensval for PHP

void setup() {
  Serial.begin(9600);
  pinMode(inPin_0,INPUT);
  pinMode(inPin_1,INPUT);  //ADDED FOR SECOND BUTTON//
  connectWifi();
}

void loop() {
  sensorSense_0=analogRead(inPin_0);
  if (sensorSense_0 == LOW){
    postData();
    delay(5000);
  }
  sensorSense_1=analogRead(inPin_1); //ADDED FOR SECOND BUTTON//
  if (sensorSense_1 == LOW){ //ADDED FOR SECOND BUTTON//
    postData(); //ADDED FOR SECOND BUTTON//
    delay(5000); //ADDED FOR SECOND BUTTON//
  }

void connectWifi() {
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid);

    delay(7000);
  }
}
}
void postData() {
  senseval=SensorVal+String(inPin_0);
  senseval=SensorVal+String(inPin_1); //ADDED FOR SECOND BUTTON//

  if (client.connect(server, 80)) {
    Serial.println("connecting...");

    client.println("POST /insert_mysql_doc.php? HTTP/1.1");
    client.println("Host: www.<domain>.com");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(senseval.length());//yourdata
    client.println();
    client.println(senseval);//yourdata
    client.stop();
  }
  else {
    Serial.println("Connection failed");
    Serial.println("Disconnecting.");
    client.stop();
    connectWifi();
    printWifiStatus();
  }
}

The insert PHP from https://github.com/ericbenwa/POST-Arduino-Data-Wireless:
<?php

foreach ($_REQUEST as $key => $value)
{
    if ($key == "senseval") {
        $senseval = $value;
    }
}

// EDIT: Your mysql database account information
$username = "test_user";
$password = "test_password";
$database = "test_db_name_here";
$tablename = "test_table_name_here";
$localhost = "localhost";

// Check Connection to Database
if (mysql_connect($localhost, $username, $password))
  {
    @mysql_select_db($database) or die ("Unable to select database");

    // Next two lines will write into your table 'test_table_name_here' with 'yourdata' value from the arduino and will timestamp that data using 'now()'
    $query = "INSERT INTO $tablename VALUES ($senseval,now())";
    $result = mysql_query($query);
  } else {
    echo('Unable to connect to database.');
  }

?>

int inPin_0 = A0; // choose the input pin (sensor #1)
int inPin_1 = A1; // choose the input pin (sensor #2) //ADDED FOR SECOND BUTTON/

...

  senseval=SensorVal+String(inPin_0);
  senseval=SensorVal+String(inPin_1); //ADDED FOR SECOND BUTTON//

The above is wrong because you are sending the pin numbers and not the values read from those pins. You previously read them here:
  sensorSense_0=analogRead(inPin_0);
  ...
  sensorSense_1=analogRead(inPin_1); //ADDED FOR SECOND BUTTON//

It is sensorSense_0 and sensorSense_1 that you should be sending.
Also, as Damiano Verzulli pointed out, your second assignment to senseval clobbers the first. You want something more like:
  senseval  = SensorVal + String(analogRead(inPin_0)) + ", ";
  senseval += SensorVal + String(analogRead(inPin_1));

Even that may not be perfect, I didn't read your PHP side.

Looking at the PHP side now:
$query = "INSERT INTO $tablename VALUES ($senseval,now())";

That isn't going to work too well for two values. I don't know your database schema, but that won't handle two values very well. A bit of tweaking and it might, or you could do two INSERT statements.

First of all, your statement: "I've made a simple arduino + wifi shield setup that can report a button push to a MySql database." is incorrect (or, at best, misleading) as the code you're running in Arduino is not talking with MySQL at all, but simply calling a remote PHP script via an HTTP/POST request.
So now your problem can be split in two parts:

checking if your arduino (via its own wifi shield) is correctly talking with remote HTTP server (invoking proper PHP script with related parameters);
checking if your PHP script is correctly dealing with MySQL.

As for 1), my first suggestion is to check web-server log files. Unfortunately you didn't tell us which web server (Apache? IIS? Other) are you running, as well as which operating system are you relying on (Linux? Windows? Other?). With Apache running on linux, tipically log files are stored in /var/log/apache or /var/log/httpd folders. There are plenty of other troubleshooting approaches but... please, let's start checking log files, ensuring that PHP script is invoked;
As for 2), your PHP script is lacking basic error-handling: should the insert (launched by the mysql_query function call) fail, you'll never know. I strongly suggest you to add proper error-handling code.
Based on official documentation it's as easy as checking the result value of the mysql_query call: "...For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error...." so what you have to do to improve your code (...and being notified about errors raised by MySQL via PHP) is to use something like following code:
$result = mysql_query($query);
if (!$result) {
   die('Invalid query: ' . mysql_error());
}

Having said all the above, let me add a couple of other notes.

in your OP, you wrote: "I'm trying to add a second button but can't seem to make it work". So it seems that previously you were testing with only one button and, in such a case, everything worked. Is it right? If yes, please, can you tell us what you changed to add proper handling of second button?
in your code I see following lines:

.
[...]
senseval=SensorVal+String(inPin_0);
senseval=SensorVal+String(inPin_1);
[...]

Please note that they are probably wrong, as the second line will override the assignment of the first one. So, with such lines, you'll surely/always loose the value related to inPin_0 (in other words: the first line, is useless).

giving a look to the server-side PHP script, I noted that it has been built to handle only one parameter (sensval passed to PHP via GET/POST parameter; with PHP storing it in the $sensval variable). So... to change the behaviour so to handle two different values... it's not trivial (in other words: such a change require a minimun understanding of web-programming and... getting deep to analyze such requirement is out of scope --I think-- of this answer).

Yes, you are right: Arduino > PHP > MySQL

Yes, you are right: Arduino > PHP > MySQL.  I've noted in the code what has "broken" the sketch.  A single button works perfectly.  I don't know how to make more than one work.  My ideal state is to have a four column db but I'm also OK with creating a column for each sensor.  I can't find any good tutorials on that though.  The little information that does exist is fragmented.  I'm running Ubuntu using phpmyadmin to manage the Apache db hosted by Network Solutions.

You might want to improve your testing, use some mocking or "unit tests".
You'll want to be sure your queries are right. Send some PHP queries for multiple buttons and check if it works. If that works, you can try to make the arduino check the buttons and activate the queries through your PHP webapp. Questions on PHP/MySql itself are unlikely to be well answered on the arduino forum.

So... to change the behaviour so to handle two different values... it's not trivial - it can be done, but you (the OP, not Damiano) need to brush on on SQL. I suggest testing the sort of statements you want purely in SQL first (forget the Arduino) and get the syntax errors out of the SQL side. Take a look at 13.2.5 INSERT Syntax - in particular the form for multiple inserts: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);


text:
Problem with Arduino code
Please help me with this code it's shows some error [but I can't be bothered to tell you what].
#include <TimerOne.h>

/**

 Analog Clock

 Paul Cox Dec 2010

*/

#define    PI       3.141592653589793e-06;

byte rows[8] = {9, 14, 8, 12, 1, 7, 2, 5};

byte cols[8] = {13, 3, 4, 10, 6, 11, 15, 16};

byte pins[16] = {5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};

byte screen[8] = {0, 0, 0, 0, 0, 0, 0, 0};

volatile byte screenRow = 0;

volatile byte screenCol = 0;

int iHour = 0;

int iMin = 0;

int iSec = 0;

void setup()

{

  Timer1.initialize(100);

  for (int i = 2; i <= 17; i++)

  {

     pinMode(i, OUTPUT);

  }

  Timer1.attachInterrupt(doubleBuffer);

  Serial.begin(9600);

  resetAnim();

}

void doubleBuffer()

{

  digitalWrite(translatePin(rows[screenRow]), LOW);

  digitalWrite(translatePin(cols[screenCol]), HIGH);

  screenCol++;

  if (screenCol >= 8)

  {

     screenCol = 0;

     screenRow++;

     if (screenRow >= 8)

     {

       screenRow = 0;

     }

   }

   if((screen[screenRow] >> screenCol) & B1 == B1)

   {

     digitalWrite(translatePin(rows[screenRow]), HIGH);

     digitalWrite(translatePin(cols[screenCol]), LOW);

   }

   else

   {

     digitalWrite(translatePin(rows[screenRow]), LOW);

     digitalWrite(translatePin(cols[screenCol]), HIGH);

   }

}

byte translatePin(byte original)

{

  return pins[original - 1];

}

void allOFF()

{

  for (int i = 0; i < 8; i++)

  {

     screen[i] = 0;

  }

}

void on(byte row, byte column)

{

  screen[column-1] |= (B1 << (row - 1));

}

void off(byte row, byte column)

{

  screen[column-1] &= ~(B1 << (row - 1));

}

void resetAnim()

{

  for (int i = 0; i < 8; i++)

  {

     screen[i] = B11111111;

     delay(25);

  }

  for (int i = 0; i < 8; i++)

  {

     screen[i] = B00000000;

     delay(25);

  }

}

void loop()

{

  drawClock();

  iSec++;

  if (iSec == 60)

  {

    iSec = 1;

    iMin++;

    if (iMin == 60)

    {

       iMin = 0;

       iHour++;

       if (iHour == 12)

       {

          iHour = 0;

       }

    }

  }

  delay(10);

}

void drawClock()

{

  allOFF();

  setHand(iHour,12,3);

  setHand(iMin,60,4);

  setHand(iSec,60,5);

}

// work out the pixel for a hand - val is out of a possible max val

// radius is distance from the centre

void setHand(int iVal, int iMax, int iRadius)

{

  double  dAngle = (iVal * 2 * PI) / iMax;

  double  dPosX = 4.5 + (iRadius * cos(dAngle));

  double  dPosY = 4.5 + (iRadius * sin(dAngle));

  drawLine(5,5,constrain(round(dPosX),1,8),constrain(round(dPosY),1,8));

}

void drawLine(int x0, int y0, int x1, int y1)

{

  int      iTemp;

  boolean  bSteep = abs(y1 - y0) > abs(x1 - x0);

  if (bSteep)

  {

     iTemp = x0; x0 = y0; y0 = iTemp;    // swap x0,y0

     iTemp = x1; x1 = y1; y1 = iTemp;    // swap x1,y1

  }

  if (x0 > x1)

  {

     iTemp = x0; x0 = x1; x1 = iTemp;    // swap x0,x1

     iTemp = y1; y1 = y0; y0 = iTemp;    // swap y0,y1

  }

  int deltax = x1 - x0;

  int deltay = abs(y1 - y0);

  int error = deltax / 2;

  int ystep = ((y0 < y1) ? 1 : -1);

  int y = y0;

  int x = x0;

  while(x <= x1)

  {
    if (bSteep)
    {
       on(y,x);
    }
    else
    {
       on(x,y);
    }
    error = error - deltay;
    if (error < 0)
    {
       y = y + ystep;
       error = error + deltax;
    }
    x++;
  }
}

What error does it show?  And please format the code as a code block - highlight the code and press {} at the top of the editor.

I#ll do it for you this once, but next time format your question properly.  Also ask your question in the question area, not in the title!

#define    PI       3.141592653589793e-06; - apart from the semicolon problem, π is not 0.000003141592654.

"it's shows some error [but I can't be bothered to tell you what]." I'm amazed anybody has bothered to tell you what the problem was.

A selfish can tell the comment like you my friend. all minds are not same. I SOLVED MY problem with other  friend  named Majenko. some people have good heart not like you .  any way thank you very much.

@shinas The whole point of the error report in Arduino IDE (any all other IDEs, for that matter) is to tell you what the error is. You're lucky that the mistake in your code is almost the very first line and therefore very easy to spot. Nobody on the internet is telepathic anymore.

It's amazing the difference one character can make:

You must NEVER terminate a #define with a ; unless you absolutely know that you need one when it is expanded.

You have a macro defined:
#define    PI       3.141592653589793e-06;

That macro is then used here:
double  dAngle = (iVal * 2 * PI) / iMax;

Expand the macro PI and you get:
double  dAngle = (iVal * 2 * 3.141592653589793e-06;) / iMax;

Which obviously is a syntax error - you have a rogue ; in there where you really don't want one.
Oh, and one other thing - you shouldn't define PI - the Arudino core already defines it for you to a greater accuracy than you are:
arduino/Arduino.h:#define PI 3.1415926535897932384626433832795

... though you seem to be working in microPi's whatever those are...

Maybe he's using an Arduino Micro?

@NickGammon Or he moves in MicroCircles....


text:
analogRead function not working in MATLAB
I am new to Arduino and I am trying to control it through MATLAB.  I have downloaded the arduino IO package and installed it.I am using MATLAB 2014a.I have a LED and I change its brightness by changing the PWM voltage as follows :
a=arduino('COM3');
brightness_step = (5-0)/20;
   for i = 1:20
      writePWMVoltage(a, 11, i*brightness_step);
      val=a.analogRead(0);
      display(val)
      pause(0.1);
   end

   for i = 1:20
      writePWMVoltage(a, 11, 5-i*brightness_step);
      val=a.analogRead(0);
      display(val)
      pause(0.1);
   end
clear a

Everything works great except for the analogRead part which throws the following error :
No appropriate method, property, or field analogRead for class arduino.
What am I doing wrong?

That function is part of legacy code.

NOTE: This solution (formerly known as "Arduino IO Package") is no
  longer supported. It is recommended that you use Arduino support
  packages that are developed and supported by MathWorks:

MATLAB Support Package for Arduino Hardware: Read, write, and analyze data from Arduino sensors
  http://www.mathworks.com/hardware-support/arduino-matlab.html
Simulink Support Package for Arduino Hardware: Develop algorithms that run standalone on your Arduino
  http://www.mathworks.com/hardware-support/arduino-simulink.html

Use this legacy support only if one of the following is true:
- You are using MATLAB R2013b or earlier (but not earlier than R2011a).

You are using 2014a, so its probably the reason analogRead isn't working. Get the more recent package and use this function instead:

Sorry, I don't have MatLab to verify this but try this in the two places you call a.analogRead(0);
val=analogRead(a,0);

This is based on what appears to be the classdef for the arduino object.

Both val=analogRead(a,0) and val=a.analogRead(0) appear as valid examples in the function's description. I don't understand why one would work but not the other, but that's no reason not to try...


text:
While loop not breaking
I'm trying to build a circuit that buzzes until a button is pressed, or it buzzes 5 times:
void alarm()
{
  int AlarmState = 0; //Just to get while loop going
  int count = 1;
  while(AlarmState==0)
  {
    int count = 1;
    AlarmState = digitalRead(alarmStop);
    digitalWrite(buzz,HIGH);
    AlarmState = digitalRead(alarmStop);
    delay(500);
    AlarmState = digitalRead(alarmStop);
    digitalWrite(buzz,LOW);
    AlarmState = digitalRead(alarmStop);
    delay(500);
    count++;
    if(count>=5){
       break;
    }
  }

I put a bunch of digitalRead's  so it has a better chance of catching the button press while the loop is going, there's a better way to do that I'm sure but it's not my main concern right now.
This is part of a larger project, but I hope I've posted only the necessary code. The function runs, but does not break after count equals 5. Why?

Remove that int count = 1; from within the while-loop.

It would make more sense to use a for loop to count to 5, and then if (AlarmState != 0) break;.

@NickGammon for(unsigned char i = 0;i<5 && AlarmState != 0;i++){ ? Not sure if it fits the problem, but it's a little more readable (since you can see when the loop will end, within the statement/check).

Well it should be && AlarmState == 0 to match the original post, but yes, that is another way. Actually the posted code in the question reads alarmStop multiple times which is a bit alarming (no pun intended). I suppose it depends how quickly you want to react to a change in alarmStop.

Please note that with AlarmState = digitalRead(alarmStop); you just read the last value. Replace all those lines with AlarmState |= digitalRead(alarmStop);; this way as soon as one reading is 1 it will exit

I think the main problem with the code not breaking within the while() statement is what @ott pointed out above.
To expand on the exact problem, note that you have defined two different count variables in your code. Each has a different scope.
As soon as you enter the alarm function, you define an int count variable and initialize it. Then, when you enter the while () statement, you define a second int count variable and initialize it. These are NOT the same variable. This second variable is the one being used and unfortunately, is reinitialized each time through the loop. It will always have a value of 1 so your test for it becoming greater than or equal to 5 will never test true. Thus no break.
If you comment out the second int count line, your loop should then work and break as expected. it should look like this:
  while(AlarmState==0)
  {
  //  int count = 1;
    AlarmState = digitalRead(alarmStop);

Others have pointed out other improvements that can be made to the code but the two variables of the same name with different scopes appear to be the specific cause of the while() not breaking.

void alarm()
{
  int AlarmState = 0;
  int count = 1;
  while(AlarmState==0) //Your count == 2, then while starts over again and you redefine you count to 1, so thats becomes infinite loop
  {
    int count = 1; //Here you initialize "count" second time
    AlarmState = digitalRead(alarmStop);
    digitalWrite(buzz,HIGH);
    AlarmState = digitalRead(alarmStop);
    delay(500);
    AlarmState = digitalRead(alarmStop);
    digitalWrite(buzz,LOW);
    AlarmState = digitalRead(alarmStop);
    delay(500);
    count++; //Now you incrementing count value, 1+1 = 2, go back to "while" and read
    if(count>=5){
       break;
    }
  }

The problem with your code is your using delay(). This is a function
that should most of the time be avoided for one simple reason: when the
Arduino is executing the delay() instruction, it does nothing but
wait. This means, among other things, that it cannot be reactive to user
input. As outlined by ARK in his answer, interrupts could be used to
overcome this problem. But you actually do not need them: the standard
way to avoid delays is to use instead the millis() function to control
timings. This approach is well described in the Blink without
delay Arduino
tutorial.
Here is how you can apply this technique to your alarm() function: In
a nutshell, you can think of delay() to be roughly equivalent to this:
void naiveDelay(uint32_t ms)
{
    uint32_t start = millis();
    while (millis() - start < ms) {
        // do nothing
    }
}

The problem here is the “do nothing” part. You do not want your program
to do nothing, you want it to monitor the “alarm stop” button. So the
simple solution to your problem is to replace delay() by the code
above, and then change it so that it monitors the button instead of
doing nothing. Then you get something like this:
void alarm()
{
    for (int count = 0; count < 5; count++) {

        // start the buzzer
        digitalWrite(buzz, HIGH);

        // first delay
        uint32_t start = millis();
        while (millis() - start < 500) {
            if (digitalRead(alarmStop) == HIGH) {
                digitalWrite(buzz, LOW);  // stop the buzzer
                return;
            }
        }

        // stop the buzzer
        digitalWrite(buzz, LOW);

        // second delay
        start = millis();
        while (millis() - start < 500) {
            if (digitalRead(alarmStop) == HIGH) {
                return;  // buzzer already off
            }
        }
    }
}

Try This One its Simple:
void alarm()
{
  int count = 0;
  while ( digitalRead(alarmStop) && (count++ <5))
  {
    //A
    digitalWrite(buzz, HIGH);
    delay(500);
    digitalWrite(buzz, LOW);
    delay(500);
  }
}

But, There is a logical problem with this Code. Lets say that your code is at point A (metioned in comment) and at same time button is pressed. Now This code above will, still buzz and then stop.
To avoid This try using interrupts. To use interrupts on Arduino I prefer This Library. Download Here. Extract this and inside you will find a folder Named PinChangeInt. Copy This whole folder to your Documents\Arduino\libraries folder. Now, restart Arduino IDE and copy paste this code:
#include <PinChangeInt.h>

int buzz = 3;

bool alarmStatus = false;
#define PIN3 4
void pin3func() {
  digitalWrite(buzz, LOW);
  alarmStatus = true;
}

void setup() {
  pinMode(PIN3, INPUT); digitalWrite(PIN3, HIGH);
  PCintPort::attachInterrupt(PIN3, &pin3func, CHANGE);
}

int count = 0;
void loop() {
  if (count < 5)
  {
    if (!alarmStatus)
    {
      digitalWrite(buzz, HIGH);
    }
    delay(500);
    digitalWrite(buzz, LOW);
    delay(500);
  }
}

Because, of unavailability of hardware, I haven't tested this code. But, I hope It will work.

(On your second piece of code) #define PIN3 4 ? You might want to use a constant rather than a define. If you write PIN31 somewhere it will be replaced with 41. It's also a little weird to define PIN3 to 4. Also, int count = 0 is placed in between functions. Use a static variable (or a global variable placed on the top of your code). Plus I think you broke some logic since the count is never increased. The alarmStatus variable should be volatile since it's used in an interrupt (not sure if that's also on Arduino)?


text:
I want to be able to upload a batch of tweets to a twitter bot to be qued' for tweeting
I have built a twitter bot with my Arduino and an Ethernet shield
right now, the way to make it tweet something is to manually add a phase into the code and upload it to the board for each new tweet,
I would like to create a simple way of scrolling through a queue of phrases and tweeting each consecutive one after a given amount of time (several hours).
the issue I'm seeing is that, the code needs to rerun for each tweet, and I can't figure out what needs to be in what loop. Also the entire thing needs to delay for 3.6e^6(1 hour) milliseconds (the code takes delays in milliseconds) so that I don't spam the feed,
the twitter for this project is @ether_bot.
Code is below:
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>

/*
void speech()
{
  //this is where i would put the que of tweets
}
*/

// the next three lines connect the ethernet shield to the local network and establish a link with the twitter account
byte ip[] = { 192,168,1,104 };
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEU }; //address for the shield
Twitter twitter("2790106893-5ljE7WPyyGe16SqTMEm8CN5gpwDquhGnyjH2TCM");
char msg[] = "hello again, im getting some major work done soon!"; // message to tweet

void setup()
{
  delay(30000);
  Ethernet.begin(mac, ip);  // makes the connection
  Serial.begin(9600); //opens a serial interface similar to the prnt window in bluejay
}

void loop()
{
  Serial.println("connecting ...");

  if (twitter.post(msg))
  {
    int status = twitter.wait();

    if (status == 200)
    {
      Serial.println("OK.");
    }
    else
    {
      Serial.print("failed : code ");  //stuff happens here idk
      Serial.println(status);
    }
  }
  else
  {
    Serial.println("connection failed.");
  }

  do {} while(1);
}

You mention a "queue" of messages; a queue has to be fed somehow: how would it be fed in your situation? If it is static, then it is not really a queue and the problem is rather simple to solve (see @geometrikal answer below).

i would like the next tweet in the queue to be tweeted after a certain amount of time, (say every few hours)

You did not answer my question: is the lsit of tweets in the queue "static", ie known and fixed at compile-time, or is it dynamic, ie it can change at runtime; in the latter cas, how is the queue fed with new tweets?

static. the tweets would be typed in before the compile. i would generate all of them myself and they would all be in the code from the beginning. after the tweets in the queue are all tweeted, then i would type new ones into the code and re-upload

Ok. Then @geometrikal answer fits your question.

First create an array of all the messages:
#define NUM_MESSAGES 3
const char *msg[NUM_MESSAGES] = {
    "This is the first message",
    "This is the second",
    "Third time lucky" };
int msg_num = 0;

Then in the loop, switch between messages and add a delay
void loop()
{
  Serial.println("connecting ...");
  if (twitter.post(*msg[msg_num]))
  {
    int status = twitter.wait();
    if (status == 200)
    {
      Serial.println("OK.");
    }
    else
    {
      Serial.print("failed : code ");  //stuff happens here idk
      Serial.println(status);
    }
  }
  else
  {
    Serial.println("connection failed.");
  }

  //Next message
  msg_num++;
  if (msg_num >= NUM_MESSAGES) msg_num = 0;
  delay(1000*60*60);
}

so i put some stuff together and got this error at this line... im a totatl noob at coding so i dont really know how to make it work,,,,
if (twitter.post(*msg[msg_num]))
sketch_oct06a.ino: In function 'void loop()':
sketch_oct06a:18: error: invalid conversion from 'const char' to 'const char*'
sketch_oct06a:18: error: initializing argument 1 of 'bool Twitter::post(const char*)'

Try removing the * in front of *msg[msg_num]. This now compiles for me but I don't have a WiFi/Ethernet shield to test it.


text:
Arduino power sources
Is it safe to connect a USB input to an Arduino (Nano) at the same time as an external regulated 5V supply to its 5V pin is connected, assuming the supplies have common grounds ? Will (I hope) the external 5V be used so as to not draw too much current out of the USB supply ?

From the Arduino Nano at Arduino.CC:

The Arduino Nano can be powered via the Mini-B USB connection, 6-20V unregulated external power supply (pin 30), or 5V regulated external power supply (pin 27). The power source is automatically selected to the highest voltage source.

Or, take if from the schematic:

OK, I see a section labelled +5V auto selector, with a Schotky diode between +5V and the VUSB rail, I don't understand enough about electronics to see what this does though. I get that if I supply 7V, say, to Vin then the Nano will use that as the 'highest voltage source'. I could perhaps use a variable voltage source fed from the batteries and set it to, say, 5.2V and force the Nano to use that? The reason for all this is that the Nano will be connected to a Raspberry Pi via USB for communicating with the ros system, and the Pi is unable to supply much from its USB ports, it cant run, for example, a WiFi dongle, mouse and keyboard at the same time.


text:
Buying Arduino Parts Different Manufacturers
I'm looking to buy my first arduino kit. However I have a concern.
If my Arduino Mega is bought from one manufacturer, then can I buy shields or other parts from other manufacturers? Are there any incompatibility issues
Thanks!

Of course you can. In just the same way that you can buy a car from one manufacturer and bumper stickers from another.
That's the whole point of the Arduino platform - mix and match to make things -just like LEGO®.

Awesome! Thanks for the prompt reply.
if you do not mind, are there any basic components which are necessary for any project that I can ensure are in the kit I decide to buy

That's a hard question to answer without knowing what you want to do… You might start by taking a look at some of the Arduino starter kits at Adafruit or some of the other vendors. They will give you a good idea of what you could use to get start with some general hacking and experimenting.


text:
multiple connection with ISP Pin at Arduino Micro
Actually I'm not good at English ;-) trying to ask to you. please understand me :)
I needed connect SD card Shield and TFT LCD Screen to Arduino Micro.
successfully finished compile at source code but when i connect MISO together
it doesn't work. only SS pin is connected separate Pin's to Micro
How can i make it work together to Micro..
i've checked each device perfectly work at Micro
Plese Help me!!
Regards and Thanks

So you have determined that they both work properly individually? When it doesn't work, do they both fail to work or only one?

yes. i've perfectly check both work properly.
it doesn't work both.. when i put MISO pin together.

MISO -> MOSI on the other device, as well as the other way around.

Each SPI device must have a separate device/slave select pin. The device must disconnect (high impedance state) when not selected. The SD shield will have a level shifter. It may not correctly disconnect from MISO.
Depending on what libraries you are using you might also need to check that they set the SPI hardware attributes correctly (clock, mode, etc).
For more help please post code and references to the shields and libraries.
Cheers!

i did it. you means do like 'digitalWrite(lcdCS,HIGH)' when i use SD Card Shield right?.. i don't know my code is wrong or not
i wonder is this possible to work at the same time two SPI device in Micro??

That is correct but you also need to check that the SD Card Shield does not drive the SPI MISO pin due to level shifter (such as resistors). The same goes for the LCD. It is possible; here is an example sketch, CosaCanvasBMP that loads a BMP file from SD and displays it on a ST7735.


text:
How can one use the SPI hardware on the Arduino Nano?
I recently prototyped and programmed a system that used some SPI sensors on an Arduino Uno. I wanted to get the size down a bit, so I was thinking I might buy an Arduino Nano and re-wire my system around that. The problem is that I have seen mention of SPI not working on the Nano. From the Nano product page:

These pins support SPI communication, which, although provided by the underlying hardware, is not currently included in the Arduino language.

Yet I have also seen mention of SPI working on this board, or at least people saying that it should. Someone asked a similar question on Stack Overflow and was told that it should work with the same level of support as I2C, even if it isn't built in to the core framework. But that answer does not definitively answer the question of whether SPI does work, and it doesn't explain any caveats that one may come across. In this question, the OP's premise is that their SPI device works on the Nano but not on other boards; this seems to be a strong indication that SPI does work.
I figured it would be worth it to buy a Nano 3 and see if it worked. SPI devices did not work on that board, including the same radio module mentioned in the question linked to above. So, I am inclined to believe the Arduino product page when they say it isn't supported. But that still isn't satisfactory, and it is the opposite conclusion from that of the other questions: The hardware is all there and the software framework is in place, so what does one need to do to make SPI work on the Arduino Nano? Why is it that some sources say it works while others say it doesn't?

Don't always trust the arduino website. It's very outdated and often incorrect. You could try compiling some example code that uses SPI. If it compiles, the statement from the arduino site would be incorrect.

You can always connect your logic analyser or oscilloscope to the SPI pins and actually look at what is happening on the pins... You do have the basic test tools you need to do electronics, don't you? https://hackingmajenkoblog.wordpress.com/2016/03/23/top-6-things-every-engineer-needs/

@Gerben Although I did not try to run one of their samples, I did run my own code (the same code that works on the Uno) and double-checked the wiring. While the compile and build were fine, the SPI device did not respond with any data, nor could I see any other sign that it was working.

I thought this was a purely theoretical question. Showing your wiring and your code would be helpful.

@Gerben I am asking it theoretically, having been prompted (as mentioned) by seeing a certain behavior in reality. I would like to keep this question away from my specific test and focus on the theoretical situation: Does the Nano support SPI, and is there anything that must be done differently on the Nano to use it? If the answer is that it does support SPI out-of-the-box, I will then investigate on my own why I was unable to get it to work.

I am having the same problem - a code for Uno, which compiles fine for Nano, but does not work. One thing to notice is that MISO and MOSI pins are switched between Uno and Nano, but that's not all. The crystal frequency of Uno is 16MHz, while Nano is at 12MHz. I wonder if this means some constants need to be changed in SPI.h.

Yes, the Nano supports SPI when used with a modern Arduino version, and no, you do not have to do anything special to utilize it on this board.
The information you found that seems to suggest something to the contrary is simply a result of the fact that that the web page for the Nano is sadly out of date date and does not reflect the current state of the Arduino libraries which support SPI on this processor and hence board.
In terms of components, the Nano it is very nearly just a form-factor shrink of the discontinued Duemilanove, and in the current version updated to an an ATmega328p it has capabilities essentially comparable to an Uno, differing primarily the in the USB interface which has nothing to do with SPI.
In terms of what is wrong with the web page, if we examine archive.org's records for the page of the comparable Duemilanvoe, on September 15th, 2010 it said:

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication, which, although provided by the underlying hardware, is not currently included in the Arduino language.

But a few days later on September 26th, 2010 it had been changed to say:

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library.

Although the page for that once-flagship product was updated to reflect SPI support nearly six years ago, they've not yet made a corresponding correction to the Nano page.  But as the difference is in the software and the same software is used in either case, the addition of SPI support to the Duemilanove was also automatically an addition of that support to the Nano.

In this Nano schematic, I see MOSI, MISO & SCLK on pins J1-14, J1-15 & J2-15.
On this page I see a SPI library.
The Nano is not specifically listed in the latter link.  However the Nano and other Arduino boards are similar.

The Nano is just a smaller version of the Leonardo.

Sorry. I was thinking of the Arduino MICRO.


text:
How does one design for the power on transient conditions?
Following on from the question Reset an Arduino UNO by an command (software) and the excellent answer provided by mpflaga, the comment addressing option (1) suggests that there are design considerations for connecting an output pin to the RESET pin.

Option 1. or a variant can be a clean enough way to do this as long as
  power on transient conditions are designed for.
  - Russell McMahon

or more ominuously

From everything I've read, the first option is not recommended. - sachleen

Could someone tell me exactly what those considerations are? Is it that it is not as simple as connecting the two with a jumper cable - is additional circuitry (i.e. an RC timer) required, or is there a software solution?
I find the latter option unlikely as the device is rebooting, so unless the software fix is to ignore hardware interrupts (since a RESET is simply that, and the state of the output pins is unlikely to be known, or stable at reboot) for a few mS after reboot, I presume that a hardware fix is required.

An external driver, such as a simple monostable circuit (555 timer, if a little inelegant) could be constructed to pull the reset pin low for the right amount of time when triggered by the uC. However, you are far better off with Nick Gammon's software-only solution.

Atmel specifically recommend against driving /RESET low from an output pin, because the first thing that the reset process does is set all pins to high impedance, thus cancelling the reset pulse before the recommended reset pulse length has elapsed.
The recommended use of the watchdog timer does not suffer from these limitations. It is designed to reset the board (or there would be no purpose to having it) and it does a proper reset (unlike jumping to address 0x0000).

Reference
Atmel knowledge base - Software Reset

If you want to perform a software reset of your AVR you should use the internal Watchdog. Simply enable it and let it time out. When the Watchdog triggers it resets the program counter back to 0, clears all the registers and performs all the other tasks. This operation gives the same result as pulling the RESET line low.
You should not try to:

Use another pin of the AVR to pull the external RESET line. The pins of the AVR are tristated halfway through the minimum reset time, this releases the RESET line and hence nothing happens.
Jump to program location 0. Jumping to program location 0 does not clear all the registers and hence you do not have a "clean" reset.

Their suggested code to reset the processor:
#include <avr/io.h>
#include <avr/wdt.h>

#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {}

int main(void)
{
Reset_AVR();
}


text:
Allocate object memory statically; intialize it dynamically?
I have an object whose constructor gets passed a parameter. If I know the parameter value at compile time, I can construct the object statically:
static FOOOBJ foo(3);
(I understand that it isn't really done statically, i.e. by the compiler, but is actually done during setup).
But if I don't know the parameter value at compile time, I'd still like to pre-allocate space for the object but construct the object in that space at run time. Can it be done without a separate .initialize() method?

Using an initialize() method to a class is contrary to the principle of a class constructor, i.e. once a class instance has been constructed, it should be "ready to use".
As suggested by Ignacio's answer, C++ placement syntax is much better for your purpose.
However, with Arduino libraries, placement syntax is not supported "out of the box", so you  have to implement it yourself; don't fear, that is quite straightforward:
void* operator new(size_t size, void* ptr)
{
    return ptr;
}

Placement syntax can be a complex beast in C++, but for your specific purpose, its usage can be rather simple:
static char buffer[sizeof FOOOBJ];
static FOOOBJ* foo;

void setup() {
    ...
    foo = new (buffer) FOOOBJ(3);
    ...
}

The difference with your current code is that foo is now a pointer, hence any method call will use -> instead of ..
If you absolutely want to keep using foo as an instance and not a pointer, then you can do it (but I don't advise it as explained later) by using a reference instead:
static char buffer[sizeof FOOOBJ];
static FOOOBJ& foo = *((FOOOBJ*) buffer);

void setup() {
    ...
    new (buffer) FOOOBJ(3);
    ...
}

The problem with this code, is that you cannot know if foo has already been constructed with a real FOOOBJ instance or not; using a pointer, you can always check if it is 0 or not.
Using placement syntax, you must be aware that you cannot delete the foo instance above. If you want to destroy foo (i.e. ensure that its destructor is called), then you have to explicitly call the destructor:
foo->~FOOOBJ();

I wasn't aware of the syntax but that makes total sense! Does the constructor need to be aware of / designed for it? FOOOBJ is a OneWire object, using Jim Studt's library (v2.2). I'm getting the message error: no matching function for call to 'operator new(unsigned int, byte [14])' on the new call. It looks like avr-g++ may not understand the syntax.

Yes, you're right, I'm using Eclipse for my Arduino projects and what I checked it, it seemed to work, except that what worked was Eclipse C++ compilation, not avr-g++! I have edited my answer to show a simple workaround.

Regarding your question on constructor, ther is no specific requirement, but if the constructor itself performs dynamic allocation, then placement new will not prevent it.

I'm also using Eclipse - what C++ compiler is yours configured with? Plus looking at the OneWire constructor, it doesn't new anything, it just initializes some i/o.

I'm using Eclipse with http://eclipse.baeyens.it/ plugin (which uses Arduino IDE tools, ie avr-g++ + Arduino libs); but the C++ compilation occurs on-the-fly with Eclipse C++, and uses avr-g++ only when launching the Arduino build. I had not checked the latter step initially.

This is clearly the right approach. That  my current tools don't support it directly is unfortunate but it points me in the direction I need to go. Thanks for the help.

You can use placement syntax to specify an existing allocation in which to instantiate the class.
FOOOBJ foo(0);

 ...

  FOOOBJ *f = new (foo) FOOOBJ(3);

I'd suggest to replace the declaration of foo with char foo[sizeof FOOOBJ]; so that FOOOBJ constructor does not get called for foo which could be a real problem depending on what the constructor does.


text:
Car dome light fading with arduino nano
So I'm working on my car and now I've got my sights on the electrical system. I've installed a keyless entry system and a pulse timer for the dome light. Now, I'd like to give the dome light the fade effect all the modern cars have. After looking around, it seems an Arduino would be the most reliable.
I currently own an board similar to the Arduino Nano, specifically the SainSmart Nano. So I've determined that I'd power the board with a constant 12V, use pin 7 as input, and use pin 9 as output.
My code:
int domeLightIn = 7;
int domeLightOut = 9;
int brightness = 0;
int fadeAmount = 5;

void setup() {
  pinMode(domeLightOut, OUTPUT);
  pinMode(domeLightIn, INPUT);
  digitalRead(domeLightIn);

}

void loop() {
  // Case 1: State of Door: Open/Closed
  // Case 2: State of Switch: On/Off
  // Case 3: State of KES: Active/Inactive

  //Case 1: If door is closed and led is off, brightness remains 0;
  //Case 2: If switch is off and led is off, brightness remains 0;
  //Case 3: If KES is inactive and led is off, brightness remains 0;
  if (digitalRead(domeLightIn) == LOW && brightness != 255){
    brightness = 0;
  }

  //Case 1: If door is open and led is off, brightness will fade in;
  //Case 2: If switch is on and led is off, brightness will fade in;
  //Case 3: If KES is active and led is off, brightness will fade in;
  if (digitalRead(domeLightIn) == HIGH && brightness != 255) {
    for (brightness = 0; brightness < 255; brightness = brightness + fadeAmount) {
      analogWrite(domeLightOut, brightness);
      delay(35);
    }
  }

  //Case 1: If door is closed and led is on, brightness will fade out;
  //Case 2: If switch is off and led is on, brightness will fade out;
  //Case 3: If KES is inactive and led is on, brightness will fade out;
  if (digitalRead(domeLightIn) == LOW && brightness == 255) {
    for (brightness = 255; brightness > 0; brightness = brightness - fadeAmount) {
      analogWrite(domeLightOut, brightness);
      delay (35);
    }
  }
}

I am unsure whether I am using digitalRead() correctly along with wiring the input. So, am I doing this right? or perhaps there is a better way?

Any particular reason why you don't want to use a capacitor and resistor instead?

Flexibility. I didn't mention this, but I'm also installing footwell lights, perhaps even more accessories. Eventually I'll try different things with it. I'd like to give each a fade effect, but if I can't do it with the arduino, then I'll fall back to capacitors and resistors.

Did you've added a PULLUP resistor on the input?

You're not using digitalWrite properly. You should do:
if (digitalRead(domeLightIn) == LOW && brightness != 255){

Just a sidequestion. What is pin7 connected to? If it's a 12v signal, you'd have to convert it down to 5v somehow.
Also, the 12v in the car can be up-to 14v, and can have some huge spikes. Not sure if the sainsmart's regulator can handle those spikes. It might die prematurely. It's also just wasting 60% (generating heat!), turning 12v to 5v. I would suggest adding one of those cheap car-phone-chargers.

Thanks. And Pin 7 is supposed to be the input signal wire. Messed that up in my code. And I was thinking more along the lines of wiring up a voltage divider to change the input voltage to somewhere between 7V and 12V

A voltage divider means wasting power twice.

If I want to power the board, wasting power is inevitable. My car's accessory wire isn't always on. The only wires that I believe are constantly hot are the 12V constants, dash and headlights, and dome light.

A voltage divider will work. It would only wast a few milli amps, if you use high enough resistors, so not an issue. Not sure what you meant by "between 7V and 12V". Maximum input voltage is 5.5V. So try to get a voltage between 3v (minimal) and 5v, when providing a signal voltage between 12v and 14v.

Ah my bad. The 7V to 12V was meant for the wire powering the board.

You should consider bringing the voltage down to 5v thats very important, when a car is running as stated above the voltage will increase because the battery is no longer running the electronics, the alternator powers everything and charges the battery.
Instead of trying to control this strait from the Arduino, use a transistor such as the TIP 120 darlington in order to control the existing light or you can put in a new one if you want.  This gives you the ability to add more powerful lights or add more lights to the circuit, which the Arduino would not be able to power via pwm.


text:
Multiplexing potentiometers
Is it possible to have two rotary potentiometers read from a single analog input pin?
The analog input is 10 bits (0-1023), so each pot would have 5 bit precision (0-15).
Least significant bits for pot 1 and most significant bits for pot 2.
A SPI/I2C ADC IC (eg. MCP3008) is an option if this is not possible.
Edit:
The two pots do not need to be read at the same time.
It seems full 10 bit precision could be achieved if I use a digital pin to enable each pot before it is read.

There are a few ways of doing what you want.  One would be to use an analog multiplexer as in this answer: Expanding analog inputs to the Arduino
Another would be to use digital I/O pins to control the power and ground to the potentiometers.  Note that both sides of the pot need to be controlled, not just one, since any connection of one will interfere with the other.
So you will need four IO pins - one for the +5v and one for the GND of each potentiometer.

In this example set D3 to OUTPUT and HIGH, D4 to OUTPUT and LOW, and D5 and D6 both to INPUT.  You will now be reading from the top pot.
Then change D3 and D4 to both be INPUT, and D5 to be OUTPUT and HIGH and D6 to be OUTPUT and LOW.  You will then be reading from the bottom pot.
A bit wasteful of IO pins though.

This is great, and I don't think it's really wasteful of IO pins when you consider that the alternative is adding in a multiplexer which is a bit overkill for cases like this.

Building on @Majenko's answer, I think you could do the same thing, using 1 analog pin (as shown in his answer) and one digital pin.
Rather than using one digital pin for each side of the each pot, you could use one transistor for each side of each pot, and then use one digital pin to switch all 4 transistors on/off at the same time, in the right combination.

It could be done, yes. It's a choice between lots of components or lots of IO pins. If you're going in the lots of components direction you may as well go for an analog MUX and get lots more channels to play with anyway.


text:
LCD Display Flicker When Arduino Main Board Supply Voltage to GSM Shield Board
I have a 16x2 LCD display that is connected to an Arduino microcontroller.
It is working fine but the LCD display flickers when I connect the Vin and GND of the main board to its slave GSM Shield.
I used main board Vin and GND to power up the GSM Shield so I only have one power supply. I was able to power up GSM Shield by adding jumper to Vin and GSM +Vin.
In additional question, is there any other way to power up Arduino GSM Shield without connecting it to another power source to still keep having only one plug for power?

What Arduino model?  What's the supply you attached to Vin, what's it's nominal voltage, and what voltage do you measure when it's attached?  What model GSM board?  Why hook GSM to Vin instead of +5?

GSM is notorious for very high pulse power demand when transmitting, which can easily cause a supply brownout.  Capacitor solutions are possible, but some have resorted to using a battery to power the radio.

This sounds like either your GSM Shield is drawing to much power (from time to time) and thus your Vin drops resulting in flickering or your GSM Shield induces ripple on top of your Vin.
To debug this I would recommed to have a look at Vin with an oscilloscope and see how stable Vin is. Additionally some capacitors between Vin and GND (100nF and 10-100µF) and a ferrit between Vin and the GSM Shields Vin might help.


text:
Printing SD card file contents on LCD

This is a part of my program which reads data from file stored in SD card and displays that on an LCD screen.
  File dataFile = SD.open("1165.txt");

  if (dataFile) {
    Serial.println("File Opened");
    lcd.clear();
       delay( 5 );  //LCD-specific M
       lcd.setCursor( 0,0 );

  while (dataFile.available()) {
      Serial.write(dataFile.read());
      lcd.write(dataFile.read());
      lcd.print(dataFile.read());
    }
  dataFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error");
  }

When I look at the serial monitor it prints the contents of that file but none of these commands print what is printed in the serial monitor,
lcd.write(dataFile.read());
lcd.print(dataFile.read());

Any ideas?

When you call dataFile.read(), the file pointer is advanced, so you always read different bytes in each read call. Imagine the file like a book with many lines: Each time you read, you advance the current line, so with multiple calls, you never get the same data. The solution is to currently store the last read byte:
while (dataFile.available()) {
  char readByte = dataFile.read();
  Serial.write(readByte);
  lcd.write(readByte);
  lcd.print(readByte);
}

You have two calls for displaying data in the LCD, but be careful that the second call (print) might interpret your data as a number, so just remove the lcd.print(readByte) call altogether to be sure it's printing the raw character.

You could also implement a readLine routine, similar to:
void _readLine(File f, char *line)
{
    boolean cr_found = false;
    int p = 0;
    while (f.available()) {
        char b = f.read();
        if(b!='\r' && b!='\n')
            line[p++] = b;

        if(b == '\r') cr_found = true;
        if((b == '\n') && cr_found) break;
    }
    line[p] = '\0';
}

And read the SD file line by line, processing each one of them by its own.
char buffer[32];

while(dataFile.available()) {
    _readLine(dataFile, buffer);
    // do something with buffer
}


text:
Anyone using ModBus RTU on Galileo gen 2?
I'm trying to communicate with some industrial hardware, on ModBusRTU, from my Intel Galileo Gen2 board. I use this board to convert UART to RS485 http://linksprite.com/wiki/index.php5?title=RS485_Shield_V2.1_for_Arduino and I can talk serially between Arduino (with SoftwareSerial on pin 2/3) and Galileo (with Serial1 on pin 0/1). So I know the RS485's link is working.
With Arduino Uno I can talk with my devices using ModBusRTU, thanks to this library https://github.com/4-20ma/ModbusMaster
On galileo gen2 I received this warning WARNING: library ModbusMaster claims to run on [avr, sam] architecture(s) and may be incompatible with your current board which runs on [i586] architecture(s). because of the different architecture.
Now I'm trying to use the examples of cooking hack's tutorial about modbus and rs485 for Arduino, Raspberry and Galileo but I can't make it works for me. I received tons of compiling errors like these:
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp: In member function 'uint8_t ModbusMaster485::ModbusMasterTransaction(uint8_t)': C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:701:50: error: '_crc16_update' was not declared in this scope
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:814:52: error: '_crc16_update' was not declared in this scope
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp: At global scope:
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:881:14: error: prototype for 'unsigned int ModbusMaster485::makeWord(unsigned int)' does not match any in class 'ModbusMaster485'
In file included from C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:25:0: C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:302:11: error: candidates are: uint16_t ModbusMaster485::makeWord(uint8_t, uint8_t)
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:301:14: error: uint16_t ModbusMaster485::makeWord(uint16_t) C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:887:14: error: prototype for 'unsigned int ModbusMaster485::makeWord(uint8_t, uint8_t)' does not match any in class 'ModbusMaster485'
In file included from C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:25:0: C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:302:11: error: candidates are: uint16_t ModbusMaster485::makeWord(uint8_t, uint8_t) C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:301:14: error: uint16_t ModbusMaster485::makeWord(uint16_t) Error compiling.

Did someone has got ModBus working on Galileo Gen2?


text:
How do I program the Arduino Primo Core using the Arduino Primo?
the Arduino Primo Core website (https://store.arduino.cc/usa/arduino-primo-core) says that I can program the Arduino Primo Core using an Arduino Primo.
I have no idea how to do this!
Can you do it through the Arduino IDE? Which pins on the Arduino Primo Core should I connect to which pins on the Arduino Primo?
Thanks for your help!

instructions were on arduino.org. it is turned off now, but you can find them in Web Archive (without downloads)
Arduino.org pages in web archive

Juraj's answer answered my question, however I've gone back since and found the link to be broken. Fortunately I saved the file so I'll summarise here for others:

Download the nRF52 platform using the Boards Manager:

Connect the Arduino Primo Core to the Arduino Primo using a SWD connector (J2 on Arduino Primo Core and J9 on the Arduino Primo):

Plug the Arduino Primo into the PC using a USB data cable.
Select "Arduino Primo Core" from the Tools > Board menu:

Select the corresponding port of the Arduino Primo from the Tools > Port menu:

Select the Blink sketch from the File > Examples > 1. Basics menu.
Upload the sketch. If the light blinks on the Arduino Primo Core it has worked!


text:
How do I calculate sampling rate of external ADC?
I am wondering if someone could explain this to me.
I want to calculate sampling rate of external ADC.
I am using ADS8320 which has max sampling rate of 100kHz, with Arduino MEGA 2560.
SPI divider is set to 128, which makes SPI frequency 125kHz.
Baud rate is 115200 (I am not sure if this is important).
Thanks a lot!

To get an idea of the sampling rate write a loop that takes 10,000 measurements and time how long it takes. You have your sample rate, not perfect but gives you some idea.
long start = millis();
// the loop

Serial.print( 10000000/(millis() - start) );
Serial.println(" samples per second");

Easy.

Based on your set up, figure out the spi speed.
Take a look at the adc datasheet, figure out it's frame of transmission . Aka how many pulses per frame / sampling.
The product of the numbers in 1 and 2 gives you the minimum time per frame. The inverse of it is the maximum transmission in your application. That speed is cap by the devices own max sampling rate (100ksps).
Your actual sampling rate will depend on your specific application but it should not go above the number obtained in 3.
You may need to factor in other timing requirements as well so read the datasheet carefully. But the gist is the same.


text:
Help reading a 125khz FSK RFID
Reddit doesn't seem to be much help, so I'm posting here as well.
I'm try to read (what I think is) an HID Duoprox II 125kHz FSK RFID and am having a bit of trouble. I'm using an Arduino nano and am copying the code from the Arduino Playground. The changes I've made to the code are adjusting the frequency to 125kHz, changing debug to true, and reducing maxBuf to 100. I believe I also have to change val = digitalRead(inPin); to val = !digitalRead(inPin);, and I made grnLED turn on before "got buf num: " is sent, and turn off after. Rather than build the circuit shown, I bought an Rdm6300, reverse engineered the front end, and disconnected the back end from it, letting me use the Arduino as the back end instead.
As far as hardware goes, the reader seems to be working properly. The coil has a nice sine wave on it, and the output of the circuit seems to be a proper FSK data stream . (I scoped LedPin, 13, which is outputted by the Arduino after it has recieved the signal on pin 7.)
For some reason, the Arduino is not sending anything back to the computer. I'm fairly certain that this is somehow a software issue, despite me copying the code from the Arduino website. The TX LED does not light up at all. Even if the data being sent to the Arduino were corrupted, it should still send "got buf num: " every 100 changes of the input signal. (grnLED does turn on for 37.4ms, but no serial data is sent, and the pin never turns on again.)
What's going on? Why doesn't the Arduino send anything back to the computer?
Full code:
#include "TimerOne.h"

int ledPin = 13; // LED connected to digital pin 13
int inPin = 7;   // sensing digital pin 7
int val;
int bitlenctr = 0;
int curState = 0;

#define maxBuf 100 //reduce to 100 or so for debugging
#define debug  true

char raw[maxBuf];

int index = 0;
int bufnum = 0;
#define   redLED 12
#define   grnLED 11

void setup()
{
  Serial.begin(9600);
  Timer1.initialize(8);  // initialize timer1, and set the frequency; this drives both the LC tank as well as the pulse timing clock
  // note: modify this as needed to achieve resonance and good match with the desired tags
  // the argument value is in microseconds per RF cycle, so 8us will yield RF of 125kHz, 7us --> 143kHz, etc.

  Timer1.pwm(9, 512);           // setup pwm on pin 9, 50% duty cycle
  Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt, once per RF cycle

  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output for scope monitoring
  pinMode(inPin, INPUT);      // sets the digital pin 7 as input to sense receiver input signal
  pinMode(grnLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(grnLED, 0);
  digitalWrite(redLED, 1);
}

void callback()
{
  val = !digitalRead(inPin);
  digitalWrite(ledPin, val); // for monitoring
  bitlenctr++;
  if(val != curState) {
    // got a transition
    curState = val;
    if(val == 1) {
      // got a start of cycle (low to high transition)
      if(index < maxBuf) {
        raw[index++] = bitlenctr;
      }
      bitlenctr = 1;
    }
  }
}

void loop()
{
  if(index >= maxBuf) {
    digitalWrite(grnLED, 1);
    Serial.print("got buf num: ");
    Serial.println(bufnum);
    digitalWrite(grnLED, 0);

    if(debug) {
      for(int i = 0; i < maxBuf;
      i++) {
          Serial.print((int)raw[i]);
        Serial.print("/");
      }
      Serial.println("///raw data");
      delay(2000);
    }

    // analyze this buffer
    // first convert pulse durations into raw bits
    int tot1 = 0;
    int tot0 = 0;
    int tote = 0;
    int totp = 0;
    raw[0] = 0;
    for(int i = 1; i < maxBuf; i++) {
      int v = raw[i];
      if(v == 4) {
        raw[i] = 0;
        tot0++;
      }
      else if(v == 5) {
        raw[i] = raw[i - 1];
        totp++;
      }
      else if(v == 6 || v == 7) {
        raw[i] = 1;
        tot1++;
      }
      else {
        raw[i] = 101; // error code
        tote++;
      }
    }

    // next, search for a "start tag" of 15 high bits in a row
    int samecnt = 0;
    int start = -1;
    int lastv = 0;
    for(int i = 0; i < maxBuf; i++) {
      if(raw[i] == lastv) {
        // inside one same bit pattern, keep scanning
        samecnt++;
      }
      else {
        // got new bit pattern
        if(samecnt >= 15 && lastv == 1) {
          // got a start tag prefix, record index and exit
          start = i;
          break;
        }
        // either group of 0s, or fewer than 15 1s, so not a valid tag, keep scanning
        samecnt = 1;
        lastv = raw[i];
      }
    }

    // if a valid prefix tag was found, process the buffer
    if(start > 0 && start < (maxBuf - 5*90)) { //adjust to allow room for full dataset past start point
      process_buf(start);
    }
    else {
      Serial.println("no valid data found in buffer");
    }
    if(debug) {
      for(int i = 0; i < maxBuf;
        i++) {
          Serial.print((int)raw[i]);
        Serial.print("/");
      }
      Serial.print("///\nbuffer stats: zeroes:");
      Serial.print(tot0);
      Serial.print("/ones:");
      Serial.print(tot1);
      Serial.print("/prevs:");
      Serial.print(totp);
      Serial.print("/errs:");
      Serial.println(tote);
      delay(1000);
    }

    // start new buffer, reset all parameters
    bufnum++;
    curState = 0;
    index = 0;
  }
  else {
    delay(5);
  }
}

// process an input buffer with a valid start tag
// start argument is index to first 0 bit past prefix tag of 15+ ones
void process_buf(int start) {
  // first convert multi bit codes (11111100000...) into manchester bit codes
  int lastv = 0;
  int samecnt = 0;
  char manch[91];
  char final[45];
  int manchindex = 0;

  Serial.println("got a valid prefix, processing data buffer...");
  for(int i = start + 1; i < maxBuf && manchindex < 90; i++) {
    if(raw[i] == lastv) {
      samecnt++;
    }
    else {
      // got a new bit value, process the last group
      if(samecnt >= 3 && samecnt <= 8) {
        manch[manchindex++] = lastv;
      }
      else if(samecnt >= 9 && samecnt <= 14) {
        // assume a double bit, so record as two separate bits
        manch[manchindex++] = lastv;
        manch[manchindex++] = lastv;
      }
      else if(samecnt >= 15 && lastv == 0) {
        Serial.println("got end tag");
        // got an end tag, exit
        break;
      }
      else {
        // last bit group was either too long or too short
        Serial.print("****got bad bit pattern in buffer, count: ");
        Serial.print(samecnt);
        Serial.print(", value: ");
        Serial.println(lastv);
        err_flash(3);
        return;
      }
      samecnt = 1;
      lastv = raw[i];
    } //new bit pattern
  }

  Serial.println("converting manchester code to binary...");
  // got manchester version, convert to final bits
  for(int i = 0, findex = 0; i < 90; i += 2, findex++) {
    if(manch[i] == 1 && manch[i+1] == 0) {
      final[findex] = 1;
    }
    else if(manch[i] == 0 && manch[i+1] == 1) {
      final[findex] = 0;
    }
    else {
      // invalid manchester code, exit
      Serial.println("****got invalid manchester code");
      err_flash(3);
      return;
    }
  }

  // convert bits 28 thru 28+16 into a 16 bit integer
  int code = 0;
  int par = 0;
  for(int i = 28, k = 15; i < 28+16; i++, k--) {
    code |= (int)final[i] << k;
  }
  int paritybit = final[28+16];
  for(int i = 0; i < 45; i++) {
    par ^= final[i];
  }

  if(par) {
    Serial.print("got valid code: ");
    Serial.println((unsigned int)code);
    // do something here with the detected code...
    //
    //
    digitalWrite(redLED, 0);
    digitalWrite(grnLED, 1);
    delay(2000);
    digitalWrite(grnLED, 0);
    digitalWrite(redLED, 1);
  }
  else {
    Serial.println("****parity error for retrieved code");
    err_flash(3);
  }
}

// flash red for duration seconds
void err_flash(int duration) {
  return;
  for(int i = 0; i < duration*10; i++) {
    digitalWrite(redLED, 0);
    delay(50);
    digitalWrite(redLED, 1);
    delay(50);
  }
}

EDIT:
Even the following code doesn't work! All I receive is "St"! Increasing the PWM period does fix this.
#include "TimerOne.h"
int val = 0;
int inPin = 7;

void setup(){
  Serial.begin(9600);
  Serial.print("Starting!!");
  Timer1.initialize(8);
  Timer1.pwm(9, 512);
  Timer1.attachInterrupt(callback);
  pinMode(inPin, INPUT);
  }

void callback(){
  val = digitalRead(inPin);}

void loop(){
  Serial.println("hi!");}

If you invert what you read from pin 7, you should at least invert the initial and later settings of curState too as well as the if(val == 1) ....

The only reason I'm inverting what I'm reading from pin 7 is because the circuit I'm using inverts the signal compared to the circuit on the Arduino website (I think.) The program should send debug information either way.

Have you tried using different serial baud rates? Just a stab in the dark...

Did you figure this out? It looks like it's printing the first 2 letters of "Starting".  Adding a delay between your print and Timer1.initialize printed the rest of it.


text:
High frequency audio sampling and storage
I want to use an arduino duemilanove atmega168 for audio signal processing. I can sample the signal at around 38.5kHz using this code. I want to send the sampled data over the serial to a computer for processing.

Data acquisition rate: 38.5 kbps (using 8-bit precision)
Maximum serial communication rate: 115200 bps (I don't know exactly how this relates to the transfer rate of the actual data (without any overheads), but anyhow the limit is 13.94 kbps)
Arduino flash memory: 16 kB

I would like to transmit around 4-5 seconds of the audio signal to the computer. Is there a way to achieve this?

So I think this is going to very hard since the serial communication limit is based on the underlying atmega168 and there isn't really another hardware based communication system. I poked around and apparently people have made hardware serial run at 1Mbps, this seems rather difficult though check here for some more details http://arduino.stackexchange.com/questions/4071/serial-begin-why-not-always-use-28800?rq=1.

After doing some reading here Serial.begin(): Why not always use 28800? and looking at the manual for the 168. You should be able to achieve the baud rate you want by directly programming the USAR.
According to the answer there you should be able to use miniterm to keep up with a high baud rate.
As stated there you might run into problems with computer power.
Read chapter 20 here http://www.atmel.com/images/doc2545.pdf.
Basically you can set up the USART speed (UDR0) and the control registers (UCSR0A,UCSR0B and UCSR0C) such that you can send data pretty fast.
Let me know if you can't access that link and if you need me to explain some more about these things.


text:
How can I pass an object as a parameter to a function?
I am making a tiny game, and want to store high-scores. I made a Highscore-class in the top of the sketch file, like this:
class Highscore {
public:
  String name;
  int score;

  String toString() {
    return this->name + " - " + (String)score;
  }

  Highscore(String name, int score) {
    this->name = name;
    this->score = score;
  }
};

setup() { // etc

Now. Near the bottom of the sketch, I have a function I want to take a Highscore-object as a parameter, but the compiler will not let me. Example:
void writeHighscore(Highscore hs) {
  File f = SD.open("high.txt", FILE_WRITE);
  // Do stuff

The complation error is as follows:

sketch.ino:19:21: error: variable or field ‘writeHighscore’ declared void
  sketch.ino:19:21: error: ‘Highscore’ was not declared in this scope
  sketch.ino: In function ‘void setup()’:
  sketch.ino:64:20: error: ‘writeHighscore’ was not declared in this scope

After changing parameter type to String, int or whatever, all the errors go away. I am able to create Highscore-objects INSIDE the writeHighscore() function, but how can I pass objects to it?
Edit 1 - Object creation
Highscore hs = Highscore("John", 975);
Serial.println(hs.toString()); // Prints "John - 975" as expected
writeHighscore(hs); // Error

can you please post the code where you create Highscore object?

Included the object creation code.

I think the problem is some missing bracket or so. Because there is no full code, I can guess and see: 1)  setup() should be void setup(). But it should generate C++ warning/error. 2) Passing class parameter forces object copy when procedure is called. gcc should also generate a warning if copy constructor is missing. Use:
void writeHighscore(Highscore &hs)
or
void writeHighscore(Highscore *hs)
Copy compilable snipet in your post.

Like stated in the original question, by changing the Highscore-parameter by, say, a String or an int, the errors go away, there are no missing brackets. I've also tried the &hs approach beforee writing the post, as well as passing the pointer writeHighscore(&hs) -> void writeHighscore(Highscore *hs) but to no avail.

Please post the full source code, otherwise the line numbers in compilation errors are pointless.

You are doing everything right, but you need to move the class outside of your .ino file for this to work.  I'm not sure why the arduino IDE makes you do this  (see edit) , but it is something I've run into before.
I just tested this, and moving the class declaration outside the ino and into a header file in the project folder makes it compile correctly. Just remember to include the header you make in the ino and to #include "Arduino.h" in the header to get access to "String" again.
Technically, only a forward declaration of the class needs to be in a different file.
Edit:
I'm relatively sure what is happening is the IDE is generating forward declarations for all your functions but not the class, which are placed before your class definition.
This means that breaking the function regex the IDE uses with a dummy "throw()" fixes your problem. for example:
void writeHighscore(Highscore hs) throw() { ...

should work just fine (it worked for me)

This is a classic example of the IDE "helping" you by generating function prototypes, and not doing it very well. Example code to reproduce:
class Highscore {
public:
  String name;
  int score;
  String toString() {
    return this->name + " - " + (String)score;
  }

  Highscore(String name, int score) {
    this->name = name;
    this->score = score;
  }
};

void setup () { }
void loop () { }

void writeHighscore(Highscore hs)
{
// do stuff
}

This gives the error:
sketch_jul06b:4: error: variable or field ‘writeHighscore’ declared void
sketch_jul06b:4: error: ‘Highscore’ was not declared in this scope

If you look at the output of the IDE preprocessor (you can do this by turning on verbose compilation, and finding out the name of the file it is actually compiling) you see this:
#line 1 "sketch_jul06b.ino"
#include "Arduino.h"
void setup ();
void loop ();
void writeHighscore(Highscore hs);
#line 1
class Highscore {
public:
  String name;
  int score;
  String toString() {
    return this->name + " - " + (String)score;
  }

  Highscore(String name, int score) {
    this->name = name;
    this->score = score;
  }
};

void setup () { }
void loop () { }

void writeHighscore(Highscore hs)
{
// do stuff
}

The important part is that it put:
void writeHighscore(Highscore hs);

before where the class is declared.

You can fix the error by simply generating your own function prototype like this:
void writeHighscore(Highscore hs);  // function prototype
void writeHighscore(Highscore hs)
{
// do stuff
}

Now it compiles without errors. It detects your own function prototype, and therefore does not generate its own. The first few lines of the generated file are now:
#line 1 "sketch_jul06b.ino"
#include "Arduino.h"
void setup ();
void loop ();
#line 1

That troubling prototype has gone.