text:
NRF24l01+ works only when touching its antenna
I have two simple NRF24l01+ (with range of 200m) and two NRF24l01+ with range of 1km.and two socket adapter.
 or what I have
and I have two good library with names RF24 and RF24-master . problem is that I tried a lot of combinations and just one of them worked : two simple NRF24l01+ with their socket adapter and with Getting started example of RF24-master library and only when I touch the antenna of the NRF it can transmit the package and get response. whats the problem? thats with me or my modules have problem?
I've also readed the datasheet and wrote my own code for modules.but it just worked with 1km range NRF24l01+ and most of the packages have failed.
my own code for transmitter :
#include <SPI.h>

#define cePin 7
#define csnPin 8

//#define cePin D0
//#define csnPin D1

int data = 7;

void IRQ() {
  Serial.println("STATUS register from IRQ ISR :  ");
  digitalWrite(csnPin, 0);
  SPI.transfer(0x07);
  delay(10);
  Serial.println(SPI.transfer(0xff), BIN);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x08);
  delay(10);
  Serial.println(SPI.transfer(0xff), BIN);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x07 + 0x20);
  delay(10);
  SPI.transfer(0xff);
  delay(10);
  digitalWrite(csnPin, 1);
}

void NRF_transmitterBegin() {

  //reading
  /*digitalWrite(csnPin, 0);
    SPI.transfer(0x00);
    delay(10);
    Serial.println(SPI.transfer(0xff), BIN);
    delay(10);
    digitalWrite(csnPin, 1);*/

  pinMode(cePin, OUTPUT);  //CE
  pinMode(csnPin, OUTPUT);  //CSN
  delay(100);
  digitalWrite(csnPin, 1);
  digitalWrite(cePin, 0);

  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  SPI.begin();
  delay(1000);

  digitalWrite(csnPin, 0);   //flush TX_FIFO
  SPI.transfer(0xe1);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);   //flush RX_FIFO
  SPI.transfer(0xe2);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x07 + 0x20);
  delay(10);
  SPI.transfer(0xf0);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x00 + 0x20);
  delay(10);
  SPI.transfer(0x0e);
  delay(10);
  digitalWrite(csnPin, 1);
  delay(10);

  /*digitalWrite(csnPin, 0);
    SPI.transfer(0x11 + 0x20);
    delay(10);
    SPI.transfer(0x3f);
    delay(10);
    digitalWrite(csnPin, 1);*/

  //Down for DYNPL
  digitalWrite(csnPin, 0);
  SPI.transfer(0x1c + 0x20);
  delay(10);
  SPI.transfer(0x01);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x1d + 0x20);
  delay(10);
  SPI.transfer(0x04);
  delay(10);
  digitalWrite(csnPin, 1);
  //Up for DYNPL

  digitalWrite(csnPin, 0);
  SPI.transfer(0x01 + 0x20);
  delay(10);
  SPI.transfer(0x3f);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x02 + 0x20);
  delay(10);
  SPI.transfer(0x03);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x03 + 0x20);
  delay(10);
  SPI.transfer(0x03);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x04 + 0x20);
  delay(10);
  SPI.transfer(0xff);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x05 + 0x20);
  delay(10);
  SPI.transfer(0x4c);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x06 + 0x20);
  delay(10);
  SPI.transfer(0x06);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x0a + 0x20);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x10 + 0x20);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  digitalWrite(csnPin, 1);

  attachInterrupt(digitalPinToInterrupt(2), IRQ, FALLING);
  delay(10);

}

void NRF_transmit(int whatIsData , float data , float hum) {    //hum is used just for temp&humidity
  /*
     byte 0 says what is our data:  1 -> data and humidity    2 -> movement   3 -> gas

     1(float) :   byte 1 -> integer part of temp  byte 2 -> fractional part of temp   byte 3 -> integer part of humidity    byte 4 -> fractional part of humidity    byte 5 -> %battery
     2(binary) :  byte 1 -> %battery
     3(float) :   byte 1 -> integer part of gas   byte 2 -> fractional part of gas    byte 3 -> %battery

     %battery feature is in progress ...
  */

  int byte0 = 0 , byte1 = 0 , byte2 = 0 , byte3 = 0 , byte4 = 0 , byte5 = 0;
  float buf = 0;

  byte0 = whatIsData;

  switch (whatIsData) {
    case 1: {

        byte1 = data;
        buf = data - byte1;
        byte2 = buf * 10;

        byte3 = hum;
        buf = hum - byte3;
        byte4 = buf * 10;

        break;
      }
    case 2: {

        break;
      }
    case 3: {

        byte1 = data;
        buf = data - byte1;
        byte2 = buf * 10;

        break;
      }
    default: {
        break;
      }
  }

  digitalWrite(csnPin, 0);
  SPI.transfer(0xe1);   //flush TX_FIFO empty
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0xa0);   //write on TX_FIFO
  delay(10);
  SPI.transfer(byte0);
  delay(10);
  SPI.transfer(byte1);
  delay(10);
  SPI.transfer(byte2);
  delay(10);
  SPI.transfer(byte3);
  delay(10);
  SPI.transfer(byte4);
  delay(10);
  SPI.transfer(byte5);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(cePin, 1);   //CE High
  delay(1);
  digitalWrite(cePin, 0);   //CE Low

}

void NRF_monitorRegisters() {

  for (int i = 0; i < 30; i++) {
    digitalWrite(csnPin, 0);
    SPI.transfer(i);
    delay(10);
    Serial.print(i , HEX);
    Serial.print(" -> ");
    Serial.println(SPI.transfer(0xff), BIN);
    delay(10);
    digitalWrite(csnPin, 1);
  }
  Serial.println("");

}

void setup() {

  Serial.begin(115200);

  NRF_transmitterBegin();
  NRF_monitorRegisters();

}

void loop() {

  NRF_transmit(3 , 15.1 , 0);

  delay(1000);
}

and my code for receiver :
#include <SPI.h>

#define cePin 7
#define csnPin 8

//#define cePin D0
//#define csnPin D1

long int lastTime = 0;

void IRQ() {

  int whatIsData = 0;
  int byte1 = 0 , byte2 = 0 , byte3 = 0 , byte4 = 0 , byte5 = 0;
  float data = 0 , hum = 0 , buf = 0;

  /*Serial.println("STATUS register from IRQ ISR :  ");
    digitalWrite(csnPin, 0);
    SPI.transfer(0x07);
    delay(10);
    Serial.println(SPI.transfer(0xff), BIN);
    delay(10);
    digitalWrite(csnPin, 1);*/

  digitalWrite(csnPin, 0);
  SPI.transfer(0x61);
  delay(10);
  whatIsData = SPI.transfer(0xff);
  delay(10);
  byte1 = SPI.transfer(0xff);
  delay(10);
  byte2 = SPI.transfer(0xff);
  delay(10);
  byte3 = SPI.transfer(0xff);
  delay(10);
  byte4 = SPI.transfer(0xff);
  delay(10);
  byte5 = SPI.transfer(0xff);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);   //flush RX_FIFO
  SPI.transfer(0xe2);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x07 + 0x20);
  delay(10);
  SPI.transfer(0xf0);
  delay(10);
  digitalWrite(csnPin, 1);
  delay(10);

  switch (whatIsData) {
    case 1: {

        buf = byte2;
        data = byte1 + buf / 10;
        buf = byte4;
        hum = byte3 + buf / 10;

        Serial.print("Received data from DHT22 -> temp:");
        Serial.print(data);
        Serial.print("  humidity:");
        Serial.println(hum);

        break;
      }
    case 2: {

        Serial.println("Received data from PIR -> Move detected");

        break;
      }
    case 3: {

        buf = byte2;
        data = byte1 + buf / 10;

        Serial.print("Received data from gas sensor -> %gas:");
        Serial.println(data);

        break;
      }
    default: {

        Serial.println("a problem accured");

        break;
      }
  }

}

void NRF_receiverBegin() {

  //reading
  /*digitalWrite(csnPin, 0);
    SPI.transfer(0x00);
    delay(10);
    Serial.println(SPI.transfer(0xff), BIN);
    delay(10);
    digitalWrite(csnPin, 1);*/

  pinMode(cePin, OUTPUT);  //CE
  pinMode(csnPin, OUTPUT);  //CSN
  delay(100);
  digitalWrite(csnPin, 1);
  digitalWrite(cePin, 0);

  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  SPI.begin();
  delay(100);

  digitalWrite(csnPin, 0);   //flush TX_FIFO
  SPI.transfer(0xe1);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);   //flush RX_FIFO
  SPI.transfer(0xe2);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x07 + 0x20);
  delay(10);
  SPI.transfer(0xf0);
  delay(10);
  digitalWrite(csnPin, 1);
  delay(10);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x00 + 0x20);
  delay(10);
  SPI.transfer(0x0f);
  delay(10);
  digitalWrite(csnPin, 1);
  delay(10);

  /*digitalWrite(csnPin, 0);
    SPI.transfer(0x11 + 0x20);
    delay(10);
    SPI.transfer(0x01);
    delay(10);
    digitalWrite(csnPin, 1);*/

  //Down for DYNPL
  digitalWrite(csnPin, 0);
  SPI.transfer(0x1c + 0x20);
  delay(10);
  SPI.transfer(0x01);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x1d + 0x20);
  delay(10);
  SPI.transfer(0x04);
  delay(10);
  digitalWrite(csnPin, 1);
  //Up for DYNPL

  digitalWrite(csnPin, 0);
  SPI.transfer(0x01 + 0x20);
  delay(10);
  SPI.transfer(0x3f);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x02 + 0x20);
  delay(10);
  SPI.transfer(0x03);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x03 + 0x20);
  delay(10);
  SPI.transfer(0x03);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x04 + 0x20);
  delay(10);
  SPI.transfer(0xff);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x05 + 0x20);
  delay(10);
  SPI.transfer(0x4c);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x06 + 0x20);
  delay(10);
  SPI.transfer(0x06);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x0a + 0x20);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  digitalWrite(csnPin, 1);

  digitalWrite(csnPin, 0);
  SPI.transfer(0x10 + 0x20);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  SPI.transfer(0xaa);
  delay(10);
  digitalWrite(csnPin, 1);

}

void NRF_startListening() {

  attachInterrupt(digitalPinToInterrupt(2), IRQ, FALLING);

  digitalWrite(cePin, 1);   //CE High
  Serial.println("Listening started");

}

void NRF_monitorRegisters() {

  for (int i = 0; i < 30; i++) {
    digitalWrite(csnPin, 0);
    SPI.transfer(i);
    delay(10);
    Serial.print(i , HEX);
    Serial.print(" -> ");
    Serial.println(SPI.transfer(0xff), BIN);
    delay(10);
    digitalWrite(csnPin, 1);
  }
  Serial.println("");

}

void setup() {

  Serial.begin(115200);

  NRF_receiverBegin();
  NRF_startListening();
  NRF_monitorRegisters();

}

void loop() {

  /*if (millis() - lastTime > 20000) {
    NRF_monitorRegisters();
    lastTime = millis();
  }*/

}

Can you clarify what you mean by "tow" which appears multiple times in your question? See tow. Do you mean "two" or "a"? I understand English may not be your first language, but your question is hard to understand.

thanx and sorry for my bad English :)

just one of them worked - what do you mean by "worked"? What range are you testing over? I've got a few of those and they work fine over 20m or so.

I mean sending package and getting response.they are close to each other but I don't know why they can't communicate. I wrote my own code base on datasheet and now I'm adding it to my post.if U can pls try my code and let me know if it works.

If they are to close the signal will distort and data will be lost. For very short range communication you have to reduce the gain, which is what your hand does.

Sometimes I heard it's better to have some minimum distance of 20-30 cm... I tried the simple ones and got on fast speeds about 5-6 meters. Try also rotating them and not have other electronics/metal nearby.

thanx all.
yeah , when I set PA to Low it works good. But still I can't understand why it doesn't work with 1km NRF or without socket adapter.
I thought it's a perfect module for RF communication but I have alot problem with that.

Those 1km versions have an additional amplifier. So at very short distances, they receive so much signal, they can't understand it. It's like someone shouting in a megaphone next to your ear, and all you can hear is ringing.

thanx Gerben. so I'm gonna try 1km modules far away from each other in next few days.I hope it work

The socket adapters take 5.0v. How much power are you supplying? 3.3 or 5v?

I give it a 5v from arduino and it works well about 95% of the time. but when I give it a 3.3v without socket it doesn't work! and I'm not familiar to stackoverflow so can u pls tell me how I can select a comment as 'useful comment' or it needs a high reputation?


text:
HC-05 bridge using Arduino Nano and GNU Screen
I connect an HC-05 module to an Arduino nano with CH341 serial chip (voltage divider on RX pin). I am trying to make a bridge for a test, i.e. serial in, echo local and echo to Bluetooth and vice versa. I modified the echo code from here.
int incomingByte = 0;    // for incoming serial data

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() {
    BTSerial.begin(38400);    // opens serial port, sets data rate to 9600 bps
    Serial.begin(9600);    // opens serial port, sets data rate to 9600 bps
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {

    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }

  if (BTSerial.available() > 0) {

    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }

under OSX I open two terminals. In the first terminal using screen /dev/cu.wchusbserial1410 9600 I see local echo as desired. But on the second terminal using screen /dev/cu.HC-05-SPPDev 38400 I see nothing after pairing. The only effect is that by typing the latter command, the module stops blinking rapidly and blinks only two times with long pause in between. Exiting the screen environment, then again blinks rapidly.
Appreciate any hints what I am doing wrong...
=====
intermediate success but not quite there yet:
I simplified the code and corrected the wrong connection. Local echo on serial works as usual, even between the two, characters are being transferred, but they are black question marks instead of why I typed.
/*
 * echo script
 */

byte incomingByte;

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(3, 2); // RX | TX

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

void loop() {
  if (Serial.available()) {
    incomingByte = Serial.read();
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }

  if (BTSerial.available()) {
    incomingByte = BTSerial.read();
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }
}

Any ideas?
========
Edited the Buadrate to 9600. Now everything works.

Might want to check the sketch logic. "BTSerial.available() > 0" and then "incomingByte = Serial.read();". Hum, and then all the echo statements. Also comments say 9600 baud but code says 38400 (which is tough for softwareserial).

Make sure your RX and TX pins actually connect to the right pins. TX to RX and RX to TX.

thanks for both comments. Indeed the RX and TX pins were connected at the wrong position. I got a bit of success, but I am not quite there yet (see edited post).

As Mikael noted, 38400 baud is a challenge for SoftwareSerial to reach without errors. Try 9600.

yes now it works. both at 9600 baud works. But I wonder how to manage higher baud rates with HC-05, if software serial does not supper higher speeds?

Based on the above comments I provide here the full answer in the hope it will be useful in the future.
HC-05 has two modes. The Communication Mode and AT Command Mode. In the latter mode, HC-05 responds in kind of "config" way and many default settings of the communication mode can be change here. While the baud rate of the communication mode, and many other settings can be changed, the baud rate of the AT command mode is always fixed 38400 to avoid any confusions and mistakes. On the other hand, the default factory baud rate of the communication mode, i.e. before any change, is set to 9600. So the solution to my problem was to set the baud-rate to 9600 on my newly purchased HC-05 and I was able to make an echo bridge between HC-05 Bluetooth and serial. Here is the code:
/*
 * echo script
 */

byte incomingByte;

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(3, 2); // RX | TX

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

void loop() {
  if (Serial.available()) {
    incomingByte = Serial.read();
    BTSerial.print((char)incomingByte);
  }

  if (BTSerial.available()) {
    incomingByte = BTSerial.read();
    Serial.print((char)incomingByte);
  }
}

After pairing HC-05 with OSX, I was able to open two OSX Terminals with one of these commands in the first terminal:
screen /dev/cu.wchusbserial1410 9600

and in the other:
screen /dev/cu.HC-05-SPPDev 9600

Everything worked properly, i.e. typing in one terminal produced characters in the other and vice versa. For changing the default baud-rate in the communication mode, I found a very good tutorial which can be found here.

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

To make this question and answer useful in the "Stack Exchange" way, can you please change your answer to summarize what the problem was. As it is it reads like "I had a problem" and "I solved it" which doesn't really help anyone else.

@LookAlterno It is not possible to "accept" a comment, whereas the solution was in the comment. So I had to answer the question myself. It does not even allow me to like a comment, the like buttons are off.

@NickGammon I have already edited the OP. The answer was in the comments others left, so I had to create an answer so that it can be accepted. Or how do you do this the "Stack Exchange" way?

@MichelKeijzers I have updated the answer to include the full description.

Your amended answer is much better, thank you. It will hopefully help other people in the future who have a similar problem. :)

source: Stack Exchange

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

sort: votes


text:
Resurrecting a fried Arduino (Bluno) USB port
Slightly distractedly, I went and connected 5V to the 3.3V pin on my DFRobot Bluno (the pins are right next to each other!)
The magic smoke leaked out of the AMS1117 3.3V regulator in a neat little puff. The sketch that was loaded on the board still runs fine, but the Bluno is no longer recognised by my Macbook Pro when I plug it into USB (I have tried different ports and different cables; they're all fine—it's the USB on the Bluno that's fried.)
In an attempt to repair it, I've replaced the AMS1117 (check the third paragraph of that tutorial—ha!) with an LF33ABV; this went well and I'm now getting a stable 3.3V on the 3.3V pin. Check out my handiwork:

However, the Bluno still isn't being recognised by the USB ports on my Mac.
Is there another way to upload new sketches to the Bluno? Theoretically you can do so over BTLE, but you need another Bluno to act as the "peripheral" and I don't have one to hand. I have various other Arduinos laying about if that helps.

Since the CC2540 is powered using the 3.3v, you might have also blown that chip by giving it 5v instead of the 3.9V, which is its maximum rating. Does BT still work? (Great fix with the regulator though; look awesome)

I think I might have :-(. The Bluno isn't showing up on any of the BTLE-sniffer apps I have on the iPhone.

Upload via ICSP. See those six pins next to the regulator you so expertly tacked on? Those are the ICSP pins. You'll need a second controller or programmer to do it.
http://arduino.cc/en/Tutorial/ArduinoISP

Funnily enough I remembered I had a USBtinyISP laying around. With it (and these instructions I've successfully managed to upload a new sketch to the board. Now to see if I can talk to it via BTLE...

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


text:
How do I read from an SD card on the Yun?
I'm trying to read a small file off the SD card installed in a Yun. Here's the sketch:
#include <FastLED.h>
#include <FileIO.h>

#define WIDTH 32
#define HEIGHT 1
#define NUM_LEDS (WIDTH * HEIGHT)

#define DATA_PIN 9

CRGB leds[NUM_LEDS];

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  Bridge.begin();
  Serial.begin(115200);
  FileSystem.begin();
}

void loop() {
  File f = FileSystem.open("/mnt/sd/single-line-testpattern.ppm", FILE_READ);
  f.seek(29); // seek past the header bytes
  Serial.print("position = "); Serial.println(f.position());
  for (int i = 0; i < NUM_LEDS; i++) {
    uint8_t r = f.read();
    uint8_t g = f.read();
    uint8_t b = f.read();
    Serial.print("r = "); Serial.print(r, HEX);
    Serial.print(", g = "); Serial.print(g, HEX);
    Serial.print(", b = "); Serial.println(b, HEX);
    leds[i] = CRGB(r, g, b);
  }
  f.close();
  FastLED.show();
}

Here's the contents of the PPM file:
50 36 0A 23 20 3A 20 62 79 20 54 6F 79 56 69 65 77 65 72 0A 33 32 20 31 20 32 35 35 0A FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF

This looks pretty straightforward to me, but the output I'm getting is absolutely baffling:
position = 5888
r = 6, g = A9, b = A
r = B9, g = 0, b = 5
r = 0, g = E9, b = 5
r = 0, g = 0, b = 4
r = 8, g = 21, b = 0
r = 0, g = 0, b = 0
r = 0, g = E5, b = A
r = E0, g = A, b = 0
r = 0, g = 0, b = 0
r = A, g = DA, b = 0
r = 0, g = 0, b = 0
r = 0, g = 0, b = A
r = E5, g = 0, b = 4
r = 2, g = 71, b = 5
r = 1, g = 32, b = 80
r = 9, g = 12, b = 58
r = 58, g = 31, b = 30
r = 30, g = 58, b = 58
r = 58, g = 58, b = 58

WAT?! Where are those numbers even coming from? What does file.read() think a byte is? How come it's trying to read from 5888 bytes into a 125 byte file?
Note this is the FileIO library from the Yun Bridge package to read from the SD card built into the Atheron side of the Yun. The "normal" Arduino SD card library isn't relevant here.

You might try first  reading and printing out the header as a consistency check, then you could try a version that seeks a few bytes into the header.  How would you expect this library to respond to a failure, such as the file not being found?  And do you really want to close and reopen it in loop()?  Is your output from the first cycle of loop() or a subsequent one?

You are not testing if the FileSystem.open succeeded. If it did not, subsequent calls using f would possibly give undefined results.


text:
When using Arduino Uno as ISP does "Yikes! Invalid device signature" mean a bad connection, bad config, or bad version of avrdude?
I'm using an Arduino UNO to program a pre-compiled hex image to an ATTINY45, using the avrdude in the Arduino IDE directory, on Windows 7. The Uno has the ISP sketch loaded from the examples directory and that works- the heartbeat LED pulses nicely.
On the hardware side I have this setup, except the ATTINY is surface-mount, soldered to a surfboard with all its pins verified-soldered with a voltmeter. I use a header-pin strip, held by hand to get the pins touching the surfboard, to get the signals from the Uno to the ATTINY.
Here are the command lines, which I took from looking at the IDE's debugging output:
REM set the fuse for 8MHz, so the ISP programmer can work
C:\Progra~1\Arduino\hardware\tools\avr\bin\avrdude -CC:\Progra~1\Arduino\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pattiny45 -cstk500v1 -P\\.\COM7 -b19200 -e -Uefuse:w:0xff:m -Uhfuse:w:0xdf:m -Ulfuse:w:0xe2:m
REM load the program
C:\Progra~1\Arduino\hardware\tools\avr\bin\avrdude -CC:\Progra~1\Arduino\hardware/tools/avr/etc/avrdude.conf -v -pattiny45 -cstk500v1 -P\\.\COM7 -b19200 -Uflash:w:firefly.hex:i
REM set fuse for 1MHz, as the project requires
C:\Progra~1\Arduino\hardware/tools/avr/bin/avrdude -CC:\Progra~1\Arduino\hardware/tools/avr/etc/avrdude.conf -v -pattiny45 -cstk500v1 -P\\.\COM7 -b19200 -e -Uefuse:w:0xff:m -Uhfuse:w:0xdf:m -Ulfuse:w:0x62:m

-I try running those separately, but always get this error:
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
     Double check connections and try again, or use -F to override
     this check.

but sometimes the number is ff0000 or ffff00 or ffffff
I read that "Arduino uses a slightly modified version of avrdude to upload sketches to the Arduino board. The standard version queries for the board's device signature in a way not understood by the bootloader, resulting in this error." Does this mean that using the Arduino avrdude with a new ATTINY chip, no bootloader on it, would also cause that same error? In other words, is the modified avrdude incapable of querying a non-Arduino-bootloaded AVR chip?
Or does that error simply mean I don't have a good contact between all my programmer pins and the ATTINY?
And, are the fuse settings truly needed, can the Uno program the flash into an attiny running at 1MHz and thus save me some steps?
(I would just buy a "real" programmer, but need to get this code in the next two days, and am in a rural part of Nova Scotia)

Try setting the programmer to -c avrisp. I think you can program it at 1 MHz without problems.

When I upload from the arduino IDE and set the programmer to "Arduino as ISP" it uses -carduino not the stk500. Just try uploading the blink program to the attiny from the IDE. That way you can see the correct commandline at the bottom, if you enable "verbose output" in the settings.

Did you upload the ArduinoISP sketch first?

Phil, I did load the ArduinoISP sketch into the Uno before these steps, it succeeded, and I see the green "heartbeat" LED in pin 9 pulse. Gerben/user2973, I did try "-carduino", I will try "-c avrisp" next. Thanks.

This looks like an ISP<->target connection issue.  Anything in your circuit which could be loading the lines?  Are the ATtiny fuses still set for internal clock, or are you providing an external one?  Are you sure you have all four signal wires and ground connected, and in the right order?  Perhaps you should tack solder a setup just to verify it is not your hand-held method (though I've also used that)

I soldered wires to pads to be sure the connection was good, and used those wires for programming from the Uno. Then the programmer worked, without any edits to the command lines as posted in the question. I ran a few variations and was able to answer all my questions, and a few more besides:

The "Yikes! Invalid device signature" error was being caused by poor contact between the programmer (Uno) and the ATTINY pins.
It had nothing to do with the bootloader not being on the new microcontroller. The new ATTINY45 chip doesn't need a bootloader for the in-circuit programmer to work.
The Uno can program the ATTINY45 configured to either of its speeds, 1MHz or 8MHz. The factory settings are fine, and don't require changing the fuses.
Both avrdude versions worked for programming- the 6.1 from the author's site, and the modified one from the Arduino IDE.
avrdude can program via the Uno using any of -c avrisp, -c arduino, or -c stk500v1, it doesn't matter which.

One little question I wasn't able to answer, was what speed the Uno programs at (communication speed between the Arduino I/O pins & microcontroller being flashed). Is it related to the serial port speed? But it turned out to be not pertinent to answering this problem. Someone else can ask it if curious enough.

ArduinoISP sets the SPI interface to clock/128, so for a 16 MHz Uno the connected AVR is programmed at 16 MHz / 128 = 125 kbit/s. But the limiting factors are the serial speed and when PROG_FLICKER is set, 30 ms delays added for each page commit.

I had exactly this problem. If the ATtiny is set for external clock, then the ArduinoISP will not be able to program it without an external crystal. Connected a 16 MHz crystal and 2 capacitors and worked perfectly.
(I was then able to set ATtiny to internal clock, remove the crystal, and then worked perfectly without the crystal.)

Add the board and their fuse description from what is already set and it will work.
For adding just C:\Program Files\Arduino\hardware\arduino\avr\boards.txt and add the board description.
########
############ Definitions for ATmega 8MHz
##############################################################
atmega16-8.name=Atmega16 (internal 8MHz clock)

atmega16-8.upload.tool=avrdude

atmega16-8.upload.protocol=stk500v1

atmega16-8.upload.maximum_size=14336
atmega16-8.upload.speed=19200

atmega16-8.bootloader.low_fuses=0xE8
atmega16-8.bootloader.high_fuses=0x99

atmega16-8.build.mcu=atmega16
atmega16-8.build.f_cpu=8000000L
atmega16-8.build.core=arduino:arduino
atmega16-8.build.variant=mega16

##############################################################
############################

I used it.

I was not getting connectivity to read the "fuse" bits from an ATTiny85 after having once successfully burned them from an Arduino. There was a failure from both an Arduino setup and a PICkit. I finally discovered that the issue was with the capacitors. 15 pF.  Removed them and was able to read the bits. Will probably try different capacitors, or this could be the combination of bits used and capacitors chosen.

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


text:
Reading atomic radio clock
i have some data logging to do. And i want some what accurate time meaning accuracy has to be +/- 1 minute.
I have considered a RTC, but then i thought. When i was 10 i got a watch that kept time from this radio clock. And if it is possible 20 years ago to make a clock that updates automatically in such as small form factor, then i should be able to do it with my arduino today.
Does anyone know of a guide/solution with components where i can read this atomic radio clock?

So, the first consideration goes to the radio propagation aspect. Every country does things a little different with their radio clocks. And you might only have good signal a few times a day. For a nice overview, check out a solution for the German DCF77. If you're totally set on using a radio clock, time-nuts has discussed in the past ripping open a $10ish clock to get at the fun parts of a WWVB receiver, so that's one overview of the pool you're diving into.
For myself I've skipped past the terrestrial time keeping and went straight to GPS. Find a receiver that provides a pulse-per-second and attach that to an interrupt and process it alongside the timestamp; you can see how I've gone about that in both code and final product.
I think GPS is both easier and more precise than the alternatives, assuming you're above ground and can pick up satellites. I think of RTCs as something to tell me the day and the year, while GPS can tell me the second. But you could consider ripping the antenna out of a cheap bedside radio-controlled clock and using that to set an RTC, careful to consider whether you want a cheap RTC (DS1307) that drifts a minute per day or a slightly more expensive RTC (DS3231 or ISL1220) that drifts a minute per month. (Rough numbers of course.)

Ok great - You can pick time from gps signals! While not an answer to the question i asked it was a much better solution! This is what i like about stack.
*


text:
Is it possible to read VGA with an arduino
In this forum thread on arduino.cc http://forum.arduino.cc/index.php?topic=107375.0 they talk about it not being possible to get 800 x 600 video in color with the arduino.
My case is a bit different:

I don't care about color, it can be black and white / grayscale.
I don't need 800 x 600 just 640 x 480.
I can do with something like 2-5 frames per second.
I don't need it to be processed by the arduino, just transmitted through an ethernet shield.

In other words, it is possible to transmit simple video (just enough to handle eg. bios) remote?

Hi, my current solution was to look in to FPGA but i didnt get so far in this project. It is still pending though.

Please note that this question is about capturing VGA video, not about generating a VGA display.  The Arduino is not a good choice for either, but the capture problem at issue here is far worse than the more usual generation one.

Trying to capture analog video such as VGA and transmit it over Ethernet is going to be technically challenging, and of questionable wisdom (at least without compression).  A conventional ATmega-based Arduino is just about the worst contemporary platform you could choose for this job - even aside from the VGA issue, it is a poor choice for Ethernet requiring an expensive add-on.  But just for the sake of "can it be done" ....
If you can threshold your signal to a digital level (assuming a high contrast image) this probably can be done, crudely, but will be quite tricky.  The display is likely to be very blurred horizontally - really, it would only be worth doing for bragging points.
The first thing to realize is that the standard VGA 640x480x60 mode has a pixel clock of 25.175 MHz, and most others will be even faster.
One approach would be to try to write a program which samples a digital pin (directly, no Arduino abstractions) to memory as fast as possible.  This would not capture every pixel, but rather something like every 10th.  You would then have to send these over the network before you fill up your available memory.
The tricky part is that you then have to go back, and scan another frame of video with a slight offset, so that by getting every 10th pixel again, you effectively get the pixel adjacent to the first.   And then you do it again, and again, until you have collectively transmitted the entire screen, which hopefully hasn't changed much as you did it.
It's going to be tricky as you will have to work your delays from the sync signals, and you really want a delay which is a fraction of ATmega's clock - which won't happen without external circuitry (programmable delay buffer, etc)
The whole project would be a lot more feasible on an 80+ MHz ARM Cortex part, as you could then use a counter/timer to generate pixel-or-less-adjustable starting delays relative to the sync pulse.  An FPGA would likely be an even better choice.

Get a cheap usb-camera in front of the sceen. Write a program, which takes a picture and sends it to you, when you press a button of your remote PC.
Select the button so, that it does not interfere with what you are doing. Here in Finland I might use Å (a Swedish character, which I never use).
I have also a home server. Some times I need to reboot or start the system to BIOS, while I'm thousands of miles away.

Well, it's very possible, but actually you'll stress the arduino. You can use it perfectly but the problem is, it takes a lot of time of Arduino. The reason is actually simple: Horizontal syncronization takes each 32uS of arduino, so the code is interrupted a lot, and if you use other codes the screen may flick. But i have a solution for you. I found software libraries:
http://forum.arduino.cc/index.php?topic=102181.0
or:
http://labdegaragem.com/profiles/blogs/gerando-sinal-vga-colorido-com-arduino-completo
The last link is in portuguese but you can always ask me anything.
OK, what people do is to use for example 2 arduinos to aliviate de stress, you can buy a arduino bare metal chip and put it in a protoboard to reduce costs. Buuut, ther's another very very easy way to work with vga in arduino. Using a isolated hardware:
http://www.hobbytronics.co.uk/serial-vga
You just need to send serial commands to the vga driver and it will do whatever you want. It comes with a library so you can use in arduino. It's perfect, aliviates the arduino, so you can use your ethernet communication and the price is great (for you, here in Brazil the fees kill a lot of children every day :-( ).

From what i read about the Serial VGA is that it displays stuff from arduino to VGA, I want to read from a VGA port.

Been on both pages, and it seems like it is ARDUINO => VGA => MONITOR, i want to do COMPUTER => VGA => ARDUINO => ETHERNET

Hum, i think there isn't yet any library you can find on the net because this is very specific, but if you can send signal, you can receive it. Actually you just need to get any vga software library. put it in an arduino to simulate a vga video running, and in the other end of the vga cable you read it with other arduino. What i'm saying is that you just need to get the same vga library and change it to read instead of writting. It is possible, it will just take time from you, but its not difficult because the already done library cointain time directives.

No.  This is not applicable to the question asked.

Do you want to connect direct to ethernet shield?


text:
Split arduino run mode depending on active USB connection
Ok, so i have a unit that i want to add information to the EEPROM, using the USB port, such as SSID for wifi shields.
Then i want to disconnect the USB cable, plugin a battery and then it should run its normal loop.
So something like:
IF usb-cable
   run_setup_loop();
ELSE
   run_main_loop();

Which board do you use?

Uno 3 and Nano China

Not really possible with the Uno or Nano. The UNO might work if you change the program on the 16u2 (that does the usb to serial). I think it would be easier to detect serial input (e.g. user presses enter) using if( Serial.available()). And then when some serial data has come in, change "mode" to setup-mode.

The wifi module is serial also so that wouldnt work.


text:
Dynamic SSID + Password from ESP8266WiFi
I'm using the ESP8266WiFi library on a NodeMCU, running the arduino bootloader in the arduino software (Windows 10 app version).
I'm trying to load the SSID and password from SD-card (this part is successfull).
My problem this far is when i use the Wifi library it looks like this:
 Wifi.begin(const char*, const char*);

Since it takes 2 const parameters i cannot change it later. Is there anyway i can add SSID and PASSWORD to my sketch without having to recompile it. (I have to send it to people who does not know how to compile and flash an arduino)
I'm not attached to the ESP8266WiFi library, i'm not attached to SD-card, other solutions are welcome.
SD-reader works as planned, WiFi works as planned with a static password and SSID.

The const keyword there does not force the data you call it to be constant, it only forbids certain assignments with the parameters inside that function but it's just superfluous in most cases. Meaning you can call it with input you got from serial or some other source (for ex. setup page accessible from hotspot->Store in EEPROM->Next boot connect to set WiFi AP). There's also a nice StackOverflow thread about this here and why it's not actually a good idea in many cases.

I've considered this, but i think the user is on a level here where connecting to a temp hotspot would be too advanced. I even think that downloading a configuration file to an SD card is on the edge of too advanced - Thats my problem. Though i think your reply gave me an idea on how to fix it. Let me just try it out and if it works you get the correct answer.

The problem was not const char*, but bad conversion from string to char*.
Thing that lead me to believe it was the const char* was an unclear compiler message, and poor understanding of C++ data types.
but the correct answer was:
 ssid.toCharArray(ssidc, ssid.length());


text:
Wrong Mouse.move() output in Arduino Leonardo
I'm using my Arduino Leonardo as a Mouse but I'm experimenting a strange behaviour.
I put my mouse at (-1, -1) (absolute) coordinates and then I execute this code:
Move.move(com[curr_cmd_id].x, com[curr_cmd_id].y, 0);

where that point is (334, 180) (relative coords) (and I checked it through Serial console)
Now, the pointer is actually moving to the right but then it stops. Let's say it reaches the point (334, 0).
Then I tried:
Mouse.move(com[curr_cmd_id].x, 0, 0);
delay(500);
Mouse.move(0, com[curr_cmd_id].y, 0);

but still the same behaviour.
Then finally I tried this one (which it actually solves my problem but it's a dirty solution):
int i;
for(i=0; i<com[curr_cmd_id].x; i++){
  Mouse.move(1,0,0);
  delay(1);
}
for(i=0; i<com[curr_cmd_id].y; i++){
  Mouse.move(0,1,0);
  delay(1);
}

Could anybody help me in understanding what's going on here? How can I achieve a simple and direct relative movement for my pointer?
Thanks you in advance!!

So it's only moving to the right, and not up?

Only on the right and not down (considering the coordinates I expect to go down with positive y)

It looks like maybe there's something filtering a maximum "jump" in the mouse position.  What happens if your increment your for loop by more than 1 - can you experimentally discover a limit?

I struggled with this too until I realized this

Parameters
xVal: amount to move along the x-axis - signed char
yVal: amount to move along the y-axis - signed char
wheel: amount to move scroll wheel - signed char

Note it says signed char.
That means the value you pass to the Mouse.move is a signed 8-bit. (-128 to 127)
My work around is this below:
void moveMouse(int x, int y, int w){
  x = (int)x / 1.59; //Adjust these two values accordingly. I found out that 100, 100 does
  y = (int)y / 1.58; //not move 100, 100. It moves 159, 158 for me.

  while(x!=0 || y!=0 || w!=0){
    int moveX, moveY, moveW;
    if(x > 0){
      if(x >= 100){
        moveX = 100;
      }else{
        moveX = x;
      }
    }else if (x < 0){
      if(x <= -100){
        moveX = -100;
      }else{
        moveX = x;
      }
    }else{
      moveX = 0;
    }

    if(y > 0){
      if(y >= 100){
        moveY = 100;
      }else{
        moveY = y;
      }
    }else if (y < 0){
      if(y <= -100){
        moveY = -100;
      }else{
        moveY = y;
      }
    }else{
      moveY = 0;
    }

    if(w > 0){
      if(w >= 127){
        moveW = 127;
      }else{
        moveW = w;
      }
    }else if (w < 0){
      if(w <= -128){
        moveW = -128;
      }else{
        moveW = w;
      }
    }else{
      moveW = 0;
    }

    x = x - moveX;
    y = y - moveY;
    w = w - moveW;

    Mouse.move(moveX, moveY, moveW);
  }

Same answer in 5 lines: void MouseMove(int x, int y) {   for(int i=0; (x>0)?(i<x/100):(i>x/100); (x>0)?(i++):(i--))      Mouse.move((x>0)?(100):(-100), 0);   for(int j=0; (y>0)?(j<y/100):(j>y/100); (y>0)?(j++):(j--))      Mouse.move(0, (y>0)?(100):(-100));   Mouse.move(x%100, y%100); }


text:
Arduino Yun Webpage Server Issues
So, I've made a sketch on my Yun, which I would like to be able to take information from a webpage (like a button) and have the Arduino Microcontroller perform functions based on what button is being pressed. I have an html file with the webpage of buttons. I also have a sketch that responds to those button presses. When I upload the project via WiFi, everything copies over properly. The html file gets copied to the SD card, the sketch gets loaded onto the Arduino Microntroller, and I can browse to the webpage with my browser. However, whenever I click on the button within the webpage, nothing gets sent back to the Arduino Microcontroller. If actually program the webpage into the actual sketch, everything works fine, but not if the webpage is being loaded onto the SD card. After that, no data gets passed between the Linio and the Atmel Microcontroller.
I would like to be able to have the webpage be hosted by the Linio processor, but pass information about button presses to the actual Atmel Microcontroller.
Does anybody know how to do this properly? I would like to stay away from JScript and AJAX as much as possible. However, I guess I'll use them only if it's absolutely necessary.
Here is my arduino sketch:
#include <Bridge>
#include <Console.h>
#include <YunServer.h>
#include <YunClient.h>

YunServer server;
boolean receiving = false;

void setup() {
  Bridge.begin();
  Console.begin();
  server.listenOnLocalhost();
  server.begin();
  Console.println("Ready");
}

void loop() {
  YunClient client = server.accept();

  if (client) {
    Console.println("Client Connected");
    String request = client.readString();
    Console.println(request);

    boolean currentLineIsBlank = true;
    boolean sentHeader = false;

    while (client.connected()) {
       if (client.available()) {
         char c = client.read();

       if (receiving && c == ' ') receiving = false;

       if (c == '?') receiving = true;

       if (receiving) {
          if (c == 'A') {
            Console.println("Three Beeps");
            threeBeeps();
            break;
          }
          else if (c == 'B') {
            Console.println("Fast Beeps");
            fastBeeps();
            break;
          }
          else if (c == 'C') {
            Console.println("Fast Scale");
            fastScale();
            break;
          }
          else if (c == 'D') {
            Console.println("Alarm");
            playAlarm();
            break;
          }
          else if (c == 'E') {
            Console.println("Evil Alarm");
            evilChord();
            break;
          }
        }
        if (!sentHeader) {

  /*** I COMMENTED THIS PART OUT WHEN TESTING THE ACTUAL HTML FILE ***/
  /************************* ON THE SD CARD **************************/

           //client.println("HTTP/1.1 200 OK");
           //client.println("Content-Type: text/html\n");
           //
           //client.println("<form action='' method='get'>");
           //client.println("<input type='hidden' name='A' value='1' />");
           //client.println("<input type='submit' value='Three Beeps' />");
           //client.println("</form>");
           //
           //client.println("<form action='' method='get'>");
           //client.println("<input type='hidden' name='B' value='2' />");
           //client.println("<input type='submit' value='Fast Beeps' />");
           //client.println("</form>");
           //
           //client.println("<form action='' method='get'>");
           //client.println("<input type='hidden' name='C' value='3' />");
           //client.println("<input type='submit' value='Fast Scale' />");
           //client.println("</form>");
           //
           //client.println("<form action='' method='get'>");
           //client.println("<input type='hidden' name='D' value='4' />");
           //client.println("<input type='submit' value='Alarm' />");
           //client.println("</form>");
           //
           //client.println("<form action='' method='get'>");
           //client.println("<input type='hidden' name='E' value='5' />");
           //client.println("<input type='submit' value='Evil Siren' />");
           //client.println("</form>");

             sentHeader = true;
        }
        if (c == '\n' && currentLineIsBlank) break;

        if (c == '\n') {
           currentLineIsBlank = true;
        }
        else if(c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(5);
    client.stop();
  }
}

void threeBeeps() {
  for (int i = 0; i < 3; i++) {
    tone(11,2200);
    delay(100);
    noTone(11);
    delay(100);
  }
  noTone(11);
}

void fastScale() {
  for (int i = 0; i < 1000; i++) {
    tone(11,(i * 2));
    delay(1);
  }
  for (int i = 1000; i > 0; i--) {
    tone(11,(i * 2));
    delay(1);
  }
  noTone(11);
}

void playAlarm() {
  for (int i = 0; i < 5; i++) {
    for (int j = 1000; j < 4000; j++) {
      tone(11,j);
    }
    for (int j = 4000; j > 1000; j--) {
      tone(11,j);
    }
  }
  noTone(11);
}

void fastBeeps() {
  for (int i = 0; i < 6; i++) {
    tone(11,2000);
    delay(50);
    noTone(11);
    delay(50);
  }
  noTone(11);
}

void evilChord() {
  for (int i = 0; i < 5; i++) {
    tone(11,1110);
    delay(500);
    tone(11,785);
    delay(500);
  }
  noTone(11);
}

Here's the code in my index.html file:
<!DOCTYPE html>

    <form action='' method='get'>
    <input type='hidden' name='A' value='1'>
    <input type='submit' value='Three Beeps' />
    </form>

    <form action='' method='get'>
    <input type='hidden' name='B' value='2'>
    <input type='submit' value='Fast Beeps' />
    </form>

    <form action='' method='get'>
    <input type='hidden' name='C' value='3'>
    <input type='submit' value='Fast Scale' />
    </form>

    <form action='' method='get'>
    <input type='hidden' name='D' value='4'>
    <input type='submit' value='Alarm' />
    </form>

    <form action='' method='get'>
    <input type='hidden' name='E' value='5'>
    <input type='submit' value='Evil Siren' />
    </form>

As you can probably tell, the 5 buttons the webpage generates tells the Arduino to play a sound corresponding to the pressed button.
Like I said, I can program the webpage into the actual sketch (all commented out for the time being), and everything works just dandy. However, if I load the webpage onto the SD card in the Yun, I can still browse to it by browsing to "Arduino.local/sd/<project name>", but the buttons no longer function since the webpage was sent to the client from the Linio and not the Arduino. The reason I am wanting to let the Linio handle the webpage is because it can handle much larger webpages much more quickly without taking up precious sketch room on the Arduino. Also, I CAN read an SD card with the Arduino and send the webpage to the clients that way, but it's way too slow compared to using the Linio. So, does anybody know how to take the button presses from the Linio and send them back to the Arduino?
Any help would be greatly appreciated!

Your form actions are empty: when you'll press the buttons, they will send data to the current URL (something like /sd/project_name/index.html) instead of the /arduino url, which sends data to YunClient.
Reading your sketch, I think they are something like /arduino/?A=1, right?
A couple of advices:

start from the sketch and make sure you can control it from the browser. Manually type the expected URLs and verify the played sound.
Make the URLs easy to read, like /arduino/sound/A
Use the approach of Bridge example: code something like

String command = client.readStringUntil('/');
if (command == "sound") {
  char soundType = client.read()
  if (soundType == 'A') {
    ...

I'm not sure that's the problem, though. Do you see the Console.println("Client Connected") line? That line NEVER gets called when loading the webpage from the SD card, but it DOES get called when embedding the webpage into the sketch. The problem is just getting the responses from the client and having the Linio send those responses back to the Arduino side.

I fixed my problem by changing my sketch to this:
#include <Bridge>
#include <Console.h>
#include <YunServer.h>
#include <YunClient.h>

YunServer server;
boolean receiving = false;

void setup() {
  Bridge.begin();
  Console.begin();
  server.listenOnLocalhost();
  server.begin();
  Console.println("Ready");
}

void loop() {
  YunClient client = server.accept();

  if (client) {
    String command = client.readString();
    command.trim();

    if (command == "threeBeeps") {
      Console.println("Three Beeps");
      threeBeeps();
    }
    if (command == "fastBeeps") {
      Console.println("Fast Beeps");
      fastBeeps();
    }
    if (command == "fastScale") {
      Console.println("Fast Scale");
      fastScale();
    }
    if (command == "siren") {
      Console.println("Siren");
      playSiren();
    }
    if (command == "evilAlarm") {
      Console.println("Evil Alarm");
      evilChord();
    }
    client.stop();
  }
  delay(50);
}

void threeBeeps() {
  for (int i = 0; i < 3; i++) {
    tone(11,2200);
    delay(100);
    noTone(11);
    delay(100);
  }
  noTone(11);
}

void fastScale() {
  for (int i = 0; i < 1000; i++) {
    tone(11,(i * 2));
    delay(1);
  }
  for (int i = 1000; i > 0; i--) {
    tone(11,(i * 2));
    delay(1);
  }
  noTone(11);
}

void playSiren() {
  for (int i = 0; i < 5; i++) {
    for (int j = 1000; j < 4000; j++) {
      tone(11,j);
    }
    for (int j = 4000; j > 1000; j--) {
      tone(11,j);
    }
  }
  noTone(11);
}

void fastBeeps() {
  for (int i = 0; i < 6; i++) {
    tone(11,2000);
    delay(50);
    noTone(11);
    delay(50);
  }
  noTone(11);
}

void evilChord() {
  for (int i = 0; i < 5; i++) {
    tone(11,1110);
    delay(500);
    tone(11,785);
    delay(500);
  }
  noTone(11);
}

And also by changing my webpage to this:
<!DOCTYPE html>

<button onclick="threeBeeps()">Three Beeps</button>
<button onclick="fastBeeps()">Fast Beeps</button>
<button onclick="fastScale()">Fast Scale</button>
<button onclick="siren()">Siren</button>
<button onclick="evilAlarm()">Evil Alarm</button>

I also include the zepto.min.js Javascript file.

Zepto is the way to go. On a side note, since you call it "linino", you probably need to upgrade your yun. Check http://arduino.cc/en/Main/Software#toc8


text:
Arduino Underwater Inertial Navigation
I am working on prototyping an underwater navigation system with Arduino. It's going to be used to track movement underwater from a starting point and then be able to tell how to get back to that point or relatively close. The unit would only be going a few hundred feet underwater.
I am using an Arduino Nano, is this going to be sufficient? Also, what IMU would you recommend? I'm sure it will need to at least have a 3-axis gyroscope, 3-axes accelerometer, and possibly a 3-axis magnetometer.
This does need to be relatively affordable. Currently I'm building a unit that can go underwater and just record data onto an SD card so that I can take the data and map it out to check the IMUs accuracy, error margin, along with test various filters on the data. Any recommendations would be greatly appreciated.

Realistically, this is a problem that gets solved with sonar/beacons, not inertial navigation.

The nano can run an IMU just fine, but unfortunately no accelerometer based IMU short of some fancy missile guidance tech is going to be able to track position as accurately as you seem to want.
Since the Gyro and Magnometer only help with rotational orientation, the accelerometer is the only source of info on linear motion, and it has to be integrated twice to get position or distance. This site has a great explanation:
http://www.chrobotics.com/library/accel-position-velocity
As their table shows, even with an angular error of only .1 degrees, after 1 minute your position could be off by 62 meters with a standard quality accelerometer.
As far as IMU's go, the MPU 6050 (accl, gyro) and MPU 9150 (Accl, gyro and mag) are pretty standard in the hobby area, and sparkfun has some breakouts. The AltiIMU from Pololu has similar features and comparable cost. If you don't want to do the sensor processing the UM7 from chrobotics works well, but is significantly more expensive.

Thanks for the answer. That makes sense. Would an array accelerometers and a kalman filter reduce the amount of errors enough to make it work it? Is there some other sensor(s) I could add to significantly increase the accuracy?

I'm sure adding more would help your accuracy, but you still don't solve the fundamental problem that there is no check on the accumulation of error using accelerometers, so I don't think you could add enough to get long lasting accuracy. You're going to need to find some kind of absolute feedback system. Though it would require a raspi or similar, you could try using two lights to track with a camera like the wii sensor bar; Just a thought.


text:
What sensor would I use to get the speed or velocity of my Arduino based nav system?
I'm building a Arduino Nano based underwater navigation system using an IMU and various sensors. The only problem with this is that I cannot get the speed or velocity(at least reliably) and it would help the accuracy of my navigation system immensely if I had accurate speed to go off of.
Does anyone have any ideas on how I could measure the speed of my Arduino underwater? I've seen some people recommend paddle wheel like sensors but this needs to be accurate for slow movement.

As commented on your previous question, this is a problem usually solved with sonar.  A flow sensor can be useful, but outside of a stagnant body of water like a swimming pool or tank with no filtering system or a small pond, velocity relative to the water is not necessarily the same as velocity relative to fixed items.

On small recreational sailboats there is a small propeller on the bottom, when it turns it dials a speedometer, the faster it turns the faster the ship goes, a similar setup should be possible. With a small propeller and 2 ball bearings and an optocoupler, (same principle you got in the scroll button on your mouse, you should be able to pull it off with minimal resistance since there is no physical parts.

If you want accurate data (i.e. not by dead reckoning) then possibly GPS is an option. I suspect you will need to surface for it to work, as GPS signals are fairly week at the best of times - on a previous car I had, the windscreen was enough to stop the signal.

That makes it rather impractical for "underwater" speed determination, no?


text:
Arduino not responding
I have been using my arduino uno for many months and it worked very well even till today morning but an hour ago I tried to upload a sketch and arduino IDE showed my this "avrdude: stk500_getsysc(): not in sync: resp =0x00" , at first I thought maybe I burned my atmega32 chip but I bypassed reset and gnd with a jumper wire and opened serial monitor and my atmega32 still printing serial data,so problem must be something else,and also my led13 isn't blinking.Is it problem with bootloader?if so how can I reload bootloader in my board without using another arduino?

I'm personally not really in to this RTFM kind of answer, but in this case it really do answer most of your questions about the bootloader part: http://arduino.cc/en/Hacking/Bootloader
About the error, a quick search on SO gives you this: https://stackoverflow.com/questions/24240285/arduino-nano-3-avrdude-stk500-getsync-not-in-sync-resp-0x00


text:
How to store gps values in EEPROM arduino?
I have two successfully working individual programs,
1.GPS coordinate extract program.
2.EEPROM saving and reading program.
now all I want to do is combine them both, whenever GPS location is updated ,I want to save that latitude data to EEPROM memory repalcing the previously saved data, but I guess my program is unable to save it,its just showing blank spaces when reading EEPROM,please help me guys..here is my code.
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define RXPin 8
#define TXPin 9
#define GPSBaud 9600
#define ConsoleBaud 9600

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

// The TinyGPS++ object
TinyGPSPlus gps;
#include <EEPROM.h>
int address = 0;
int read_value = 0;
char data;
void setup()
{
  Serial.begin(ConsoleBaud);
  ss.begin(GPSBaud);
  Serial.println("Previous value stored :");
  for(address = 0; address < 25; address ++)        // read the entire EEPROM memory
  {
    read_value = EEPROM.read(address);
    Serial.write(read_value);
  }
  Serial.println("\n");

}

void loop()
{

  while (ss.available() > 0)
    gps.encode(ss.read());

  if (gps.location.isUpdated() || gps.altitude.isUpdated())
  {
    Serial.print("Location: ");
    Serial.print(gps.location.lat(), 6);
    Serial.print(",");
    Serial.print(gps.location.lng(), 6);
    Serial.println("\n");

    data=(gps.location.lat(), 6);

    for(address = 0; address < 25;  )
    {
      EEPROM.write(address, data);
      address ++;
    }
  }
}

data=(gps.location.lat(), 6); just always stores 6 in data, this is what will be sotored on all 25 first locations of EEPROM. It looks you don't understand what you're doing with this code. I'd recommend taking a look at some basic C programming tutorial.

Consider TinyGPS++ over TinyGPS only if you are running on Due or processor which can take advantage of the higher precision of 64-bit “double” floating-point.
char data; should be double data;. You're wasting resources otherwise.
data=(gps.location.lat(), 6); isn't how you do it. You only need to specify precision when writing to Serial, like Serial.print(gps.location.lat(), 6);. Make it data = gps.location.lat();.
address ++; should be address = address <=512-sizeof(address) ? (address + sizeof(data)): 0 ;
address <=512-sizeof(address) ensures that the last value written to the EEPROM is written in it's entirety.
Alternatively, I would recommend this to save you data structure directly to EEPROM, and what @jfpoilpret mentions.

You might try using sprintf. First define a buffer:
char data[25];

Then use sprintf to print to the buffer:
sprintf(data, "Location: %.3f,%.3f\n", gps.location.lat(), gps.location.lon());

%.3f prints a float with 3 decimal places. Check out the printf reference for details.
Then write the buffer to EEPROM:
for(address = 0; address < 25; address++ )
{
  EEPROM.write(address, data);
}

Careful with lat() and lon(): those return a double not an int! Hence sprintf("...%d...") will not work unless you explicitly cast lat() and lon() return to int.

well spotted @jfpoilpret :P


text:
ATTiny to drive LEDs
I'm installing some daylight running lights in my car and I have purchased 2 LED bars, each with 8 white LEDs. They use 12V and I need to make some effect when they turn on. Like in some modern cars, when I turn on the key, LEDs should blink(shake like when old fluorescent tubes turns on) and then turn on slowly(brightness from 0-100).
I can do this with Arduino-Uno and I need to put this in a smaller chip. What would be the best suitable ATTiny chip for this project? Because using an ATmega328 is not worth for a small project like this.

The ATtiny85 is an 8-pin AVR device with 3 PWM channels available in DIL and SO packages. The Arduino core can be downloaded from arduino-tiny. It can be programmed via ISP using either ArduinoISP or a dedicated programmer.

I have done a similar project, and can verify it works well. Make sure you have a transistor between the attiny and the LEDs (and a resistor between the attiny and the transistor!), so the high amps & 12 volts aren't drawn through the attiny. If you step down the voltage from 12v to 5v, make sure you check that they have a common ground - measure the voltage between the car battery's ground (negative) and the attiny's ground.


text:
PYM-1 PIR sensor current concerns
I am busy toying with some PIR sensors to detect movement etc for a nightlight for my kids. One of the sensors I ordered is the PYM-1 PIR sensor.
The data sheet states the following:

Operating Voltage: 4,5~5V.
Standby current: 65 micro-amps (65uA)
Operating Current: 40mA (40 milli-amps)

The limit for current on the arduino pins is 40mA. According to documentation at the arduino site 40mA is the upper limit per pin and the site clearly states: Absolute Maximum Ratings - the point where damage will start to happen I would rather avoid sinking the current directly on the Arduino.
So my question is will sinking 40mA on a pin cause damage? I have not been visited by the blue smoke genie yet and would rather avoid it at this point.
I suspect it might be safer to run this via a transistor and external power than directly on the arduino?

This is completely acceptable for your intended purpose.
By itself it will act as a light on/off trigger as others have noted.
An Arduino could be added if you wish to add extra features when the PIR is triggered. In it's most basic light-switching form using an Arduino is overkill.
By itself it will act as a light on/off trigger as others have noted.
An Arduino could be added if you wish to add extra features when the PIR is triggered. In it's most basic light-switching form adding an Arduino is overkill.
When it comes to playing overkill can be good :-)

To use it to provide input to an Arduino and NOT to a mains level light:
NB relay contacts may only be connected to mains for light switching OR to the Arduino. NEVER to both at the same time.
Connect it's DC supply input to your Arduino (or other) power supply.
As long as the supply can provide 40 mA when needed it will work OK.
40 mA is a power supply rating This is unrelated to the Arduino pin loading.
Connect the output to an Arduino digital pin configured as an input.

The output is a relay, activated when an object is sensed.
When inactive the centre pin is probably connected to the right pin - Check with Ohm meter.
When activated the left pin in connected to the centre pin (see their diagram)
Connect ground to right pin.
Connect Arduino digital input to centre pin.
Connect a "high" level to left hand pin.
OR as Majenko suggests, just set the pin to have pullups enabled.
If connecting to V+ as shown then V+ can be Vcc  (=5V for a 5V Arduino, 3v3 for a 3V3 Arduino)
DO NOT set V+ to higher than Arduino's Vcc.
You can connect a say 1k to 10k resistor from V+ to the voltage source bur still do not set V+ above Vcc.
OK - just have pullups enabled:-)
eg (untested)

int ADCMode = 0;
   int PIRPin = 6;                 // PIR connected to digital pin 6
   void setup()
   {
     pinMode(PIRPin, INPUT_PULLUP); // set PIRpin as input with pullup
   }
   void loop()
   {
    ...
     ADCMode  = digitalRead(PIRpin);   // $Read PIR status
   ...
   }

When the circuit activates digitalRead() will return a high.
When the circuit is not activated digitalRead() will return a low.

See here re Arduino pin modes

Thanks for the information but could you clarify the following: DO NOT set V+ to higher than Arduino's Vcc. The sensor has no adjustable setting except for distance and time which are both related to the functioning of the IR motion detection. Do you mean when using an external power source do NOT go over the VCC of the arduino?

That is not a good way to wire the relay to the Arduino.  Forget the V+ connection and just wire the middle terminal to the Arduino's IO pin and the Ground terminal to the Arduino.  Enable the internal pullup resistor on that IO pin of the Arduino.  Connect the Arduino's 5V and GND pins to the power (red and black wires respectively) pins of the board.  Wiring the relay like that will result in a dead zone between switching HIGH and LOW where the input is floating, which is not nice.  The bounce effect would be 1,000,000,000x worse that way.

@Majenko For some values of "not" :-)  / And but, or add a resistor externally or polish its doorknobs etc. My main aim was to try to provide a clearly understandable counter to the statements that the module was not suitable. Descent into pullups etc may be good if needed but may drive OP back into "it doesn't work" camp. | Aside: I wonder if the leakage current of an O/C input pin driving input capacitance of IC + PCB + ... has a time constant < to << the relay changeover time as you imply. It may BUT I (strongly) suspect that  if bounce is an issue in the application then

@Majenko formal debouncing is likely to be needed. Which is simple indeed in this application. All this I know you know. .

@RussellMcMahon That is all very well, but you have to remember - these are Arduino users.  They a) have very little knowledge, and b) what they do know is generally wrong thanks to Arduino teaching them the wrong things.  It is my quest to undo that bad teaching, and getting them away from switching like this is one of those steps.

@Majenko We have the same aim, but both of our suggestions have pros and cons. Yours aimed at electronic purity (albeit close to pedantry :-) ) and mine at having a clear "the relay does this!!!" physical picture. Bot of us have the ame aim. Neither answer is 100% right. Which is best is moot - but I have altered my answer to incorporate pullups if desired.

@Namphibian When I mention V+ I meant the connection I show on the photo I have posted. Yes. I mean do not connect it to more than the Arduinos Vcc. As Majenko notes, you can leave the line i have shown to V+ disconnected and instead set the pin to INPUT_PULLUP mode as now covered in my answer.

Thanks guys both your input is appreciated. It would help if the manual that came with the device is not in engrish.. they mention the time delay relay for suction of people in there. I was originally planning to power the device via the black and red wires(power supply terminal) and then have the relay connect to a IO pin and ground. What I did not realize is that the 40mA was power supply not the output at the relay which is a completely different case.

When I look at the PYM-1 seen here:
http://www.ebay.com/itm/Infrared-PIR-Human-Sensor-NEW-Arrival-Pyroelectric-DIY-Kit-PYM-1-for-Arduino-/271677900953
I don't see any need for an external microprocessor such as an Arduino.  It seems that one just applies 5V as input and it switches on/off up to 300W of power.  Where would one use an Arduino GPIO?

I would like to use the sensor with other sensors so when there is movement and sound for example. I do understand that this unit is probably more than I need however it does have the photoresistor which will allow me to trigger at certain light levels i.e. when it is dark when it lighter etc. This is part of a larger system in other words.

I get the impression that this module is a stand-alone device ... a PIR that detects movement and closes a circuit ... and that's it.  If you want to build a circuit that can detect movement, sound, light level changes etc etc ... you probably don't want to start with the PYM-1 but instead get parts such as an HC-SR501 and use THAT with the Arduino.

Also starting to get that impression. Love how they mark things as Arduino  on the site though. I have another one the HC-SR501 as well. Ordered two just in case the one is wrong. I will power the PYM-1 separately and play with it a bit more. I could probably just use it to close the circuit on one of the arduino pins and thus sending a signal.

I understand ... I too have bought parts before understanding what they were ... and its a lesson I learned well.  Now I study parts before purchase (unless they are so cheap it is unimportant).  I imagine I have it in front of me and set myself the puzzle of "how would I wire it?".  I then use Fritzing to build a circuit and if all still holds in theory, then I purchase.

Indeed I normally do that however this one was on special on DX.com and tried as I may I could not get a manual. Today I did get a manual however it is some of the worst english I have read. Might as well be no manual as it not worth the paper it is written on. I do however have another use for this sensor.... scary halloween puppet coming up.


text:
Maximum Current?
This is an extremely noobie question, but I have a 5V at 2A power source. This power source is going to be powering 6 Sharp IR distance sensors(20-150cm) and a few other low current consumption sensors(ie Xbee).
My question is if it is safe to simply use that power source without some sort of resistor between the power source and sensors?
also the IR sensors have a analog output. Is that same to plug into the arduino's analog pins?

also the IR sensors have a analog output. Is that same to plug into the arduino's analog pins?

If the sensors won't generate more than 5V, it should be safe. (Generally, they're all less than 5V. However, verify this...)

My question is if it is safe to simply use that power source without some sort of resistor between the power source and sensors?

You probably don't need a resistor*. Current is supplied on demand; if you need 1A but have a 2A supply, only 1A will flow. Voltage, however, is constant.
That being said, some parts will pull more current than they can safely use (like a LED, so then you would use a resistor.
This should all be found on the datasheet (especially with a more trusted brand like Sharp). Just look for example circuits and input voltage/forward voltage. A quick note, make sure to connect the grounds if you're not driving the Arduino directly from the power supply.
*There probably is an internal resistor for the LED. Again, datasheets, datasheets, datasheets!

wow once again you answered my question flawlessly. Thank you so much

A few other points, in addition to Penguin's excellent answer:
Make sure your 5V supply is a REGULATED supply. Unregulated power supplies will exceed their target voltage when unloaded, and "droop" to lower than their target voltage when under heavy load.
Quite a few digital components can be destroyed if their input voltage varies too much from 5V, especially over-voltage. TTL is especially sensitive to over-voltage (which destroys the circuit) and to malfunctioning on under-voltage.
Even a regulated power supply will have some ripple if you switch heavy loads on it. You might want to use separate, isolated supplies for your high power and low power logic systems.
A higher current regulated supply will be "stiffer" and therefore more stable if run at lower loads.

I am using 4 seperate ESC (electronic speed controllers) these give off 5 volts at 2 amps as a BEC (battery eliminating circuit) I assume that they must be regulated to take their 11.1 volt input and turn it into 5 volts.

I also have the IR sensors using their own power supply and my gps and xbee with another. By the way thanks


text:
Teensy 3.1 no overclock option for 168 MHz
I'm sorry if this isn't the right area. Teensy uses the arduino ide.
I've seen some people show off the 144 mhz and 168 mhz option in their ide. I read in the Teensyduino 1.19 release notes that the options were added but not enabled. I would like to know how to enable it or if I somehow downloaded an older version.
P.S I get the 96 mhz option.
Thanks ahead of time!

Did you look in boards.txt yet?

yes I see this:
teensy31.menu.speed.168.build.f_cpu=168000000
teensy31.menu.speed.144.build.f_cpu=144000000
teensy31.menu.speed.120.build.f_cpu=120000000
teensy31.menu.speed.96.build.f_cpu=96000000
teensy31.menu.speed.72.build.f_cpu=72000000
teensy31.menu.speed.48.build.f_cpu=48000000
teensy31.menu.speed.24.build.f_cpu=24000000
teensy31.menu.speed.16nousb.build.f_cpu=16000000
teensy31.menu.speed.8nousb.build.f_cpu=8000000
teensy31.menu.speed.4nousb.build.f_cpu=4000000
teensy31.menu.speed.2nousb.build.f_cpu=2000000

Using the latest Teensyduino distribution as of this writing, 1.25, you have to uncomment the higher overclocking options in the boards.txt file, located here in my install-
/hardware/teensy/avr/boards.txt
The options look like this, just remove the # symbol-
#uncomment these if you want to try faster overclocking
#teensy31.menu.speed.168opt=168 MHz optimized (overclock)
#teensy31.menu.speed.144opt=144 MHz optimized (overclock)
#teensy31.menu.speed.120opt=120 MHz optimized (overclock)`


text:
Maxbotixs LV-EZ4 analog read question
I am using an external 5 volt power supply to power my Sonar, and I am using a Teensy 3.1
to read in analog signal  from the sonar. my question is since the teensy is only 3.3v tolerant with analog in, is it safe to use with the maxbotix sonar?

That is not safe. Maximum voltage on the analog pins is 3.3v, according to the datasheet. But why don't you power it from 3.3v? Minimal voltage for that unit is 2.5v. And it uses only 2mA.

Yes, I just did. I assumed that it would be drawing too many mA but I was completely wrong.

Converted Gerben's comment to an answer

That is not safe. Maximum voltage on the analog pins is 3.3v, according to the datasheet. But why don't you power it from 3.3v? Minimal voltage for that unit is 2.5v. And it uses only 2mA.


text:
Arduino 1.6.1 IDE with Teensyduino Serial port lag issue?
OS: Ubuntu 14.04
Board: Teensy 3.1 and Arduino UNO
I've ran many tests and concluded that the issue is within the Arduino IDE itself.
The issue: Instead of a smooth stream of data displaying from the serial port, the terminal displays big chunks of data periodically.
I tested it with minicom and the stream of data is smooth.
Any solutions?

how fast is 'periodically'? I'm not surprised minicom is better, but unless the arduino terminal is really broken I don't think there is anything to fix.

around once per second.


text:
Why does arduino work on usb power?
The arduino website states that the operating voltage of an arduino is 7-12V.
Why does the arduino work powered on just usb then? As usb only outputs 5V and 500ma.
Is it preferable to say run the arduino on an external 9V dc power source, or does it make no difference?

The arduino website states that the operating voltage of an arduino is 7-12V.

That's when it goes through the voltage regulator. It's a linear regulator, meaning it wastes a lot of power as heat. The regulator outputs 5V that's given to the MCU. The USB voltage bypasses the regulator and goes to a fuse before going to the common 5V for the board. If less than 7V is given to the regulator, it will produce less than 5V.

Is it preferable to say run the arduino on an external 9V dc power source, or does it make no difference?

Usually, yes. A 9V supply would give you more than 500ma, giving you flexibility to add higher current components like motors and lots of LEDs. It will make no difference if you have a single LED connected.

Although you wouldn't want to run too much off the built-in regulator...

@Ignacio, true, but IIRC it's over an amp vs 500ma max... also if you use the 9V directly for sensors.

this may seem like a dumb question but will the following be a sound power supply for the arduino? http://thepihut.com/products/7-port-usb-hub-for-the-raspberry-pi  I have a 9V 1A PSU also, not sure which is the best to power it off. Or are both sound bets?

@c_breeez I can't advise you because I don't know anything about your situation.

Note that while a 9V power supply may be reasonable, future readers should not confuse that with a small 9v battery, a very low current device.  In terms of the regulator's capability there are two issues - one is a current rating, but often the more important one is a thermal rating for dissipated power, and that depends on the difference between input and regulated voltages as well as the current drawn.  The higher the supply voltage above the minimum, the less current the regulator can pass without overheating. High current projects should use a distinct regulator for peripheral loads.

@AnnonomusPenguin im running two arduino s one powering 8 300 micro amp ir detectors and one ir led. The other 6 detectors and one ir led. I'm also running a innovations id12la rfid reader on another port. And a wifi dongle. So yeah those four things one on each port. A mega, an uno, a wifi dongle and an rfid reader

@c_breez as long as the RFID reader and the wifi dongle comply with USB 2.0 specifications (no reason why they shouldn't), then the USB hub should be plenty fine. I'd be surprised if the Arduinos used 1/10th of an amp... the only thing is I think the Pi might need to be powered on for power to be delivered to the devices...

@AnnonomusPenguin Awesome thanks a lot of the input and reassuring me on this, just wanting to make sure I get the power requirements right for my project. I just tested the hub out and it will power arduinos without the pi being connected, as it runs off a DC adapter. Thanks a lot for the help


text:
Yún boot from SD card
I have an Arduino Yún, and it only has 16mb flash onboard for the Linux. I was wondering of it is possible to put a bootloader on the flash that uses the sd card as a rootfs? i want to be able to do more projects on it than those that can fit in 16 MB flash.

Not an Arduino hero, but I think you're trying to do things with your Yun that you could better do with a raspberry pi. For instance, running Linux...

I like the Yun because it's smaller and less power-intensive than the R-Pi, and i can use it for stuff that doesnt require a GUI. I asked this mainly because i want to run a Bluetooth stack on it, and the entire bluetooth code is probably going to be bigger than the linux OS it runs on.

I'm not really sure if there's a full fledged Linux OS running on Yun (and any other Arduino). Did you consider a BT-shield? (see fi. http://makezine.com/projects/connect-an-arduino-to-a-7-bluetooth-serial-module/)

@puredevotion - The arduino Yun is a 400 Mhz MIPS CPU module running Linino (which is linux - it's a fork of OpenWRT), stuck to a ATmega32U4. It's not much different from a rPi at all. Have you looked at the Yun at all? You're answering like it's just a ATmega.

@TheDoctor - The Yun draws ~200-300 mA when idle. The rPi draws pretty much the same when idle. There is likely to be no meaningful difference in power consumption (you'd probably save more power by using a more efficient power adapter).

The high power ratings of the rPi are because the power supply also runs the USB periperals, so the supply needs to be able to run the rPi + two USB devices. They err on the side of safety.

Instead of booting from the SD card, would something like this which loads a sketch from an SD card work?

Do you want client or host mode? Also, would you accept an answer that provides an alternative way for BT?

And the Arduino team finally figured it out:
http://blog.arduino.cc/2014/05/06/time-to-expand-your-yun-disk-space-and-install-node-js/

In case of future link death, it would be good if you could include the pertinent points from the link in your answer

I am using Yun as well for my projects. I don't boot from SD card, but I store a lot of Python code there and it works for me. I've also seen this article that might be interesting for you. I haven't tried to do it on my Yun but I think it should work... This is example how to install node.js on the Yun (SD card), so in theory you could use the same approach for all additional software you want to run.
http://linino.org/doku.php?id=wiki:nodejs

Welcome to Arduino Stack Exchange! Can you please add more detail to your answer? Answers that are all or mostly links are not acceptable on Stack Exchange because the answer is useless if the site goes down. Maybe just quote a few sentences? Also, in theory you could use the same approach for all software you run: Can you expand your answer explaining how to do this? Thanks!


text:
Can I use an external power supply and still communicate with my computer over Serial?
I read the following online:
If you plug in both USB power (say from a pc) and external power via the 2.1mm jack, the Arduino chooses power source automatically.
If the external 2.1mm DC is providing greater than 6.6V, the Arduino will take power from it instead of the USB.
Firstly, is this accurate?
Secondly, my real question:
If I am powering my Arduino via external DC, can I still communicate with my Raspberry Pi using serial via the USB?

Related: http://arduino.stackexchange.com/questions/893/arduino-what-happens-if-i-power-the-arduino-with-both-the-usb-and-external-pow?rq=1

Yes you can. It still leaves the data/ground lines intact, it just doesn't bridge the 5V line.
Arduino Uno Schematic v.3:

The USBVCC is directly from the 5V on the USB jack (well, technically there's a fuse there). It then goes through a transistor (T1) that only allows power through when there is no power coming from the 5V regulator (that regulates the VIN voltage).
The USB jack:

You can see pin 1 of the USB jack (5V) goes through the fuse to USBVCC. The next ones D+/D- are the data lines that go through resistors to the ATMEGA16U (used for USB to UART). The last one just ties into ground.

Great answer, penguin! (Voted). Does it matter which order you connect the devices? (Can you run your Arduino via USB, then connect Vin once it's running, OR power it via Vin and connect USB while it's on? It sounds like it's wired to prefer Vin power, so what happens when you are powered over USB and connect Vin? Does it switch power sources on the fly?)

@Duncan it should be fine to connect USB when already powered by VIN (although it will reset when the computer connects to the COM port. As far as VIN while already on USB, it looks like it will switch but I'm not sure if the transistor will let the voltage drop low enough to reset the board. Either way is fine, but it might reset a few seconds in.

The datasheet for the FDN340P MOSFET might provide a little more information: https://www.fairchildsemi.com/ds/FD/FDN340P.pdf


text:
Can tx and rx pins on the uno be used like regular digital pins?
The uno has digital pins marked 0-13.
0 is marked as rx and 1 is marked as tx.
Can these two pins be used as regular digital pins if i am short of digital pins?

If you are short of digital pins you can aways use the analog pins. They also work as digital pins.

Yes you can perfectly use these 2 pins as long as your program does not use Serial.
EDIT: Serial data over USB goes through copper traces connected to the rx and tx pins, connecting them to the USB to serial converter chip.

My program is using serial, but pumping it through the usb. Not out of the rxtx pins. Is this still a problem?

It is the same: USB data is passing through RX/TX pins :-(

Ok thanks for your great answer and clarifying these points

Also you will probably want to ensure these wires are not connected when programming the Arduino. Otherwise you may have problems.

You can, but it will disable the serial port.

No, it's the other way around: the serial port has higher priority. When you enable it with Serial.begin(), you are disabling the normal port operation (pinMode(), digitalRead() and digitalWrite()). With one exception: you can set the RX pin to INPUT_PULLUP, rather than INPUT, which is the default. C.f. the datasheet of the ATmega328P, especially the sections Alternate Port Functions, Data Transmission – The USART Transmitter and Data Reception – The USART Receiver.


text:
Need a sensor to make ball roll away from pet but which sensor?
Having recently entered the world of Arduino I am seeking to make, as my first project, a ball that will sense my dogs approach and roll away.
I can handle the rolling part but I have been unable to find a sensor that will work when fully embedded in the ball (so the dog cannot bite or swallow it). This means no ultrasound or infra red or normal proximity sensor will do.
My best bet - an inductive proximity sensor (with a metal object attached to dog's collar) is only effective at a maximum distance of 8 cm and that is far too little. I need something that activates at say 1 foot.
Any ideas anyone?

How important is it that the ball roll from a foot away? Could using an accelerometer to detect when something touches it and then rolling away for a few seconds suffice? might be a lot cheaper.

yes, probably this is a better idea..

Perhaps an RFID tag on your dogs collar and a reader inside the ball will work.
You will just have to find a reader and tag combination that can work from the range you need, I think some RFID can work from over 1ft.
EDIT: You will need active tags (battery powered) to get over a foot range.
PIR sensors detect heat given off by humans and animals, so they make work through the ball. (not totally sure though).
Edit: i think PIR that is capable of detecting small animals may be your best bet you would just have to calibrate the range of detection some how

Idea 1:
Put a transceiver in the dogs collar, and one in the ball. Monitor the RSSI (received signal strength). If it goes above a threshold, roll away. Adjust the threshold to set the correct distance.
Idea 2:
Put an accelerometer inside the ball. Whenever it detects a knock (dog's paw etc) roll away for a few seconds.

Thanks for the idea. I now need to research transceivers. But it makes sense to put much of the intelligence on the collar rather than having to stuff it all inside the ball.

Re idea 1 would it work with bluetooth? I have a master and slave combo but I am not sure if there is any way to measure the signal strength.

Other than the answers above/below, you also could try infra-red lights and photosensitive transistors. However, that has some troubles, such as not working properly in the sunlight, or the material that the ball is made of blocking the light, and therefore not working.
AVOID MAGNETS! You could get your dog stuck in some metal, like a fridge. To get one working in such distance, you would need an awfully powered magnet, which could be strong enough to permanently impact circuitry in close range, such as a home theater which sits close to the ground.
By the way, how are you going to fit it all in a ball that is bite-sized? i'm actually interested in that. Aren't you worried of the dog munching it and breaking/swallowing circuits?

My dog has a short snout so can't really put much force on a ball. I was thinking about two central containers (maybe  those Kinder egg inserts, or what you would find in a chocolate Easter egg). The idea is to then surround this with  padding and place everything into a ball around 6 inches in diameter. Components will be: an Arduino nano, 1 or 2 small toy motors (with offset shafts), the sensor (if an accelerometer would be very small), and the battery pack (maybe use one of those button type or small pencils?). Maybe I might even fit in some sound device (small buzzer?)

Interesting.  You may want to consider using strong,small, modern rare earth, low cost (silver color) magnetic that can work up to 1 foot, depending on size and shape of magnetic. Test different size/shape mag with simple mechanical compass to check the distance.
You may want to use one of those popular sensor board with
a) MPUxxxx (3D accel to sensor gravity in 3D to know which way is up and down)
b) 3D magnetic sensor
Both sensors are 3D and you know which direction the dog is coming (direction and mag strength, changed from background earth magnetic field when dog is coming, gives distance) and which 3D orientation of the ball is and hence to calculate which way to move a weight inside the ball to make the roll.
Biological disclaimer, no idea if dog health may be affected, positively or negatively (people sells human magnetic collar with health claim), by constant, 24 hours, magnetic collar.
Hope it helps

Roll away from dog, 10 USD hardware but significant 3D vector maths/modeling. Mag field like line from 2 poles of  magnet. The line has different shape depending on distance. The variables are 1D distance, and 3D orientation (xyz) of dog, ball, earth gravity and earth mag. the last two are constant. Mag field should be quite constant in wooden house. Steel structure high rise apartment may be complex. Due to size, not much sensor can sense direction of the dog in 3D vector. Radio not ok/cheap,need tens GHz small antenna with good directivity. Optical ok for cellphone cam in spherical formation

The original question is "sense my dogs approach and roll away". The roll AWAY part is very difficult to do as above, although the hardware cost is only a few US dollars. "Roll" to any direction (toward dog, side way or away from dog) is much easier as many suggestions, as just needs signal strength to detect dog approaching WITHOUT actually know the direction of the dog referencing to the ball.

Agree re moving away. Had not thought of that. Some further thought provoked by this reply though. Maybe I should put all the intelligence in the collar device and simply send instructions to the ball via bluetooth or radio; so I would have the proximity device in the collar and this would react when the ball is sensed. Just have to think of a suitable sensor but this is probably better in terms of not having to fit everything inside the ball!

Moving AWAY is difficult to execute on part of the ball unit. The sensors inside the ball need to know which way is up and presumably move a weight to action the roll as what human, with full advanced sensors than most robots, is doing in this video. https://www.youtube.com/watch?v=G9OfQL1D_hE  Roll in random direction is easier than roll AWAY

Yes I need to be more precise in my choice of words. For a first cut effort any movement in any direction will probably be enough! By the way my idea for obtaining the movement was based on having a small motor with an off centre weight, ideally a stepper so that I could make it move just a few degrees in a direction at a time. Not sure if I would find the really small and light steppers I need though.

Use there are plenty of micro size stepper. Many egg sized. Some can be very small, as uned inside camera for auto focus, etc. Try ebay, adafruit, sparkfun(?) or similar.

Good to know re the small steppers. I scavenged a relatively small one from an old inkjet printer which might work.

If you want the old path, Scanner and fax machines have  steppers inside. 0.5 to 1.5 egg sized.  Camera has small sized, like half of the smallest finger, may be too small for easy work. Scanner and ink jet printer are 'open and big' for easy disassembly

Great, thanks John. I have just embarked on an "asking relatives for any old camera etc" campaign and recently harvested 3 motors from an inkjet and one from a scanner. But I will definitely look at cameras.

I mentioned camera just to illustrate that there are big and small sizes. Likely, the one your got from printer and scanner are worth first test as seem right sizes and easy to work with. Me be only try camera route if that first option fails.

Floppy drives have a small stepper with a threaded spindle - might be nice for moving a weight in/out.


text:
Connecting Arduino Android Wirelessy
I am working with Arduino and Android. I am interested in connecting Arduino (Mega 2560 ADK) to my Android tablet (Nexus 7) wirelessly. The chepaest option is via bluetooth but the communication in not reliable. Now I would like to connect it via WiFi. But I don't want to use WiFi shield on my Arduino.
As Arduino can send the information to my laptop via serial USB connection will it be possible to put this information on my home WiFi network and get it on my Android device by connecting it to the same WiFi network?

Yes, if the laptop and tablet are on the same network communication will be possible. One way to implement this would be to have a client/server setup that communicates over TCP/IP.
The laptop can act as a TCP/IP server and also communicate through the serial interface to your arduino. Many languages will be able to do this, Java, C/C++, Python, whatever you're comfortable with.
The android tablet can then connect to the TCP/IP server as a client and send and receive data through your WiFi. Have a look at the android documentation.
This would a simple solution but for a more permanent solution you could also setup a web server on your laptop, look into the apache webserver. Your tablet would be able to communicate with the web server through http requests. The web server can then start further scripts to send data to the arduino or maintain a serial connection depending on your implementation.