text:
Adding button which resets to top of void
I'm quite new to Arduino and the programming of the board, but I wanted to have a go at making a traffic light based on an example I found online.
The example supplied a simple layout which I roughly copied with the components I had.

I then created the following code to mimic the traffic lights of my local area.
int red = 13;   int yellow = 12;   int green = 11;

void setup(){
    pinMode(red,OUTPUT);
    pinMode(yellow,OUTPUT);
    pinMode(green,OUTPUT);
}

void loop(){
    changeLights();
}

void changeLights(){
    // red on, other off for 3 seconds
    digitalWrite(green,LOW);
    digitalWrite(yellow,LOW);
    digitalWrite(red,HIGH);
    delay(3000);

    // red on, amber on,green off for 3 seconds
    digitalWrite(green,LOW);
    digitalWrite(yellow,HIGH);
    digitalWrite(red,HIGH);
    delay(3000);

    // red off, amber off,green on for 3 seconds
    digitalWrite(green,HIGH);
    digitalWrite(yellow,LOW);
    digitalWrite(red,LOW);
    delay(3000);

    // red off, amber on,green on for 3 seconds
    digitalWrite(green,HIGH);
    digitalWrite(yellow,HIGH);
    digitalWrite(red,LOW);
    delay(3000);
}

What I'm wanting to achieve next is a button which resets the code back to the top of void changeLights.
I assume I would be able to do this using a push-to-make switch, but I'm not sure how to incorporate it into my circuit or if it is even possible to reset using this.

Jumping to the top of changeLights() is not the best idea. Wouldn't you like to have an interupt service routine that clears all leds and then returns to the loop() function?

I'm not sure what the best practice is, But now is the best time to learn. Point me in the right direction please.

The reset button already does more or less what you want. If you do not want to reset the whole program, start by removing the call to delay() as in the blink without delay Arduino example. Then you will be able to poll a button in parallel. BTW, you will drive the motorists crazy if green is lit for only three seconds.

As currently written, your changeLights() function, which is repeatedly called over and over again by the Arduino loop() function, runs a timed sequence of lights.

Red light is on for 3000 ms
Amber is on for 3000 ms
Green is on for 3000 ms

This sequence could also be implemented using a state machine, but as it is right now, it's just a simple sequence of operations.
So now you have a new feature request (heh, this happens all the time in pro software development):

hardware will include a momentary switch to ground
when the switch is pressed, the changeLights() sequence will skip to the next Red light
we might also want to do other kinds of sequence change, not just reset

The simplest way to code this would be to use digitalRead() to test whether the switch is pressed. You could test just after each of the delay(3000) calls. Technically this would work, but it would only sense the switch state just at the instant that digitalRead() is called. So for most of your 9-second sequence, it will ignore the switch, and only briefly test. The user will have to hold the button for 3 seconds to be sure the program senses the switch press.
There are some better ways to make this work. The delay(3000) actually makes the program do nothing else but watch the clock for the full delay interval, it doesn't do anything else during this time. So instead of delay(3000) you could use a for loop, and test whether the button has been pressed.
// Spend 3 seconds waiting; exit the function if BUTTON1 is pressed.
for(int count = 300; count > 0; count--) {
    delay(10); // test the button every 10 ms
    if (digitalRead(BUTTON1) == LOW) {
        return; // skip out of the changeLights() function
    }
}

(Just saw Edgar Bonet's comment about the blink without delay Ardino example, which is another valid way to do the same thing. You could also use the millis() function and calculate the time when the next state transition should happen.)
Since this is an educational example, it's worth looking into how you would implement this as a state machine. (The traffic lights controller is often used as an introduction to state machines.) There's two types of state machines, Mealy and Moore, the difference is that one kind the outputs are determined only by the internal state, and the other kind, the outputs are a function of the internal state and the inputs.
A simple traffic light controller state machine might look like this:

state 0: initialize; next state=1
state 1: Red light on, timer=5 seconds, next state=2
state 2: Green light on, timer=3 seconds, next state=3
state 3: Amber light on, timer=1 seconds, next state=1

Use a timing countdown like in the example above, and when the countdown reaches 0, advance to the next state.
const int S0_INIT = 0; // state 0: initialize
const int S1_RED = 1; // state 1: Red light on
const int S2_GREEN = 2; // state 2: Green light on
const int S3_AMBER = 3; // state 3: Amber light on
int state = S0_INIT;
int stateTimer = 0;
// void setup() not shown; configures input and output pins by pinMode(...)
void loop()
{
    if (stateTimer < 0) { stateTimer = 0; state = S0_INIT; return; }
    if (stateTimer > 0) {
        stateTimer = stateTimer - 1;
        delay(10); // 10 ms interval
        return;
    }
    switch(state) {
    case S0_INIT: // state 0: initialize; next state=1
        stateTimer = 0;
        state = S1_RED;
        break;
    case S1_RED: // state 1: Red light on, timer=5 seconds, next state=2
        // digitalWrite(... etc.) Red light on
        stateTimer = 500;
        state = S2_GREEN;
        break;
    case S2_GREEN: // state 2: Green light on, timer=3 seconds, next state=3
        // digitalWrite(... etc.) Green light on
        stateTimer = 300;
        state = S3_AMBER;
        break;
    case S3_AMBER: // state 3: Amber light on, timer=1 seconds, next state=1
        // digitalWrite(... etc.) Amber light on
        stateTimer = 100;
        state = S1_RED;
        break;
    }
}

A more advanced traffic light controller (that responds to input) might look like this:

state 0: initialize; next state=1
state 1: Red light on, next state=2 (unless SWITCH1=HIGH, next state=4)
state 2: Green light on, next state=3 (unless SWITCH1=HIGH, next state=4)
state 3: Amber light on, next state=1 (unless SWITCH1=HIGH, next state=4)
state 4: Red light on, next state=5 (unless SWITCH1=LOW, next state=2)
state 5: no lights on, next state=4 (unless SWITCH1=LOW, next state=2)

An external input SWITCH1 switches this traffic controller between Red-Amber-Green sequence (states 1-2-3) and flashing-Red sequence (states 4-5). Adding constants for S4_BLINKING_RED=4 and S5_BLINKING_RED=5 and replacing the switch(state):
    switch(state) {
    case S0_INIT:
        stateTimer = 0;
        state = S1_RED;
        break;
    case S1_RED:
        // digitalWrite(... etc.) Red light on
        stateTimer = 500;
        state = S2_GREEN;
        if (digitalRead(SWITCH1) == HIGH) {
            state = S4_BLINKING_RED;
        }
        break;
    case S2_GREEN:
        // digitalWrite(... etc.) Green light on
        stateTimer = 300;
        state = S3_AMBER;
        if (digitalRead(SWITCH1) == HIGH) {
            state = S4_BLINKING_RED;
        }
        break;
    case S3_AMBER:
        // digitalWrite(... etc.) Amber light on
        stateTimer = 100;
        state = S1_RED;
        if (digitalRead(SWITCH1) == HIGH) {
            state = S4_BLINKING_RED;
        }
        break;
    case S4_BLINKING_RED:
        // digitalWrite(... etc.) Red light on
        stateTimer = 50;
        state = S5_BLINKING_RED;
        if (digitalRead(SWITCH1) == LOW) {
            state = S2_GREEN;
        }
        break;
    case S5_BLINKING_RED:
        // digitalWrite(... etc.) no lights on
        stateTimer = 50;
        state = S4_BLINKING_RED;
        if (digitalRead(SWITCH1) == LOW) {
            state = S2_GREEN;
        }
        break;
    }

(Remember to define the SWITCH1 pin, and configure pinMode(SWITCH1 ) in setup().)
Of course a real traffic light controller has more lights, say Northbound-Red, Northbound-Amber, Northbound-Green, Westbound-Red, Westbound-Amber, Westbound-Green, etc. Not to mention left turn arrows and maybe even "vehicle present" sensors. For a smart traffic light controller like that, the state is named by what traffic flow is authorized during that state:

state 1: northbound-southbound traffic green, 5 seconds, next state 2
state 2: northbound-southbound traffic amber, 2 seconds, next state 3
state 3: all lights red, 0.5 second, next state 4 (unless no vehicles waiting west-east lanes, then next state 6)
state 4: westbound-eastbound traffic green, 5 seconds, next state 5
state 5: westbound-eastbound traffic amber, 2 seconds, next state 6
state 6: all lights red, 0.5 second, next state 7 (unless no vehicles waiting N-W nor S-E left turn bays, then next state 9)
state 7: north-to-west left turn and south-to-east left turn green, 3 seconds, next state 8
state 8: north-to-west left turn and south-to-east left turn amber, 2 seconds, next state 9
state 9: all lights red, 0.5 second, next state 10 (unless no vehicles waiting W-S nor E-N left turn bays, then next state 12)
state 10: west-to-south left turn and east-to-north left turn green, 3 seconds, next state 11
state 11: west-to-south left turn and east-to-north left turn amber, 2 seconds, next state 1
state 12: all lights red, 0.5 second, next state 1 (unless no vehicles waiting north-south lanes, then next state 3)

The power of using state machines is that they all use the same basic "engine", just with more states, more outputs, more inputs. If the traffic engineer wants to adjust the timing to improve the flow of traffic, that only requires adjusting some of the data, which is much lower risk than rewriting code.  ... and of course state machines apply to more than just traffic lights, it's a very generally useful design technique.

Agreed, a state machine allow for much more complex situations, while still being readable.

MarkU provided a pretty thorough answer with all the whys and hows of
state machines. This is definitely the way to go, and I encourage you to
read that answer very carefully.
I wrote a comment to your question where I suggest dropping delay() in
order for your loop to never block and your program to be responsive to
user input. Now I am writing this answer only to show you how to combine
both ideas, i.e. implement a state machine without delays. I do not
think this code needs any explanation besides those in MarkU's
answer and in the Blink
without delay
Arduino example.
// Pinout.
const int red = 13, yellow = 12, green = 11, reset = 10;

void setup() {
    pinMode(red,    OUTPUT);
    pinMode(yellow, OUTPUT);
    pinMode(green,  OUTPUT);
    pinMode(reset,  INPUT_PULLUP);  // use internal pull-up
}

void loop() {
    static enum { INIT, RED, RED_AMBER, GREEN, GREEN_AMBER } state = INIT;
    static uint32_t duration;
    static uint32_t last_change;
    uint32_t now = millis();

    // Sense the reset button.
    if (digitalRead(reset) == LOW)
        state = INIT;

    // Wait at this state for the specified duration.
    if (state != INIT && now - last_change < duration)
        return;

    // Switch to next state.
    switch (state) {
        case INIT:
        case GREEN_AMBER:
            state = RED;
            duration = 3000;
            digitalWrite(green,  LOW);
            digitalWrite(yellow, LOW);
            digitalWrite(red,    HIGH);
            break;
        case RED:
            state = RED_AMBER;
            duration = 3000;
            digitalWrite(green,  LOW);
            digitalWrite(yellow, HIGH);
            digitalWrite(red,    HIGH);
            break;
        case RED_AMBER:
            state = GREEN;
            duration = 3000;
            digitalWrite(green,  HIGH);
            digitalWrite(yellow, LOW);
            digitalWrite(red,    LOW);
            break;
        case GREEN:
            state = GREEN_AMBER;
            duration = 3000;
            digitalWrite(green,  HIGH);
            digitalWrite(yellow, HIGH);
            digitalWrite(red,    LOW);
            break;
    }
    last_change = now;
}

I would normally have declared duration as a static const. I kept it
non-const only to follow MarkU's steps and make it easy to have
different durations for different states (really, the green light should
last longer...).

Very good! I would make pinMode(reset,  INPUT_PULLUP); to save having to have an external pull-up resistor.

@NickGammon: Good point! I edited the answer to follow your suggestion.

The best way to handle this problem is using a state machine, as shown in all the other answers. In fact, this IS the classical problem to learn how to use and implement state machines.
I just wanted to add the "fast" solution to your problem, which will enable you to do what you want without changing your code too much:
void changeLights(){
    unsigned long startTime;

    // red on, other off for 3 seconds
    digitalWrite(green,LOW);
    digitalWrite(yellow,LOW);
    digitalWrite(red,HIGH);
    startTime = millis();
    while ((millis() - startTime) < 3000)
    { // Wait for 3 seconds while checking for the button
        if (digitalRead(buttonPin) == HIGH)
            return; // Just exit this function; the loop will start again
    }

    [ repeat for the other colors ]
}


text:
How do I adjust the scale/calibration of a photoresistor?
This photoresistor has a min/max of 0-1023.
I'm trying to scale the brightness of a cathode RGB LED based on the sensor's value, but based on my current lighting, the min/max readings I generally am getting are 100-700.
So how can I scale the sensor reading so that 100 = no light on the LED and 700 = max brightness?

What circuit?  What code?   output=constrain(map(sensor,100,700,0,255),0,255)); per http://arduino.stackexchange.com/q/9219/6628 ?

You can easily scale in Arduino code with the map() function.
e.g.:
const int MIN_LIGHT 100;
const int MAX_LIGHT 700;

int light_reading = analogRead(A0);

// Convert MIN reading (100) -> MAX reading (700) to a range 0->100.
int percentage_bright = map(light_reading, MIN_LIGHT, MAX_LIGHT, 0, 100);

But you may need some calibration of your system to handle different ambient light situations. What reading do you get in direct sunlight for example?
So then I assume you're using PWM (Pulse Width Modulation) to drive the LED.  This requires a value between 0 & 255.  Once again we can use the map() function.
// Convert light-value % (0-100) to PWM speed (0-255)
int led_brightness = map(percentage_bright, 0, 100, 0, 255);
analogWrite(LED_PIN_RED, led_brightness);

Obviously these bits of code can be reduced down to a single line - mapping directly from the reading to the desired result.

A light_reading of 90 would give a negative percentage_bright, which could in turn produce negative led_brightness, which would behave badly.  You need a light_reading = constrain(light_reading,MIN_LIGHT,MAX_LIGHT) or percentage_bright=constrain(percentage_bright,0,100)

@Dave X - Yep, that's why I had the note about calibration.  But I didn't want to confuse the explanation of the map() function.

source: Stack Exchange

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

sort: votes


text:
Arduino vs Raspberry, Advantages And Disadvantes
I have done extensive research into the differences and here are the questions i have:

What is a micro controller and what differs it from the raspberry pi system
Why buy the Arduino when it is less powerful than the raspberry pi
What projects would either system be better for
Does Arduino run a full OS
Where is the best place to buy arduino and raspberry pi
What is the difference in the ad dons
Which has the most tutorials
What is the different's in power supply and usages
I know i'm asking this on a forum with arduino fans (There is no arduino vs raspberry pi forum) but opinions aside which is the best for beginners (I can program C++ and python as well as building hardware components)
What is the general price different overall including buying extra ad dons/shields

Thank you for your answers :)

This question is also on the Raspberry pi forum to ensure non baits answers: http://raspberrypi.stackexchange.com/questions/43458/arduino-vs-raspberry-advantages-and-disadvantes

Cross-posting within Stack Exchange is not permitted. See: Is cross-posting a question on multiple Stack Exchange sites permitted if the question is on-topic for each site?

And here the answer is the same as the one to this question: "which is better, a car or a a pc?".. the answer is.. it depends! They are completely different systems, with completely different targets, completely different requirements (required electronics, user skills, environment...), It depends on your application. USUALLY simple = arduino, complicated = raspberry, interaction = both, but... it depends ;) The only "real" question is number 4, and its answer is NO, Arduino does not have an OS (you are writing the whole code, no layers between you and the hardware)

1) Here is a great article about microcontrollers and how they differ from a full computer: http://electronics.howstuffworks.com/microcontroller1.htm
tl;dr: A Raspberry Pi runs a full desktop OS (often Linux) and as such, can do most of the things a "typical" computer can do, such as browse the internet or install different programs. An Arduino, however, cannot do that. An Arduino can run one piece of software that you program to it (called a sketch in the Arduino world) and repeat that same program over and over.
2) They have different purposes. A Raspberry Pi is designed as a low-cost desktop computer that you can put anywhere, and also as a platform that is easy to put into different projects. An Arduino is better suited for attaching sensors to, controlling motors, etc.
3) see #2
Also, a Raspberry Pi is typically used when a GUI is wanted, or when more computing power is required. An Arduino is typically used for more real time things such as reading sensors or controlling LED's.
4) No, it does not. Arduino's run C++ compiled as machine code object files.
5) For the Raspberry Pi, Here is the list of official resellers: https://www.raspberrypi.org/products/model-b-plus/
For the arduino, it depends on what kind you're buying and where you live, there are many different styles.
6) As a general rule, Arduino's have more shields. But, a raspberry pi typically needs a screen, mouse, keyboard, etc. Everything a standard computer needs.
7) Entirely depends on what you're trying to do.
8) Both take a 5V input voltage. An Arduino can take up to a 20v input (again, depending on the model) whereas the Raspberry Pi can just be powered with 5v over USB.
9) Again, depends on what you're trying to do. A Raspberry Pi is "easier" to use, as it's a full computer.

Thank you very much i'm thankful for your answer i think the arduino is for me. I like more of the technical side of things :) and plus I've already got a pico itx setup which is very similar to the raspberry pi anyway. And hey the arduino forums seem to be nicer then the snobby raspberry pi fans :p

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


text:
How do I install the latest Arduino IDE on Ubuntu 14.04LTS?
What I've tried:

I downloaded the package for 1.6.7 on Ubuntu 14.04 LTS but when I open it no matter what I try it will not start.
I installed 1.0.5 from the Ubuntu Software Center. I tried to update it but found no solution.

UPDATE: I found my answer in talamaki's answer on that other question linked above.

You say that you downloaded it, have you actually installed it? What command did you use? Where was it installed to (updatedb;locate arduino)? What happens it you try to run it from the command line? Is it in your path (echo $PATH)? You may need to update, or manually fix, the desktop shortcut, which is currently pointing to 1.0.5. Please edit, and expand upon, your original post with more details.

@LinuxAut2115 did you run the install script inside the tar file? Usually it replaces any arduino.desktop launcher present

If you download 1.6.7 from the Arduino Downloads page, un-archive it, and then  double-click the "Arduino" file inside the download, you will get 1.6.7. That's exactly how I use it. I'm going to close this as a duplicate of a similar question. The answer there has more details.

Follow the following step to download, install and run Arduino IDE on Ubuntu

First Download the Tar (tar-bal) from this link http://arduino.cc/en/Main/Software (download the correct 32 / 64 bit linux version ) depends upon your Ubuntu version.
Then goto download folder using terminal (shell) or the folder where you downloaded the tar and unpacked that tar using the following commands
like
cd /Downloads
tar -zxvf arduino-1.6.7-linux32.tgz
where 1.6.7 is the version of ide
you also need java runtime environment for arduino IDE download and install it using the following command
   sudo apt-get install openjdk-7-jre
you also need to provide the UART permissions for your hardware using following commands
sudo chmod a+rw /dev/ttyACM0
where ACM0 is the port number if you are using multiple or many arduinos just give permissions using the above commands by replacing the ACM0 to ACM1 to ACMN

then create a shortcut of arduino ide from the folder where you extract the tar
cd ~/Desktop
ln -s /Downloads/arduino-1.6.7/arduino

and then double click the shortcut to run arduino if it gives permission error then right click the shortcut and in file preferences gives permissions to the shortcut


text:
Arduino is not responding to a Tiny RTC I2C modules, How to fix?
We have an arduino due with a Tiny RTC I2C module and we're trying to print the current time to the serial monitor. However its not working, currently its printing the time as 2165/165/165 (Monday) 165:165:85 (it should read something like 2016/3/3 (Thursday) 4:15:00). Interestingly it continues to read the same thing, it doesn't change, even if I remove the module from the breadboard completely. I have tried this with two of the modules and both have the same exact results. Does anyone know how to fix this?
My schematics are the same as shown here:
http://www.hobbyist.co.nz/?q=real_time_clock
This is my code, it's just the example code from the imported library for the clock.
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop () {
    DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");

    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));

    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();

    Serial.println();
    delay(3000);
}

Please add the code you're using.

...and a schematic.

Sounds like wiring issue or just unset clock.

It seems your schematic does not include pullup resistors on SDA/SCL wires. I2C won't work properly without pullups (try 4.7k or 10k).

Alright, I'll try it in the morning, its about 10 here, thanks for the suggestion though.

Still nothing, I realised that because I'm using the due, I should be using pins 20/21 for the sda/slc rather than pins a4/a5. But even after changing those nothing happened.

Maybe show a picture of your wiring.  Also rtc.begin() always returns true, so the test will never fail.

http://i.imgur.com/MTJjsiX.jpg    It's a little hard to see, but the red wire is on the 5v to the vcc, white wire is from ground to ground, brown wire is from pin 20 to sda and the yellow wire is from pin 21 to slc.

It seems on this wiring that you put resistors in series betweens Due SDA/SCL and the RTC SDA/SCL. I don't think this is correct. You should try real pullup resistors from SDA/SCL to 3.3V.

I don't quite understand, are you saying I should be using 3.3v rather than 5v, and where should the resistors be?

I mentioned 3.3V because this is the voltage level used on Due; IIRC, any 5V voltage to an input would damage it. A pullup resistor is a resistor between a line (SDA or SDL) and the positive voltage level. I2C wiring is such that these pullups are necessary for the communication to work.

Still no luck, updated image: http://i.imgur.com/3qyJAZx.jpg    I tried the resistors on the 5v to vcc and the other on the sda, and then again on the slc, neither worked.

You have a couple of problems (although the lack of pull-up resistors is not one of them, because the board you linked has pull-up resistors on it).

The DS1307 needs to operate at a minimum of 4.5 volts, so you can't connect it to the 3.3V pin on the Due. (You need to supply it with 5V).
However the Due is a 3.3V device on its data pins, and thus you can't connect the DS1307 directly to SDA/SDL or you will damage the Due.

Thus you need to supply the clock board with 5V, and use a bi-directional logic-level converter, such as this (using two logic-level MOSFETs):

You can buy level-converter boards, but as you can see, one is easy enough to make up.
Now the clock chip runs at 5V, but the logic levels are converted to 3.3V for the Due.
I tested this with mine, and it worked OK.

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 myclock;

void setup () {
    Serial.begin(115200);
    Wire.begin();
    myclock.begin();
}

void loop () {
    DateTime now = myclock.now();

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

    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");

    Serial.println();
    delay(3000);
}

Output:
2016/3/6 12:0:20
 since midnight 1/1/1970 = 1457265620s = 16866d

2016/3/6 12:0:23
 since midnight 1/1/1970 = 1457265623s = 16866d

2016/3/6 12:0:26
 since midnight 1/1/1970 = 1457265626s = 16866d

A useful technique for debugging is to run the "I2C scanner" I have on my I2C page. The code is:
// I2C Scanner<!-- language-all: lang-none -->
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

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

  // Leonardo: wait for serial port to connect
  while (!Serial)
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;

  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

If you don't see your device appear in the Serial Monitor, there is no point wondering why the date doesn't change, because it hasn't found the clock at all. You should see something like this:
I2C scanner. Scanning ...
Found address: 104 (0x68)
Done.
Found 1 device(s).

How the level converter works
For more information, read the Philips Application Note AN97055
In brief (taking SDA as an example):

If neither side is driving SDA low, then VGS is zero (they are both 3.3V) and the MOSFET does not conduct. Hence each side is "pulled-up" to their respective voltages. The low side is pulled up to 3.3V and the high side is pulled up to 5V.
If the low side drives SDA low, then VGS is 3.3V which is high enough for the MOSFET to conduct. Since it conducts it also drags the high side low as well (overpowering the 10k pull-up resistor).
If the high side drives SDA low, current initially flows through the drain substrate diode of the MOSFET (it will be a diode drop above 0V, namely 0.7V), lowering the voltage at the source, until VGS is high enough for the MOSFET to conduct. Once it starts conducting then the low side is pulled further lower.

Do you have an actual photograph of this?

I've pulled it all apart days ago, however thankfully I took a snapshot before I did.

To be honest, the schematic is easier to follow. When looking at photos it can be hard to see exactly what is plugged into where.

Thanks Nick Gammon, I will take a closer look at this soon and try it out.

I just noticed that you are using the pins on the right hand side of the module, I think on the board it's labeled as P1, where as I am using the pins on P2, does that make a difference?

No I don't think that matters. As your page says: The most useful pins are duplicated from P1 to P2.

Do you have an actual photograph of this? The MOSFETs finally arrived so I can try this out now but I'm having trouble reading the schematic...

I think the schematic is a lot clearer than any photograph will be. However see amended reply.


text:
help compiling code for flora project
I'm working on the Adafruit Firewalker shoes.
I can't make my code compile to test my flora project.
This is my error message:
Arduino: 1.6.7 (Windows 10), Board: "Adafruit Flora"

C:\Users\Devi\Documents\Arduino\test_2\test_2.ino\test_2.ino.ino:1:29: fatal error: Adafruit_NeoPixel: No such file or directory

 #include <Adafruit_NeoPixel>

                             ^

compilation terminated.

exit status 1
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

https://learn.adafruit.com/firewalker-led-sneakers/test-circuit
    #include <Adafruit_NeoPixel.h>

const int analogInPin = A9;  // Analog input pin that the potentiometer is attached to
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, 6, NEO_GRB + NEO_KHZ800);
int sensorValue = 0;        // value read from the pot

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
 pinMode(9, INPUT_PULLUP);
   strip.begin();
  strip.show(); // Initialize all pixels to 'off'

}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // print the results to the serial monitor:
  Serial.print("sensor = " );
  Serial.println(sensorValue);

if (sensorValue < 100){
  Serial.println("leds triggered");
colorWipe(strip.Color(255, 0, 0), 25);
colorWipe(strip.Color(0, 0, 0), 25);
}

}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

Can you please copy and paste the code, and the error message, into your question as text? Not a screen-shot? I can hardly read what the error is. Edit your post and format the code using the code formatting markdown (four leading spaces). For help see Markdown help. You should be able to do this by selecting the code and pressing Ctrl+K to have your browser do this for you.

@NickGammon thank you sorry I'm a mess ive never coded with Arduino before

Your error message says #include <Adafruit_NeoPixel> but your code says #include <Adafruit_NeoPixel.h> - which do you actually have?

@NickGammon I have #include <adafruit_neopixel.h>  all I did was copy and paste the source code

I had the same problem, you just have to download the Adafruit Neo Pixel library:

i think issue is in your this path
C:\Users\Devi\Documents\Arduino\test_2\test_2.ino\test_2.ino.ino:1:29: fatal error: Adafruit_NeoPixel:
make new arduino file and copy the same code and save it on other folder on desktop or other drive then compile it
Compilation
I compiled you same code and my stored path of .ino file is
C:\Users\Muhammad Hassaan\Documents\Arduino\sketch_mar04a

this did work it still says no directory found for neopixels did I install something wrong all I did was copy and paste source code

i think issue is with your library that you have downloaded, please reinstall the Arduino IDE and download the library again with the help of ide then recompile your code


text:
Integration of signal
In my house, I have a low voltage AC signal (0-10V) that is proportional to the amount of current that is drawn at any moment (or as it is presented: kW) (europe, 50Hz). Presently, it is just shown as a dial in my kitchen, of course I would to log this. I want to rectify and integrate this singnal over an appropriate time span (maybe on minute) As far as I can see, I basically have two ways of doing this:

The pure arduino approach: Using a voltage divider to get it down to 0-5 V (after rectification) (and maybe throw in a zener diode as an extra protection) Then using an adc in the arduino and measure the voltage directly. The problem I foresee with this approach is that I will need a pretty high sampling rate to make sure I get the peak values. If I managed to sample at exactly the same frequency as my mains,I could just calibrate the measured value (unless I managed to hit the cross overs) but I do not think that would be feasible So I think I need to maybe sample on approx 500 Hz and pick out the highest value from each 1/50 second.
Using an opamp, a few resistors and a capasitor to set up an analog integration circuit, then use the arduino to read out and reset that at appropriate times. Setting up the integration circuit is no problem for me, but I need some feedback on the reset circuit. I have been looking around a bit, but I have not found any standard way to reset an integrator circuit, it seems like the idea is that it should be integrating for as long as it is running.. As far as I can see, as long as it running on <= 5V, I could use an input on the arduino to drain it? - I would then need to make the dimensions such that the low current the arduino input draws will allow the integrator to be reset fast enough.

Any comments? Have I overlooked something? is there a third approach that I have not been thinking about? Is the 1st approach easier that what I think?

“proportional to the amount of current that is drawn at any moment (or as it is presented: kW)” Is it current or wattage you are reading? They are not the same: If you have inductive loads in your house (motors...) or switched-mode power supplies, and want to estimate the consumed power, you will have to monitor the mains instantaneous voltage (at least the phase) and multiply current × voltage. Simply multiplying RMS(current) by RMS(voltage) works only with resistive loads.

What I have is a voltage, what the meter tells me it knows is the "wattage"- I don't know if it is true kW or to which degree it is messed up with inductive load (althoug at least at wintertime, most of my usage is for heating, which should be pretty resistive load)

If that voltage is an image of the wattage, you should just run a low-pass filter on it, with no prior rectification.

Thanks works like a charm! typical what (watt?) happens when you know a bit of a topic but do not really know it - and ends up with a too complicated solution...

Sorry, but.. Why integration? Just use a peak detector like this one:

The output will "float" to the peak value of the input signal, minus the voltage drop across the diode:

The output oscillates between 9.7V and 9.2V, which is a 5% maximum error. If you want to reduce it, sample with a sample rate not multiple of 50Hz and average the measures.
The RC constant is 500ms. This means that it will require less than a second to pass from a value to a lower one:

Here in almost 500ms it will go from 10V to 5V.
If you want to reduce the diode effect (9.7V instead of 10V) use a schottky diode. This, however, will not reduce the 9.2V effect.
You should divide by 2 the voltage; you can either

divide it before the diode (but then the diode effect will be more evident - you can however correct it in software
divide it after the circuit (In this case, replace the 500k resistor with two 250k resistors and take the voltage in the middle)

Of course 500k and 250k are not standard values, but you can use any nearby value without affecting the behavior

That's pretty cool - that was the third option I didn't think about

Again thanks, I have implemented it, works like a charm!

Glad it worked :)

With an Arduino Uno, you can get 9615 samples per second from an analog
input, and do the data processing at the same time. That's more than
enough to reliably detect a peak. For this, you have to set the ADC to
"free running mode" and do the processing in the ADC interrupt service
routine. Se this answer for
a detailed explanation and code.
Oh, and instead of peak detection, you could just integrate your signal.
That should be simpler, and simple is good for interrupt-driven data
processing.

I'm not quite clear on the 'peak' detection - this would mean your reading would be changing several times a second potentially. Does the current in your house vary that much per second? I don't think your electricity meter is that clever anyway (there must be a smoothing effect, I reckon). For example, if you turned on your electric kettle for 1/50th of a second, would your domestic meter accurately record that (or the 0-10V signal vary)? I personally doubt it but I'm no meter designer! Anyway, you also mention that you want to log over a minute? I'm unclear on the exact requirements here.
Anyway, if you are reading the 'max' current (so you can accurately calculate bills, for example) I think your first approach would work - after all a 50Hz sampling rate is very low for an Arduino. You won't need a 500Hz sample rate as the data doesn't change that frequently anyway, does it?
Perhaps you could trigger the sampling activity by synchronising to the mains frequency (which you sort of allude to) and then do the reading? Use an analog input to detect the rising LV mains cycle and then do the reading? Or use a Schmidt trigger to trigger the Arduino (sounds a bit of overkill, I think the Arduino could do it all).
Experimentation is called for to see what works and what doesn't but your first approach seems eminently feasible to me.

I must have been a bit unclear, when I was talking about peak detection, I meant to measure (close to) the sinus peak to avoid aliasing effects.


text:
Why isn't there bus contention on the MISO line during SPI-based programming?
Consider this image from sparkfun:

Let's say I have this setup, a master and n slaves, plus a programmer connected to the SPI lines.
When I program the master (Arduino), the Arduino is reset. This means that all the data pins go low.
Since SS is active low, all the SS pins on the slaves go active.
I believe this means that all the slaves start driving the same MISO line (blue arrow from slaves to master), either high or low.
Doesn't this result in bus contention on that line? If not, what's the mechanism that prevents bus contention from happening?

This means that all the data pins go low. They don't go LOW, but high impedance input.

And since the ports go high impedance, put a pull-up resistor on the SS line to drive it high when the MASTER is reset

Yes, you can get SPI bus contention when using multiple SPI slave devices. It is up to you, the designer, to ensure that each SPI slave device has its chip select (CS or SS) asserted only when no other devices are driving MISO. Normally that is achieved by:

initialize all of the CS pins high (inactive) during setup
in the code that accesses SPI device #1,

assert SPI device #1 CS1 low (active)
perform SPI transfers on SPI device #1
release SPI device #1 CS1 high (inactive)

in the code that accesses SPI device #2,

assert SPI device #2 CS2 low (active)
perform SPI transfers on SPI device #1
release SPI device #2 CS2 high (inactive)

SPI bus contention can also occur during device programming (loading the bootloader or firmware image), if there is an attached SPI slave device, and its chip select (SS) is not pulled inactive by a pullup resistor.
I had a problem with this on one of my designs a few weeks ago. I was trying to burn the bootloader into some blank ATmega328-AU chips post-assembly, and my device programmer wasn't able to successfully program the chips because my one slave device had its chip select connected only to an ATmega328 pin.
I had previously breadboarded this design using an Arduino Pro Mini board, and it was working fine; but when I moved to first prototype PCB there was bus contention on MISO -- the blank ATmega328 wasn't driving the slave device's chip select high or low, but it floated low (active), causing MISO contention.
My solution (workaround) was temporarily contacting the chip-select to VDD 3.3V through a 10kohm resistor. This made my SPI slave device inactive, allowing the device programmer to successfully load the bootloader.
I think there would be no harm in leaving the pullup resistor on chip select (since it's an active-low signal), but it was only really necessary when using the device programmer. After I had the prototype boards initialized with the bootloader image, I was subsequently able to load firmware images as usual.
(One minor unrelated issue was that my assembler purchased ATmega328-AU when I had specified ATmega328P-AU -- they are almost the same, and it doesn't make a difference for my application, but it was annoying that I had to use a slightly different command line argument than then one I used with the Arduino Pro Mini board.)

Really my question applies both ways. If there is bus contention that the programming should fail. But I think what you're saying is that my assumption that pins are driven low on reset (or blank) is false. Rather, they  float.

I think the ATmega328 PORTB pins are initially configured as inputs at power-up reset, will check datasheet...

Confirmed. Section 13.2.1 Configuring the Pin: "The port pins are tri-stated when reset condition becomes active, even if no clocks are running."


text:
How to pad an ascii number with leading zeros?
I need to include a 3 digit ascii representation of message length number in the message header, but I am having difficulty trying to pad the number with leading '0' zeros in order to keep the number of 'length' digits needing to be appended always 3 even when the message length is only one or two digits long.
Addendum:
The problem, more specifically, is how to left-pad a char array containing the number representation.
I got as far as defining what and where, but I couldn't figure out how to shift the char[] contents right in order to insert the "0" at msglength[0].  (I tried using strcat, but that didn't work).
char msglength[4]          //(3 digits + nul)
for (int pad=1; pad<=3-strlen(msglength); pad++)
{
    // add a leading zero char to msglength, but that involves
    // somehow shifting all its contents to the right
}

if( value<10 ) Serial.print("0"); else if ( value<100 ) Serial.print("00"); Serial.print(value);

You have to move the bytes starting from the last one: for (int i = strlen(msg); i >= 0; i--) msg[i+3] = msg[i];. Make sure your char array is big enough, at least strlen(msg) + 3 (padding) + 1 (null terminator).

Yes, I understand I must move the existing array char digits plus null terminator to the right (top) of the msglength[4] array, but somehow I must also insert a '0' char into each vacated position. But my lack of programming knowledge can only come up with a solution which requires 2 for( loop passes, with a temporay value to hold the amount of steps used in the first 'right-shift' pass, in order to fill with the appropriate number of '0's from the left in a second pass.
Is there a more elegent solution other than using 2 for( loops and a temp variable?

Two loops is perfectly fine here. I do not think you can make it an better.

This is the kind of situation where printf() comes handy:
printf("%03d", number);

prints the number in the format you described. Alas, printf() is not
part of the standard Arduino API. But you can have it, nonetheless, at
least on AVR-based Arduinos, as it is provided by the avr-libc, which is
always linked with all Arduino programs. Some setup is needed to tell
avr-libc about where is its “standard output”. We can use the macro
fdev_setup_stream() to tell it to just push the bytes through
Serial.write():
static int Serial_write(char c, FILE *) {
    if (c == '\n') Serial.write('\r');  // convert LF -> CRLF
    return Serial.write(c);
}

static FILE mystdout;

void setup() {
    Serial.begin(9600);
    stdout = &mystdout;
    fdev_setup_stream(stdout, Serial_write, NULL, _FDEV_SETUP_WRITE);
}

void loop() {
    static int count;
    printf("%03d and counting...\n", count++);
    delay(500);
}

C.f. the manual of avr-libc's
stdio.h
for details.
Pros of this method:

printf() has plenty of options to control the formatting of your
messages.
It's very standard C, understood by anyone having programmed in that
language.

Cons:

This can make your compiled program bigger than it would be if
sticking with the Arduino API.
It's not the “Arduino way”.

I think you mean to use sprintf. printf tries to go to an output stream automagically, sprintf uses a destination buffer, which could then be sent via Serial.write().

@bss36504: I mean printf(). Read my answer.

sprintf is also a solution, especially since OP did't ask to print the data on the serial port.

One straightforward way to do this is to extract digits separately (using integer division and mod).  For example, the hundreds digit of a positive or unsigned int x is (x/100)%10.
A sketch shown below uses the statement
  Serial << ' ' << b/100 << (b/10)%10 << b%10;

to print a space and three digits of a positive number, with leading zeroes.  Here are the first 18 lines of output from the sketch:
 000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015
 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031
 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047
 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063
 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079
 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095
 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111
 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
 000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015
 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031

Here is the sketch:
#include <Streaming.h>

//char b=0;    // char is signed; messy when hi bit is on
byte b=0;    // byte is unsigned, all ok
void setup() {
  Serial.begin(115200);
}

void loop() {
  // To emulate
  //    Serial << ' ' << setw(3) << setfill('0') << b;
  // or
  //    Serial << ' ' << b<100? '0': '' << b<10? '0': '' << b;
  // write (eg)
  Serial << ' ' << b/100 << (b/10)%10 << b%10;
  // or if b is an int instead of a byte, write
  //    Serial << ' ' << (b/100)%10 << (b/10)%10 << b%10;

  ++b;
  if (b%16 == 0) Serial.println();
  delay(17);
}

The code shown above uses Streaming.h, a contributed library that adds some “syntactic sugar” to Arduino C.  That is, at compile time it converts C++-like << Serial stream operators to Serial.print statements, without increasing code size.  If you don't have Streaming.h installed, either install it via Streaming5.zip from arduiniana.org or manually translate the Serial << ... statement to Serial.print statements.
Note, if the Streaming.h library supported setw() and setfill(), they could be used to set field width and fill character.  (See comments in sketch.)  However, the current implementation merely translates the stream insertion operator << form into print() form.  It supports four base-conversion specifiers, _HEX, _DEC, _OCT, and _BIN; a _FLOAT function with number of decimal places specified; and endl.  Some _FILL functions are suggested at the Arduiniana.org link.

There is always brute force.
char* itob(int val, char* buf, size_t n)
{
  char* bp = buf + n;
  do {
    *--bp = (val % 10) + '0';
    val = val / 10;
  } while (bp != buf);
  return (buf);
}

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

  const int BUF_MAX = 3;
  char buf[BUF_MAX];

  Serial.write(itob(42, buf, BUF_MAX));
  Serial.println();
}

void loop()
{
}

Please observe that the buffer is not null-terminated, therefore the Serial.write().
Several possible optimizations from the simple solution such as detect when the value is zero and short-cut.
Cheers!

Thank you all for your suggestions.
This is what I came up with, which seems to work ok.
char lengthstr[4]="7";
Serial.print("lengthstr='"); Serial.print(lengthstr); Serial.println("'");
int maxsize=sizeof(lengthstr);  // size of lengthstr array
int steps=strlen(lengthstr)+1;  // number of chars to be moved
int hop=maxsize-steps;          // number of steps to be jumped over each move
if((steps>1)&&(maxsize>steps)) {
   for (int pos=steps; pos >= 0; pos--) {
      lengthstr[pos+hop] = lengthstr[pos];
      lengthstr[pos]='0';
   }
}
Serial.print("lengthstr='"); Serial.print(lengthstr); Serial.println("'");

Two problems here: 1) On the first iteration of the for() loop, you are writing beyond the end of the lengthstr array. This is called memory corruption and can be a very nasty bug. The loop should start at pos=steps-1. 2) Assuming you fix that previous bug, the code will work if lengthstr is of size 4, but not if it's any bigger. Your initial two-loop idea was cleaner and would work at any size.

Thanks Edgar, I very much appreciate your help and advice, so I will redo using 2 loops, which is easier to get my head around anyway.


text:
Can not connect with Bluetooth hc-05
I connect my Bluetooth hc-05. But the blind led in the Bluetooth module is not stable when I connect with my Android phone. Help help me to solve this.

It is very simple really.
Initially the Bluetooth got paired automatically with my Android, but apparently the variable transmission was not complete.
If this is the case with your module,it will be blinking with high frequency.
So here is what I did:

Hit the RESET button on HC-05 once
Go to Android Bluetooth Settings and UNPAIR HC-05
Now Pair it again by clicking on it
You will be prompted to enter password- '1234'
Open your Bluetooth Terminal and you will find your data appearing
on Android

P.S.-A 2 Hz blinking frequency on HC-05 should signify proper connection

Through which android app you are connecting because normally android only pair and will connect to device if you are sharing some data or files or you can connect to android device using any bluetooth app like bluetooth terminal or dual bluetooth chat

I'm using BT voice


text:
Is my Arduino mega dead?
I accidentally short-circuited my Arduino mega(ended up connecting the 5V and ground pins). Physically from observation nothing seems to be burnt on the board but I am not able to upload new codes to it again. I am quite sure that the last code I uploaded still run on it because when I plug it in all seems to be normal.
I tried to upload codes to it with the CP2012 programmer I use for my pro mini and that doesn't help either.
Is there any way I can manage to upload codes to the board again or it is dead?

Well, is it still short circuited? What did the old sketch do? And how can you be sure that it is still running? With the CP2012, you can't use the DTR pin to move the reset, you know? So just connect +5v, gnd, rx, tx and start uploading. When the IDE tells you "uploading", briefly press the reset button on the mega and see if it works

Have you tried turning it off and on again? (by "it" I meant both your PC and Mega)

@frarugi87 I am familiar with the manual reset approach, it doesn't work with my mega but works with my pro mini.

"when I plug it in all seems to be normal." What do you see or measure to indicate a normal board? E.g. LED behavior, measured outputs, some response to inputs?

@DannyGH with that adapter you should have the autoreset feature on the pro mini, so you don't have to manually reset it..

See Have I bricked my Uno - a lot of that applies to the Mega too. There is a sketch mentioned on that page you can use to test the processor chip with.


text:
Board won't show on one of my computers
I have the same problem with these two boards: Ruggeduino (Uno compatible) and DFRobot Romeo 1 (Duemilanove compatible). On one of my Macs (a Macbook Pro running 10.11.4), I can see a new port  /dev/cu.usbmodem641 or /dev/a4005g3t depending on the board. On the other computer (a Mac Mini late 2014), they just won't show. Same cable, same boards, and no hub. I don't know where to look to see an indication of a failure of some sort.
These two ones use a type-b USB socket (printer style)
Also on the Mac Mini that won't see any of those boards, I can connect an EtherMega2560 (Arduino Mega 2560) which happens to use a micro USB socket. I don't know if that is related to the problem.
Both computers run the same OS (OS X 10.11.4) and the latest version of Arduino.
Here is a difference (found in /var/log/system.log):
On the working computer:
Mar  3 22:20:42 pc101 kernel[0]: AppleUSBFTDI: fInBufPool,kMaxInBufPool 8,64
Mar  3 22:20:42 pc101 kernel[0]: AppleUSBFTDI: Version number - 5.0.0, Input buffers 8, Output buffers 16

On the non working one:
cfprefsd[114]: BUG in libdispatch: 15E49a - 1718 - 0x0

..

If OS X has something like dmesg and lsusb (list USB devices) please post the output.

My Ruggeduino stopped showing up as a serial device under El Capitan (10.11.6). I was able to fix this by installing/updating the VCP drivers for Silicon Labs USB devices available here:
https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx
After installing the Mac driver the Ruggeduino shows up as SLAB_USBtoUART and works fine with the Arduino GUI.

That would only help for a board with a silicon labs chip, but the documentation for the Ruggeduino seems to say it uses at ATmega16u for that role.  It's pretty easy to look at a board and read what is on the chip, if it doesn't say SiLabs, this will not help.


text:
What are the components of a Xively HTTP PUT request to send to my SIM800 GPRS module?
I have an Elecrow GPRS shield which I want to use to post temperatures from 3 x DS18B20s to Xively. The example code is a mystery to me. You can find in full at this link: http://www.elecrow.com/wiki/index.php?title=GPRS/GSM_Shield_v1.0#A_Simple_Source_Code_Example
The relevant function is here:
///send2Pachube()///
///this function is to send the sensor data to the pachube, you can see the new value in the pachube after execute this function///
void Send2Pachube()
{
mySerial.println("AT+CGATT?");
delay(100);

ShowSerialData();

mySerial.println("AT+CSTT=\"CMNET\"");//start task and setting the APN,
delay(1000);

ShowSerialData();

mySerial.println("AT+CIICR");//bring up wireless connection
delay(300);

ShowSerialData();

mySerial.println("AT+CIFSR");//get local IP adress
delay(2000);

ShowSerialData();

mySerial.println("AT+CIPSPRT=0");
delay(3000);

ShowSerialData();

mySerial.println("AT+CIPSTART=\"tcp\",\"api.cosm.com\",\"8081\"");//start up the connection
delay(2000);

ShowSerialData();

mySerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
String humidity = "1031";//these 4 line code are imitate the real sensor data, because the demo did't add other sensor, so using 4 string variable to replace.
String moisture = "1242";//you can replace these four variable to the real sensor data in your project
String temperature = "30";//
String barometer = "60.56";//
mySerial.print("\"method\": \"put\",\"resource\": \"/feeds/43634/\",\"params\"");//here is the feed you apply from pachube
delay(500);
ShowSerialData();
mySerial.print(": ,\"headers\": \"X-PachubeApiKey\":");//in here, you should replace your pachubeapikey
delay(500);
ShowSerialData();
mySerial.print(" \"_cXwr5LE8qW4a296O-cDwOUvfddFer5pGmaRigPsiO0");//pachubeapikey
delay(500);
ShowSerialData();
mySerial.print("jEB9OjK-W6vej56j9ItaSlIac-hgbQjxExuveD95yc8BttXc");//pachubeapikey
delay(500);
ShowSerialData();
mySerial.print("Z7_seZqLVjeCOmNbEXUva45t6FL8AxOcuNSsQS\",\"body\":");
delay(500);
ShowSerialData();
mySerial.print(" \"version\": \"1.0.0\",\"datastreams\": ");
delay(500);
ShowSerialData();
mySerial.println("[\"id\": \"01\",\"current_value\": \"" + barometer + "\",");
delay(500);
ShowSerialData();
mySerial.println("\"id\": \"02\",\"current_value\": \"" + humidity + "\",");
delay(500);
ShowSerialData();
mySerial.println("\"id\": \"03\",\"current_value\": \"" + moisture + "\",");
delay(500);
ShowSerialData();
mySerial.println("\"id\": \"04\",\"current_value\": \"" + temperature + "\"],\"token\": \"lee\"");

delay(500);
ShowSerialData();

mySerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
mySerial.println();

ShowSerialData();

mySerial.println("AT+CIPCLOSE");//close the connection
delay(100);
ShowSerialData();

}
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}

Note that although this is called "send2Pachube" it uses the Cosm API, which still works.
The section following the line
mySerial.println("AT+CIPSEND");

is where the HTTP gets formulated. I've assembled the string in the example code and it looks odd. The API key goes on about four times longer than it should. I'm not sure what all those colons are doing in there, are they a String operator? Can anyone give me an example of an HTTP PUT request for Cosm or Xively that illustrates how this string should be assembled?
Thanks

I've got a working solution to this issue. Here's the values you can edit and the function:
String FEED = "YOUR_FEED";
String KEY = "YOUR_API_KEY";
String DATASTREAM1 = "YOUR_DATASTREAM1_NAME";
Int VALUE1 = YOUR_VALUE1;
String DATASTREAM2 = "YOUR_DATASTREAM2_NAME";
Int VALUE2 = YOUR_VALUE2;

void send2Cosm()
{
mySerial.println("AT+CGATT?");
delay(100);
ShowSerialData();
mySerial.println("AT+CSTT=\"CMNET\"");//start task and setting the APN,
delay(1000);
ShowSerialData();
mySerial.println("AT+CIICR");//bring up wireless connection
delay(300);
ShowSerialData();
mySerial.println("AT+CIFSR");//get local IP adress
delay(2000);
ShowSerialData();
mySerial.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
mySerial.println("AT+CIPSTART=\"tcp\",\"api.cosm.com\",\"8081\"");//start up the connection
delay(2000);
ShowSerialData();
mySerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();

mySerial.print("{\"method\": \"put\",\"resource\": \"/feeds/" + FEED + "/\",\"params\"");
delay(500);
ShowSerialData();
mySerial.print(": {},\"headers\": {\"X-ApiKey\":");
delay(500);
ShowSerialData();
mySerial.print("\"" + KEY + "\"},\"body\":");
delay(500);
ShowSerialData();
mySerial.print(" {\"version\": \"1.0.0\",\"datastreams\":");
delay(500);
ShowSerialData();
mySerial.print("[{\"id\": \"" + DATASTREAM1 + "\",\"current_value\": \"");
mySerial.print(VALUE1);
delay(500);
ShowSerialData();
mySerial.print("\"},{\"id\": \"" + DATASTREAM2 + "\",\"current_value\": \"");
mySerial.print(VALUE2);
delay(500);
ShowSerialData();
mySerial.println("\"}]}}");
delay(500);
ShowSerialData();

mySerial.println((char)26); //sending = ctrl+z
delay(5000);//waitting for reply, important! the time is base on the condition of internet
mySerial.println();

ShowSerialData();

mySerial.println("AT+CIPCLOSE");//close the connection
delay(100);
ShowSerialData();

}

void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}

To answer part of my question: no, the colons aren't a String operator, they're part of the HTML. Here's an example of the formed URL that gets sent:
{"method": "put","resource": "/feeds/YOUR_FEED/","params": {},"headers": {"X-ApiKey":"YOUR_API"},"body": {"version": "1.0.0","datastreams":[{"id": "DATASTREAM1","current_value": "VALUE1"},{"id": "DATASTREAM2","current_value": "VALUE2"}]}}

This code updates my feed but after several hours the updates stop. I'm still troubleshooting this new problem so I'm not 100% sure that this code is good. I will post back if the problem's in here.


text:
Custom built Arduino is not working - double blinks
I've made a home-made Arduino based on this video. The problem is that I can't upload anything, it doesn't react, only the LED double blinks in every second. What does that mean? How to fix it? Thanks.
Update:

This is surely impossible to answer without seeing what you did. Presumably you did something different from what is in the video, what that is, is impossible to say. I suggest posting a very clear photograph, at the very least.

Thanks for the quick reply - I've just provided one. Hope that helps. Thanks :)

Did you bought atmega chip with bootloader already on it?

I guess so - at least according to the Ebay seller.

It's a reasonably clear photo (another couple would help) however I do see at least one major problem. Pin 8 (and pin 22) are Ground, but I don't see any wires running to that. Also the 22 pF (or similar) capacitors connected to the crystal should have their other sides grounded.
I suggest you look at my page Breadboard Arduino which has clear photos and wiring guides. In particular:

Notice the ground wire, and how the capacitors are connected.
I suggest you double-check all wiring, and make sure it is very similar to this:

I've just checked it but the 22s are already grounded to pin 8 as that is a ground. I updated that area anyway according to your photo but having the same issue. I've built this entire stuff for 3 times but getting the same result. :(

Yes, but pin 8 should have a ground wire. You shouldn't rely on it being grounded through the chip. Also the capacitor in series with reset looks a lot larger than 0.1 µF.

Ohh I see, mine is a 100uF one. I mixed up with the 100nF. The smallest I have now is a 1uF. I wish I could just quickly "download" one ...

3D printer? And a bit of aluminium foil? Just remove the wire leading to the capacitor. When the upload starts briefly ground it to reset the processor (a quick tap) and then un-ground it.

I haven't got any 3D printer but an oven and a hair dryer. Am I still good?


text:
MicroSD interfering with ISP programming
I have a microSD connected to an Arduino and I can't program it over ISP without removing the SD card. Does anybody know how to prevent the SD card from interfering with the ISP programming?
Details:
This is the microSD breakout: https://www.adafruit.com/products/254
I'm using an ATMEGA328P at 3.3V 8MHz.
I'm not using a bootloader and, for several reasons, I can't use the serial port for programming.
Thanks!

Have you tried putting a 10k resistor from CS to +3.3V? What pin is CS tied to?

Because the SD card is an SPI device it shares the same pins as the ISP interface. The only way to not have the SD card interfere with the ISP is to not have the SD card connected.
As you have seen, that can be achieved by removing the card.
It can also be achieved by adding a tri-state buffer between the MCU and the card so the MCU only connects the card to the SPI bus when it is ready to use it - under default operation the card is disconnected.

Would you then need to disable the tristate buffer before programming the MCU?

The buffer would, if you wired it right, default to off when the MCU stops actively setting it to on.

This sounds great! Thanks for the tip. (Do you have any recommendations for what buffer I should use?)

You can also use the buffer as your level shifter as an added bonus. Look in the 74hc series for a quad tristate noninverting buffer.

You should not need to disconnect the card - provided programming is being done at a compatible voltage level, inactivating the card's chip select should be sufficient.  SPI devices are, after all, designed to share the SCK, MOSI, and MISO signals, and so should not drive MISO when they are not slave selected.

@ChrisStratton there are two flaws in that argument... 1: most cheap card shields lack a pull up on CS, so while you are programming the CS is floating. 2: SD cards aren't 100% SPI compatible. They have times where the CS is held high while being clocked. They are notorious for not always playing well with other devices on the bus - care has to be taken with them.

The poster isn't using a shield, but a PCB wired to something that appears to not be a complete Arduino, adding a resistor (at the wiring interface if nowhere else) is trivial (though it would be with a shield as well).  Many SPI devices can continue operation after the select returns high, that's quite different than their driving MISO when it has never, or at least not recently, been low.  What could make things tricky would be if the existing sketch kicks off an SPI operation that then gets interrupted by entering programming mode.  But your "the only way" opener seems inaccurate.

@ChrisStratton Yes, many (most) SPI devices keep running with CS raised. No other SPI devices require the clock to be run with CS raised. This is a fundamental difference between SD cards and true SPI devices that is known to cause problems in the field. And then of course you have the fuzziness of what constitutes the SD card SPI interface, implemented differently by different mfrs with many cheap Chinese mfrs cutting corners, etc. I have seen some SD cards that even never tri-state their MISO pin. As a general rule of thumb I always put SD cards on their own dedicated SPI channel.

That's useful detail - your answer would be a lot better if its actual body included this explanation of why you recommend handling an SD card uniquely, as opposed to as an ordinary SPI device.

I had the exact same problem, also using Arduino (Atmega 328P). I have an sd card module with a different layout, but also with a level shifter. My circuit is running at 5V (which is appropriate when using a level shifter).

To resolve the issue I just installed a pullup resistor (10k) on my own board to the chip select line of the sd module, which keeps the sd card unselected while programming the MCU. Now it works.

There seems to be no pullup integrated into the module. Hence the CS is low during programming (without the pullup), the sd card thinks it should answer the SPI commands, and so interferes with the communication to the MCU, which is why programming over an ISP fails.

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


text:
MPU 6050 stuck on same values
I'm having a problem with my MPU6050. I'm using PID to speed up a motor with the MPU values. What could the problem be?
Here is a link to a previous question that I asked concerning a problem with pid: PID not working correctly
These are the values that I'm getting, which repeat forever. The values are:

motor speed;
the value that changes the motor speed;
the MPU value;
the change that PID made.

0.00
0
10900
4800

0.00
0
10900
4800

Here is the code itself.
int16_t ax, ay, az;

double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp,Ki,Kd, DIRECT);

void setup() {
 Input = analogRead(ax);
  Setpoint = 100;
  //turn the PID on
   myPID.SetMode(AUTOMATIC);
}

void loop() {
 accelgyro.getAcceleration(&ax, &ay, &az);
  int a=ax+10900;
//Here I set the used variable to around 0. ax is actually around -10900
//This is always true, this won't be in the final code. This is just making        it work.

if(1) {
 int val;
  val = map(a, -1300, 1300, 0, 1023);
   Input = val;
    myPID.Compute();
     Serial.println(Output);

digitalWrite(motorPin2, HIGH);
Serial.print("\t");
Serial.println(ax);
Serial.print("\t");
Serial.println(a);
Serial.print("\t");
Serial.println(val);
     }
}

Please post a Minimal, Complete, and Verifiable example - I don't see, for example, where you are printing the other numbers. And why do you do an analogRead in setup?

I added the prints. I think  my teacher did the analogread. Not sure if its supposed to be there. This code has worked before. I think its the pins thats wrong or something.

Let's deconstruct this down to a simple example which we can test without the MPU6050:
#include <PID_v1.h>

double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp = 2, Ki = 5, Kd = 1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup() {
  Setpoint = 100;
  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  Serial.begin (115200);
  Serial.println (F("\n\nStarting\n\n"));
}

void loop() {
  int a = 0;
  int val = map(a, -1300, 1300, 0, 1023);
  Input = val;
  myPID.Compute();
  Serial.print (F("Input = "));
  Serial.println(Input);
  Serial.print (F("Setpoint = "));
  Serial.println(Setpoint);
  Serial.print (F("Output = "));
  Serial.println(Output);
  Serial.println();
  delay (300);
}

Output:
Starting

Input = 511.00
Setpoint = 100.00
Output = 0.00

Input = 511.00
Setpoint = 100.00
Output = 0.00

Input = 511.00
Setpoint = 100.00
Output = 0.00

Input = 511.00
Setpoint = 100.00
Output = 0.00

Indeed it isn't changing. Let's analyze why:

The input is 511
The setpoint is 100
Therefore the error is 100 - 511 = -411
Disregarding (for the moment) the integral and differential terms, you have a proportional term of 2 (Kp) so the algorithm tries to output 2 * Error
Output would be 2 * -411 = -822
However the maximum and minimum limits default to 0 to 255, and thus the output is clamped to 0.
The algorithm outputs 0.
And the next time it does the same thing.

There is a function SetOutputLimits which can be used to change the default minimum and maximum output values.
The Ki and Kd values might eventually have an impact, but you won't notice anything with the output clamped to zero.
For example, adding this line in setup gives different results:
  myPID.SetOutputLimits (-5000, 5000);

Result:
Starting

Input = 511.00
Setpoint = 100.00
Output = -5000.00

Input = 511.00
Setpoint = 100.00
Output = -1233.00

Input = 511.00
Setpoint = 100.00
Output = -1438.50

Input = 511.00
Setpoint = 100.00
Output = -1644.00

Input = 511.00
Setpoint = 100.00
Output = -1849.50

Input = 511.00
Setpoint = 100.00
Output = -2055.00

Input = 511.00
Setpoint = 100.00
Output = -2260.50

Input = 511.00
Setpoint = 100.00
Output = -2466.00

Whether they are valid limits depend on what you are attempting to do exactly.

Im still having the problem that the mpu's value doesnt change

The problem was that I had the SCL and SDA pins connected to the wrong Arduino pins.
Sorry for bothering your time. Thanks for the tips.

authors: محمدرضا کیانی


text:
SD card initialization fails randomly
I have a SD card reader that is working fine exept that sometimes SD.begin fails for no apparent reason.
To work around this issue I have put the SD.begin in a while loop and then I display the error on my LCD. When the error happens I then remove and reinsert the card witch works usualy on the first or second try. I have never seen any problem ones the card is initilized.
Does anyone has any idea what might be the problem?

Which reader? Link? Possibly you are running too fast a clock for it. There are means of slowing down the SD library.

https://www.arduino.cc/en/Main/GTFT I do not use the TFT but only the SD card reader. If SPI where to fast should I not see random errors after a successful init when reading and writing to it to?

I don't know. There have been reports that some SD cards work better than others. During initialization there might be negotiation about which protocol to use. Possibly try adding a small delay in setup to give the card time to power up.

I have seen SD cards that do not like this section of code:
  // command to go idle in SPI mode
  while (cardCommand(CMD0, 0) != R1_IDLE_STATE) {
    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
      error(SD_CARD_ERROR_CMD0);
      goto fail;
    }
  }

Some SD cards (mine, of course) seem to need a little quiet time to finish their INIT process.  Adding a delay of <something> made the INIT process complete successfully, first time through the loop.
I'm guessing that the SD card spends so much time handling the repeated CMD0 commands (continuously sent by above loop) that they don't get to spend time on the INIT process.  IIRC, the standard says the card is allowed to take up to 2 seconds to INIT (!).  I can't recall, but I think I tried 150ms or so:
  // command to go idle in SPI mode
  while (cardCommand(CMD0, 0) != R1_IDLE_STATE) {
    delay( 150 ); // let SD get some time to work
    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
      error(SD_CARD_ERROR_CMD0);
      goto fail;
    }
  }

I do recall that reinserting the card would sometimes make it work.  I have suggested this to at least one SD card library maintainer, but I think we're all reluctant to impose a delay on all cards.  OTOH, it is just during ::begin.
It might work for you, though.  The above snippet is from SdSpiCard.cpp, but you may have to go looking for it in other places, depending on which library and version you're using.


text:
Help with a rather specific implementation of FFT Library?
So, I guess what I'm trying to do here is properly understand the FFT library posted here by Open Music Labs, done in C++. I believe I understand the Fourier transform, but the FFT has some nuance that I'm not quite familiar with. From what I understand, the FFT takes a amplitude vs. time signal and transforms it into its constituent frequencies like a normal Fourier transform, but it only does so at given points that break down the signal into the Arduino's clock speed divided by the number of bins decided on, for the sake of efficiency. Thus each bin actually accounts for a number of frequencies that is also equal to the clock speed divided by bin number. I'm correct so far, right?
So here's my question. I have a very specific application of the FFT that requires reading only frequencies at roughly 0-100 Hz. Everything else I don't need, and I want to know how to achieve such high resolution. I imagine that because the number of bins seems to be capped at around 512, that there must be some sort of way to decrease the clock speed to an exorbitantly low number in order to read these frequencies. How might I go about doing that? Or maybe there is a better way to apply the transform to the data at such low frequencies through some other method outside of FFT?
Second, I'm wondering how performing multiple FFTs simultaneously will affect performance, and if there is some way I can export this data to another program in order to do the heavy lifting regarding data storage, seeing as I imagine performing many FFTs all at once will decimate the available memory on the Arduino itself if all of those values aren't being kept on my computer.
Thanks in advance for any insight you guys might be able to provide

You are mixing things. There is the “Fourier transform” (FT), the “discrete Fourier transform” (DFT) and the “fast Fourier transform” (FFT). DFT is a generalization of FT for finite sets of data points. FFT is an efficient algorithm for computing a DFT when the number of data points is a power of two. The binning is a feature of the DFT arising from the finite nature of your data set, it has nothing to do with efficiency. “0-100 Hz” is a frequency range, not a resolution. What resolution do you need?

As Edgar has mentioned you are confusing things slightly.
First there is your sampling frequency. According to the Shannon-Nyquist theorem that is at a minimum of 2x the maximum frequency in your signal. So that is 2x100 = 200Hz. That's the number of samples per second in your sample set.
Secondly is your sample size, which is directly related to the FFT bucket size. For every two samples you can get one bucket. The more samples you have the more buckets you have, and the higher the resolution each bucket is. But for FFT to work you need a power-of-two sized sample set. That means 2, 4, 8, 16 etc samples.  So 256 samples would give you 128 buckets. That would be a little under 1Hz per bucket.
To make things cleaner though you can back-apply the last calculation to the first and get them to match. 256 samples at 256 samples per second will give you 128 buckets covering 0-128Hz so 1Hz per bucket.  Double that to 512 samples and you get 256 buckets at 0.5Hz per bucket. Double it again and you get double the resolution again.
The main speed issue that you will come across is not the time taken to do the FFT, but the time taken to capture your sample set. 256 samples at 256 samples per secod will, of course, take 1 second to capture. 512 samples will be 2 seconds, etc. Far longer than a decent FFT takes to calculate.

Ok, that makes it a bit clearer. So, if I follow correctly, it seems like taking a half decent fft at such low frequencies is not a practicable option because increasing sampling rate will up the range of sampled frequencies, thus decreasing resolution, but if I leave it where it is at 256, then it would not be sampling fast enough to achieve a real-time readout. So it seems there has to be a better way to achieve the same effect of at least a 1hz resolution, because, as I understand it now, the Fourier transform is inherently limited for this application.


text:
Breadboard for kids
I am interested in teaching young kids how to build arduino projects. I was thinking that using a breadboard may be difficult for them, as the holes are all very close together. It is easy to put the pins in the wrong hole.
Are there any breadboards with larger hole spacings that could make it easier to use for kids?

Honestly, I think kids would be very likely to plug in things wrongly, even if you've got an awfull lot of spacing.
This might be due the fact that they don't really understand why/how to wire stuff.
I would suggest adding some dedicated irreversible connectors with GND&5V to your board. And add the same kind of connector to all the peripherals.
You should also add a current limiting resistor on every Arduino-output pin. From there, you can add some nice "banana-connectors" as signal lines to all the devices you want them to be able to control.

What should they be able to connect or learn?

I'd also suggest that you'd use Ruggeduino's http://www.rugged-circuits.com/ruggeduino/, they're meant to be tolerant to errors.

What age? How secure?

The problem (probably) isn't only because it's too small, wiring can be hard to understand.
I think this might be a solution:

It'll cost you some work. But it will get difficult for them to wire it wrongly.
Also, I believe coloring them, will make the kids understand it much better. This way they would also be less likely to short out pins etc. Saving you some rangers/arduinos.
Be sure that the power-connectors are not reversible. And you should use a separated supply (with overcurrent protection and what not) and tie the GND to the arduino GND. This way you could even use the supply power for heavier devices.
I'm not a 100% sure on the resistors though, they might interfere with some things you want to make/show.
Maybe even add blue color for inputs and yellow for outputs (or whatever the standard is). Or you might even make generic connectors, like on the Lego NXT robots, that's some really easy wiring! http://www.philohome.com/nxtldraw/NXTkitLDview.jpg
Or check out projects like: "LittleBits Arduino".
https://s3.amazonaws.com/lb-spree/spree/products/2003/large/ArduinoDetail4.png?1423167488
And, check http://www.rugged-circuits.com/ruggeduino/ on 10-ways to destroy your arduino. If you take these things into mind, you can make a pretty solid Arduino, so that wrong wiring won't lead to any damaged Arduino's etc.

Breadboards are made to work with components of a standard size - a breadboard with larger hole spacing would not be able to fit standard through-hole chips. I have never seen such an item.
Having said that, I have had a lot of success using alligator clips. You can clip them directly on to wires for LEDs, resistors, capacitors, so long as you make sure they legs/clips don't touch.
Then there are made-for-children systems, snap-together, like http://www.vk3bq.com/2013/08/17/snap-circuits-electronics-kits/ or http://mashable.com/2013/05/21/lightup-magnetic-building-blocks/#t5Kq_yIDpaqr

I have one of those snap-circuit systems right here. However it probably doesn't lend itself to Arduino projects.

or

or
Maybe use something like Littlebits, which uses magnets, but is kind of expensive.

Build your own breadboard!
Literally, a wooden board with a grid of small woodscrews screwed into it, each screw holding down a cup washer.
Connections are made by trapping component leads and wires under the edge of the cup washer before screwing it down.
You need components with reasonably long leads, and it might still be necessary to solder longer wires to the leads in some cases.
I am told that in the olde days, this is how hobbyists used to do it...
Here's a link to an example (I read a copy of this book as a kid):
http://www.mds975.co.uk/Content/george_dobbs_trf_radio.html

Alternatively you could use something like an "Electronics springboard" https://learn.sparkfun.com/tutorials/recreating-classic-electronics-kits.
By pushing the spring sideways, you get some space to push in the wires. When you release the spring, it will put tension on the wire, and trap it.

I just wanted to mention that your example is a very good read, it's an old source (which makes it even better) but is very informative.


text:
Bluetooth HC-05 Library for Proteus
I m working on a project in which I am using HC04 module so can anyone give me any Arduino Library for Proteus which have HC05 in it. Or tell me how to use HC05 in Proteus.
Thanks.

I have found this Bluetooth Library for Proteus. Thanks for helping me out guys. I am posting it here so that others can also get benefit out of it.
Thanks.

I don't know Proteus, but I think HC05 a bluetooth module? If so, the module interface from HC05 <==> arduino is done through Serial (UART) communication.
Arduino has built in support for this - you don't need any special libraries besides SoftwareSerial.
wire up the module as such:

Then run the following code:
#include <SoftwareSerial.h>

#define rxPin 10 // connected to TX pin of HC05
#define txPin 11 // connected to RX pin of HC05

SoftwareSerial mySerial(rxPin, txPin); // RX, TX
char bt;

void setup() {
  Serial.begin(9600);
  Serial.println("Hello");

  mySerial.begin(9600);
  mySerial.println("World");
}

void loop(){
  while(mySerial.available()){
    bt = mySerial.read();
    Serial.print(bt);
  }

  while(Serial.available()){
   bt= Serial.read();
   mySerial.print(bt);
  }
}

There is no Proteus Library for HC05. (Not one I know of.)
Now, your HC05 is a serial device i.e. it acts as a Serial monitor. and fortunately there is Serial Monitor in Proteus. You can use that.
Here, Have a look.
P.S. if you are using ISIS 7.x. there is a thing to be noted. You have placed a serial monitor and connected to arduino and you started execution and its working fine. Now, what happens sometimes is that when you stop execution and start again, serial monitor might not work. No need to worry about. Stop execution, delete that serial monitor and place a new.That will work.


text:
"'Serial' does not name a type" error
I'm getting a "'Serial' does not name a type" error when this program is compiled. I need for the 8 channels of voltage to be displayed. I'm sure it's a simple fix, however I'm still learning Arduino programming. I thank you for your help.
int pin_Out_S0 = 8;
int pin_Out_S1 = 9;
int pin_Out_S2 = 10;
int pin_In_Mux1 = A0;
int Mux1_State[8] = {0};
//float Mux1_State[i] =0;
int RawValue=0;
float Voltage = 0;
void setup() {
  pinMode(pin_Out_S0, OUTPUT);
  pinMode(pin_Out_S1, OUTPUT);
  pinMode(pin_Out_S2, OUTPUT);
  pinMode(pin_In_Mux1, INPUT);
  Serial.begin(9600);
}

void loop() {
 RawValue = analogRead(pin_In_Mux1);
 Voltage = (RawValue * 5.0) / 1024; //scale the ADC
  updateMux1();
  //Serial.println(Mux1_State);
  for(int i = 0; i < 8; i ++) {
    if(i == 7) {
      Serial.println(Mux1_State[i]);
    } else {
      Serial.print(Mux1_State[i]);
      Serial.print(",");
      //vout = (value * 5.0) / 1024.0;
    }
  }
}

void updateMux1 () {
  for (int i = 0; i < 8; i++){
    digitalWrite(pin_Out_S0, HIGH && (i & B00000001));
    digitalWrite(pin_Out_S1, HIGH && (i & B00000010));
    digitalWrite(pin_Out_S2, HIGH && (i & B00000100));
    Mux1_State[i] = analogRead(pin_In_Mux1);
  }
}
Serial.print("Raw  Value = " );
Serial.print(RawValue);

Tom, StackExchange has got built-in code formatting and syntax colorization.  Paste raw code, select it in the editor, click the {} button on the toolbar.

Things like pin_Out_S0 need to be declared, otherwise they will generate error messages.

Your last two lines are not in any function. This confuses the compiler. You need to move those two statements inside a function.
Because those statements refer to RawValue, I'm guessing you want to put them in loop(), where RawValue is being updated.
Also, remember that the IDE will tell you on which line the error is, which is helpful when debugging compilation errors.

Please put these lines inside the loop() function block:
Serial.print("Raw  Value = " );
Serial.print(RawValue);

Should look something like:
void loop() {
 RawValue = analogRead(pin_In_Mux1);
 Voltage = (RawValue * 5.0) / 1024; //scale the ADC
  updateMux1();
  //Serial.println(Mux1_State);
  for(int i = 0; i < 8; i ++) {
    if(i == 7) {
      Serial.println(Mux1_State[i]);
    } else {
      Serial.print(Mux1_State[i]);
      Serial.print(",");
      //vout = (value * 5.0) / 1024.0;
    }
  }
  Serial.print("Raw  Value = " );
  Serial.print(RawValue);
}

That should at least remove the first issue with your code.
Cheers!

In addition to the good answers by Mikael and Uint, everything needs to be inside {curly braces} otherwise the IDE does not know where it belongs. If you didn't want the last 2 lines in your loop segment you could put them in a separate void xxxx () section to be called when the time is right (by using an ISR with an enableinterrupt function for example).


text:
How to know if my Bluetooth HC-05 is connected through serial monitor
I want to connect a Bluetooth module to arduino and check if my module is connected or not.. Through serial monitor. Is there and particular code to connect with that?

i think thats not the answer what he want...
.
he (actually me :D) want to know is the bluetooth connect or disconnect when sistem is running, in my program if bluetooth connect i'll send using bluetooth, if not i'll send using sim800,,,,
.
if i pull the KEY pin to vcc, bluetooth be ATCommand Mode, i hope==

If your board is actually a HC-05, you can

Pull the KEY pin to Vcc (see note)
Write the serial command AT on the serial interface
Look at the output: if you receive AT or OK then the module is connected, otherwise it is not

Note: The key pin is the number 34 on the SMT module (with the antenna pointing upwards, its the pin in the top-right corner). If you have a THT module (so the one with about 6 pins) MAYBE this pin is connected to one of the pins you don't usually use (they are named EN, STATE, ...). Check with a multimeter if it is connected to one of these. If it is not, then you'll have to solder a wire from it to an arduino pin.
If, on the other hand, your board is a HC-06 (almost identical to HC-05, but with a different firmware - it is a slave-only bt device), then keep it disconnected from the master and perform steps 2 and 3: when not connected, in fact, the HC-06 is already in AT mode.
More information on this webpage


text:
How to use strtok() and strstr() with arduino?
Can anyone explain how things like strtok() and strstr() can be used to provide a numeric value for a substring location position within the mainstring array.
I've tried to understand from the C++ examples, but their 'position' locations of the substring within the mainstring (which I need) are returned in C++ as %d variables, whereas all I can get returned by the arduino 'char * pointer=' is the actual substring chars if they exist, rather than a number for their start position locations within the mainstring.
The C++ examples show that it is possible to discover the position values from %d,  but how can I get that equivalent position value in arduino?
I want to be able to parse a char header[30] array for occurances of things like "s=123" and "d=789" in order to extract and assign the specified values to any appropriate variables (source or destination etc).

If you have a pointer to a substring (of a null terminate C string, not a C++ String) stored literally within the original, you can determine the offset by subtracting the pointers.  Pointer math is a key C concept, but it can also be a tricky one, with many pitfalls for the unwary.

So is there an effective way of parsing things out from char arrays?  (perhaps that's the question I should have asked)

It sounds like sscanf() is way more appropriate for what you want to do than any str*() functions.

You have to define a format for the header you will be parsing and stick to that format. Say this is a sample header terminated by null:
s=123 d=789 e=463

A common property of each assignment in the string is the '=' symbol. You can use that to locate each variable and the value assigned to it. strchr is the function to use to locate a single character. Once you locate the = character, you move back and then forward along the array to obtain the variable and its value.
I will make some assumptions here: that your variable names will be single character, that numbers assigned will be no bigger than ints, and a space character is used to separate assignments.
char header[] = "s=123 d=789 e=463";

int d, s, e;   //your variables to be assigned to
char * ptr = header;
char * eq = NULL; //locate assmts
int * num = NULL; //just for starters
while (1){
  eq = strchr(ptr, '=');
  ptr = eq; // update the pointer
  if (ptr == NULL) // found no = chars
    break;
  switch (*(ptr - 1)){
    case 'd':    //all the possible variables
      num = &d; break;
    case 's':
      num = &s; break;
    case 'e':
      num = &e; break;
    default:   //unknown variable
      num = NULL;
  }
  ptr++;
  if (num == NULL) //unrecognized var
    continue;   // locate next = char
  *num = 0;
  while (*ptr && (*ptr != ' ')){  // while space or end of string not yet reached
    *num *= 10;  // extract each int
    *num += *ptr - '0';
    ptr++;
  }
}

Serial.println(d);  //now contains the numbers in the header
Serial.println(s);
Serial.println(e);

Untested but it should work for the header sample I gave.

Your answer is excellent Mr T, thank you very much indeed.

@Electroguard You're welcome. I've seen your other question. You may have to get rid of strchr in the receiver code and do the searching yourself, if you want to implement checksums efficiently.


text:
Trying to pass a char to software serial with a button press
Good day everyone,
I'm returning to the Arduino world after my a 3 year hiatus following the birth of my son.
I'm trying to push a button connected to pin 2 and have that send a 'd' to SoftwareSerial on pins 10,11. This should trigger an output back from the device connected to the SoftwareSerial.
I'm encountering an issue:
When I press the button it sends about 15 d's. I would like to limit this to just one char per button press, I attempted to build an if statement but it seems to ignore the conditions.
#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial portOne(10, 11);
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int button1State = 0;

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Start each software serial port
  portOne.begin(4800);
  while (!portOne) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}

// the loop function runs over and over again forever
void loop() {
  int Once = 0;
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH ) {
    if (Once == 0) {
      Once = 1;
      // turn LED on:
      digitalWrite(ledPin, HIGH);
      // send D to Radio
      portOne.write("d");
      Serial.write("d");
      Serial.print(Once);
      Serial.println();
      delay(1);
    }
  }
  else (buttonState == LOW) {
    // turn LED off:
    Once = 0;

    digitalWrite(ledPin, LOW);

  }
  portOne.listen();
  // while there is data coming in, read it
  // and send to the hardware serial port:
  while (portOne.available() > 0) {
    char inByte = portOne.read();
    Serial.print(inByte);
  }
}

There's built in code formatting in the post editor, use it to format your code correctly. It looks like {}.

You should debounce your button. 2) You should qualify Once as static, otherwise it's reset to zero (actually, recreated) every time you enter loop().

Thank you Edgar, qualifying Once as static fixed it! I didn't realize it was getting cleared everytime, driving me crazy!

Now comes the second part. When I first boot up the device connected to portOne I see the boot-up message, however after I press the switch and see d1 on the serial monitor I get nothing back from the other device.

When I connect the device directly to my computer and press d I see a five line status output from the device. Based on my Sketch that should be echo'd back to the serial monitor however I see nothing but the d1, any ideas?

As Edgar stated my issue was I didn't make the Once variable static
"1) You should debounce your button. 2) You should qualify Once as static, otherwise it's reset to zero (actually, recreated) every time you enter loop()."

As pointed out by Edgar you should debounce the button. Perhaps increasing the delay() should do the trick.
Try with 100-200 milliseconds.
With this edit you can delete Once unless you are planning on using it somewhere else.

If he deletes Once, it will repeatedly send characters when the button is held down.


text:
Arduino serial hex decimal values code
I'm trying to send heximal values from arduino to PZEM-04 power module (it shows voltage, current and ect.) over serial communication in heximal format and get values in decimal format for further actions with them. Any help with the code please?
One of the commands:
Send command: B4 C0 A8 01 01 00 1E
Reply data: A4 00 00 00 00 00 A4
Edit: I am connecting wires from PZEM module TTL to arduino "serial port": TX-RX, RX-TX, VCC-VCC, GND-GND, so it's serial communication..
    PZEM module: http://www.aliexpress.com/store/product/PEACEFAIR-AC-100A-Electric-power-monitoring-and-communication-module-power-meter-power-energy-Volt-Ammeter/1773456_32373508101.html

Please add link to communication format/protocol.

I just added more information.

What code have you tried?

That for the extra info. I read this differently. You should send binary data with the hexadecimal values.

A possible implementation of the protocol using serial read/write of binary data (command and response).
void send(Stream& ios, uint8_t cmd[6])
{
  uint8_t sum = 0;
  for (int i = 0; i < 6; i++) {
    uint8_t c = cmd[i];
    sum += c;
    ios.print((char) c);
  }
  ios.print((char) sum);
}

bool recv(Stream& ios, uint8_t res[6])
{
  uint8_t sum = 0;
  uint8_t c;
  for (int i = 0; i < 6; i++) {
    while (!ios.available());
    c = ios.read();
    sum += c;
    res[i] = c;
  }
  while (!ios.available());
  c = ios.read();
  return (sum == c);
}

void setup()
{
  Serial.begin(57600);
  while (!Serial);

  uint8_t cmd[] = { 0xB4, 0xC0, 0xA8, 0x01, 0x01, 0x00 };
  uint8_t res[6];
  send(Serial, cmd);
  recv(Serial, res);
}

void loop()
{
}

Cheers!

Thank you very much Mikael Patel, you cleared it a lot to me. Now it's only needed to analize code, and insert other commands. After that I'm going to connect bluetooth module and send values to smartphone somehow, haha. Thanks again!