text:
make Arduino tell when the Python program stops reading from the Serial (crash, etc)
Here's the Arduino code:
void setup() {
  Serial.begin(9600);

  pinMode(7, INPUT_PULLUP);
}

void loop() {
    int val = digitalRead(7);
    if (val == HIGH) {
        Serial.print("1");
    } else {
        Serial.print("0");
    }
    Serial.println("");  // new line

}

Python code:
import time
import serial

# setup Arduino USB communication
try:
    arduinoSerialData = serial.Serial('com3', 9600)

except: # not connected/damaged
    pass

while True:
    if arduinoSerialData.inWaiting() > 0:
        datastr = arduinoSerialData.readline()
        print datastr
        time.sleep(1)

WHat I want to add is, if Python program exits, or crashes, let the Arduino know somehow. More specifically turn on a LED in pin 8.

You didn't provide the information you were asked for. What does your existing serial protocol consist of? How does your "program" operate? We need DETAIL!

And anyway, you just asked the same question, not the question you were told to ask!

possible duplicate of know the state of USB (Serial) connection (coonected or not connected)

You were told the exact terms to ask about, and the exact information that was required, neither of which you have given.  The question should have been more along the lines of "I have written a program in Python that does XXX.  It communicates with the Arduino using a protocol that consists of YYY, ZZZ, etc.  How can I implement keepalive in this situation?"

Majenko, I asked you what I needed to ask. You said to ask something I didn't understand what even meant and refused to explain so I'd know it is what I indeed need to ask. Give me a break.

I have just told you the exact words to use.  Fill in the blanks.

I'm not going to ask something without understanding what is it I'm asking. That's retarded.

What part of that question formatting do you not understand?

It's not about formatting, it's about the terminology, I asked you this already and you refused to listen.

WHAT terminology do you not understand?!

I told you already in the other thread and you replied with "Go ask the question". Take a chill pill.

I told you in that question WHAT to ask, yet you seem to have refused point blank. You also refuse point blank to tell me what it is you don't understand.  Is it the "Keepalive" you don't understand? "Protocol"? "Serial"? What? YOU suggested a concept. I gave it a name. Now you are saying you don't understand?!

I already said why I refused to ask what you wrote down for me to ask, and very clearly gave the reason why, which was that I didn't understand if that was what I needed to know. And I'm not refusing to tell what I didn't understand "point blank" now, it's just that the comment is still there, but fine, I'll repost here:  What is the difference between "connected" and "alive and working"? And then, "What does your existing serial protocol consist of?" What does that mean? "How does your "program" operate?" - what does this mean? Youre asking to post all that. I'm asking what you need exactly.

They are far from vague.  "What does your existing serial protocol consist of?" You have a serial connection. You must be sending data down it in some form.  The Keepalive will also be serial data. We NEED to know what data YOU are sending so we can determine what the best way of augmenting that with Keepalive messages would be. "How does your program operate?" What data does it consume or produce? If we need to CHANGE your protocol we NEED to know what that protocol has to support.

Some reading matter.  https://en.wikipedia.org/wiki/Communications_protocol https://en.wikipedia.org/wiki/Keepalive

"The Keepalive will also be serial data", "What data does it consume or produce?" sorry but for me specifically this is pretty vague. At this point I can post my Arduino code and Python code. I'm not as experienced as you nor can I read your mind.

I'm sorry, but I cannot be more explicit than that. If you are unable to describe what your program does then how are we going to know what it does unless it is only a handful of lines?

You have two programs. Let's call them A (Arduino) and P (Python).  WHAT does A send to P? WHAT does P send to A? WHEN does A send things to P? WHEN does P send things to A?

Okay, code it is then. Give me a minute to simplify the codes and post what each does (you already know though). I think you have the privillege to edit the title, right?

Cross posted on Arduino Forum and a second time.

There is no way to know if the connection has closed or not, you can only know if the connection was working at some point in the past.
Your communication protocol as shown is only half duplex (i.e., it's only one way - the Arduino sends to Python but never the other way around) which simplifies things somewhat.
There are a number of strategies you can employ in your case, and any number of them can be combined to create a system as robust (and complex) as you like.
First you would need to make your protocol full duplex.  This is, you need your Python program to be able to send information to the Arduino.  Since you aren't doing that at the moment the implementation of it can be in any way you like.
One method you can use is called Keepalive.  In this system the Python program will periodically send an "I am here" message to the Arduino.  The Arduino receives these messages and remembers when the last one was (hint: use the millis() function).  If a message hasn't been received for more than a pre-defined timeout period the link is assumed to be dead.
Another method which is good if you are sending data very regularly from the Arduino to the Python program is to use a system of acknowledgements.  In this situation every bit of data sent to the Python program is followed by the Python replying with an "I got that" message.  If the Arduino doesn't get that response after sending its data within a certain timeout period (can be much shorter than for a keepalive timeout) then the link is assumed to be dead.
Wrapped around both these methods you can add an "I have arrived" and an "I am leaving" message.  These are sent by the Python program when it starts and just before it's about to exit so the Arduino knows when the link should be alive and when it shouldn't.  If it gets an "I am leaving" message then it knows that it shouldn't care whether it gets any acknowledgement or keepalive messages, so it doesn't need to think about timeouts. Only after it has received an "I have arrived" message should it start caring.
So for instance your protocol, with all these things implemented, might look like this (>> = message from Arduino to Python, << is message from Python to Arduino):
>> 1
>> 1
>> 1
>> 0
>> 0
>> 1
<< A    - I have arrived
>> 1
<< Y    - Yes, I got that
>> 1
<< Y    - Yes, I got that
>> 0
<< Y    - Yes, I got that
<< K    - keepalive - we know the link is alive and working.
>> 0
<< Y    - Yes, I got that
>> 1
<< Y    - Yes, I got that
(Program crashes now.)
>> 1
*no Y received - assume connection is closed*
>> 1
... etc ...

In this instance the 0 and 1 are what you are sending at the moment.  A is an "I have Arrived" message, Y is a "Yes I got that" message, K is a "Keepalive" message, and if the program had exited cleanly an L would have been an "I am Leaving" message.
Keeping the messages simple (single characters) means it's really easy for the Arduino to parse those messages and work out what is going on.
There is a certain amount of balancing act to be performed when implementing your system between how often you are sending data and how long you are willing to wait for a valid response or message to flag the connection closed.
Expanding your existing example program to incorporate these messages might look like:
unsigned long lastKA = 0;
unsigned long lastSent = 0;
boolean isConnected = false;

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

  pinMode(7, INPUT_PULLUP);
}

void loop() {

    // Check the timeouts if we are connected
    if (isConnected) {

        // First check to see if the Keepalive timeout has passed
        if (millis() - laskKA > 5000) { // 5 second keepalive timeout)
            isConnected = false;
        }

        // If we have sent data...
        if (lastSent > 0) {
            // ... check that we got a response in time
            if (millis() - lastSent > 100) { // 100ms Y timeout
                isConnected = false;
            }
        }

    }

    // If we are connected then send some data
    if (isConnected) {

        int val = digitalRead(7);
        if (val == HIGH) {
            Serial.print("1");
        } else {
            Serial.print("0");
        }
        Serial.println("");  // new line

        // and set the timer for the response
        lastSent = millis();
    }

    // Now process incoming messages.
    if (Serial.available()) {
        int c = Serial.read();

        // If the message is an A then turn on the connection and
        // treat it as a Keepalive as well.
        if (c == 'A') { // Arrived
            isConnected = true;
            lastKA = millis();

        // If it's a Leaving message then turn off the connection.
        } else if (c == 'L') { // Leaving
            isConnected = false;

        // If it's a Keepalive then reset the timer.
        } else if (c == 'K') { // Keepalive
            lastKA = millis();

        // A Y acknowledgement will disable the sent timer.
        } else if (c == 'Y') { // Yes
            lastSent = 0; // Cancel the sent timer
        }
    }
}

This is odd, serial.Serial.write('1') in Python doesn't seem to write anything to the buffer, print serial.Serial.readline() doesnt show what it wrote. Otherwise will work.


text:
AnalogWrite custom voltage

I want to get a low voltage on output pin of Arduino mega. I have connected Pin 46 to A3, and wrote 120 value to 46 port. Expected was to get 2-3v on A3 input pin. Instead I always get 1023 values as input. Am I doing something wrong ?
void setup(){
  Serial.begin(9600);
  pinMode(46, OUTPUT);
  pinMode(A3,INPUT);
  }

void loop(){
  analogWrite(46,120);
  Serial.println(analogRead(A3));
  }

You could substitute an Arduino Due and connect to pin DAC1 or DAC2 (located between A11 and CANRX), 12-bit-resolution DAC's :)

The analog outputs aren't real analog outputs, they are PWM.
That means that they rapidly switch from OFF to ON and back to OFF again.  The analog value is the ration of OFF time to ON time, known as the Duty Cycle.
You can convert that rapid switching to a real voltage by passing the signal through a low pass filter.  The simplest form is the RC filter:

source: Stack Exchange

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

sort: votes


text:
Pyserial serial.write() doesn't work
I need to communicate with an Arduino. When I use serial.readline() to read what Arduino has to say it works fine. But when I useserial.write('something') doesn't seem to do anything.
Interesting thing is that if I write the same code in the console or command-line, it works as expected...
Using Python 2.7.
Python code:
import serial
import time

arduinoSerialData = serial.Serial('com6', 9600)
time.sleep(1)

while True:
    arduinoSerialData.write('AAA')
    arduinoSerialData.flush()
    sleep(0.5)

Arduino code:
void loop() {

if (Serial.readString().startsWith("AAA")) {
    digitalWrite(7, LOW);
} else {
    digitalWrite(7, HIGH);
}

delay(500);

Again, Python code runs fine from the console, so no idea why this happens.

Your subject is Pyserial serial.write() doesn't work but you follow up by saying it runs fine from the console. So, the serial.write does in fact work. Try to stop using the words "doesn't work" and describe in more detail what is happening.

Cross posted on Arduino Forum and a second time.

please append what you did that worked - so the steps you did in the 'console' -

i think that your readString() can't reliably get all three AAAs in one catch - you have to send them at the right moment - otherwise it will read only first or last part or something else...

I'm having a similar problem with my raspberry pi, where sometimes it will work, sometimes it won't. I'm trying to send the sys.argv array, minus the first element, and display it on a screen, which I thought would be simple, but sometimes it will work and sometimes not. Code on the pi: import serial import sys ser = serial.Serial('/dev/ttyACM0',9600) args = str(' '.join(sys.argv[1:])) args = args.replace("'","") ser.write("test".encode()) print(args) Code on the arduino: String incomingByte; #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { lcd.begin(16, 2); //l

@voidUpdate, please delete your comment, it has nothing to do with the question that was asked, and nobody will answer it ... please post your own question instead

Closely related to To know the state of USB (Serial) connection (connected or not connected)

I would not be using Serial.readString() personally. How do you know where the string starts and ends? Just check for three "A" in a row.
Like this:
const unsigned long MESSAGE_TIMEOUT = 10UL * 1000;  // 10 seconds
const byte LED = 7;

void setup ()
{
  Serial.begin (115200);
  while (!Serial) ;  // wait for Serial to become active
  Serial.println ("Starting");
  pinMode (LED, OUTPUT);
}  // end of setup

unsigned long lastMessage;
unsigned int countOfA;

void processInput ()
{
  while (Serial.available ())
  {
    char c = Serial.read ();
    if (c == 'A')
      countOfA++;
    else
      countOfA = 0;
    // do something with the data
  }  // end of while loop
}  // end of processInput

void loop ()
{
  if (Serial.available ())
  {
    lastMessage = millis ();  // remember when we last got input
    processInput ();  // now handle the input
  }

  if (millis () - lastMessage >= MESSAGE_TIMEOUT)
  {
    countOfA = 0;
  }

  // warn if no keepalive received
  if (countOfA >= 3)
    digitalWrite(LED, LOW);
  else
    digitalWrite(LED, HIGH);

}  // end of loop

Note that this will fail (ie. it will light the LED) if it gets something other than "A" which would include newlines, etc.
What it does it count the number of times it gets the letter "A". If it gets something else it resets the count. If 10 seconds elapse without receiving something, the count resets.

It doesn't work though.

Well, it does, because I tested it. :P The words "doesn't work" do have a rather enraging quality (we hear them so often). Does the LED stay on? Stay off? Not go off after you type "AAA"? Not go on after a time-out? What Arduino are you using? Try to give details here.

Did you try from the console, or executed a py file? It works only from the console for some reason, like few others have experienced as well. I'm using a Nano.

What console? I am using the Arduino serial monitor. Make sure you get the baud rate right, I always use 115200 which is what I had in the code in my answer. I don't know why people limit themselves to 9600 baud.

The Python console. Issue is with Python, not Arduino

check the reference to serial.write - if i understanding it right you have to manually add a Line-ending to your string...
and additionally if i remember correctly it could have to do with permission of your py file..

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


text:
Loading Leonardo bootloader to Atmega32U4 running at 8 MHz
I am currently using ATMega32U4 running at 16MHz using Leonardo. I can only supply 3.7V (I use LiPo batteries) and everything seems fine but this is not as per specs.
To run at 16 MHz, I have to supply 5V but I can't. I do not want to do any step-up. I am thinking of of using 8 MHz crystal so the processor will require only 3.3V, but I need to use a Leonardo.
Has anyone been successful in doing this?

Why do you "need" Leonardo?

Has who been successful? To whom are you addressing this?

Or is this a general survey? Finding out what proportion of the population have been successful in using an 8MHz bootloader on a Leonardo?

The bootloader does USB. I don't think you can do USB on the 32u4 on only 8mHz.
You can however set the system clock prescaler to divide the main clock by 2, making it run at 8mHz. The bootloader will however still run at 16mHz, but that's probably still fine (though out of spec).

The AVR USB has a system clock prescaler, and the system clock can be divided by setting the “CLKPR – Clock Prescaler Register” on page 38. This feature can be used to decrease the sys- tem clock frequency and the power consumption when the requirement for processing power is low. This can be used with all clock source options, and it will affect the clock frequency of the CPU and all synchronous peripherals. clkI/O, clkADC, clkCPU, and clkFLASH are divided by a factor as shown in Table 6-10.

To divide the system clock by 2, set the CLKPS0 bit in the CLKPR register. The code for this would be something like this:
void setup()
{
  cli();
  CLKPR = _BV(CLKPCE);
  CLKPR = _BV(CLKPS0);
  sei();

  ...

just note that everything runs twice as slow. So delay(1000) will take 2 seconds. You'll have to update F_CPU somehow to fix this if this causes a problem.

You can do USB on 8MHz. The first thing that happens to the 16MHz clock on its way to the USB PLL is it goes through a /2 prescaler.  That prescaler can be bypassed to make it /1 so it can run from 8MHz.  It's all in the datasheet.  These bits allow to configure the PLL input prescaler to generate the 8MHz input clock for the PLL from either a
8 or 16MHz input.


text:
Sending a value from one arduino to another
I wonder if it is possible to send a value from one  arduino to another.
Basically, I have one arduino measuring let's say weight, but I want to display that value using an lcd in another arduino.
Is it possible to  send the value to a pin using analogwrite or digital write in the arduino doing the measurement and use analogread/digitalread at the other arduino making the display?
I do not know if this is possible but what is attractive is that one can have several arduino making weight measurements, all showing up in the display of just one central one...

You could have the LCD Arduino be an I2C master and all the weighing Arduinos be slaves. There's an example of master/slave communication and wiring here: https://www.arduino.cc/en/Tutorial/MasterReader.
I2C supports up to 128 devices and the wiring is very simple.

Exactly what I too was looking for thanks!

Yes it is possible,The answer provides one of the basic methods to do so
Connections
   Arduino1          Arduino2
     TX--------------->RX
     RX--------------->TX

Arduino1 Sketch:
void setup(){
 Serial.begin(9600);
 delay(2000);
}

void loop() {
 ////read sensor data to a variable
 Serial.println(sensorDataVariable);
 delay(2000); //Not to flood serial port
}

Arduino2 Sketch :
int byteRead;
void setup(){
 Serial.begin(9600);
 delay(2000);
}

void loop() {
  /* check if data has been sent from the computer: */
  while (Serial.available()) {
    /* read the most recent byte */
    byteRead = Serial.read(); //now byteRead will have latest sensor
                              // data sent from Arduino1
  }
  //Write code to display the values to LCD
}

hope this helps

Will this option be limited to only two arduinos? I would like several arduinos transmitting weigh values to a central arduino.

you can but use Arduino 2 sketch on all other receivers,,broad cast form one arduino and receive from many,,,you should do more research

How can we achieve this if we would like to do vice versa ? Arduino 2 is sending data to Arduino 1.

To tie multiple Arduinos together you need to come up with some kind of networking topology and some form of networking protocol.
Requirements are:

The Arduinos must not (electrically) interfere with each other
There must be some way to know which Arduino is sending what and where to

The two points could be addressed by having a separate connection for each Arduino but that ends up complicated, and there are only limited resources on an Arduino for creating such connections (you really need to use the hardware UART ports and the Uno has only 1. The Mega has 4).
A better solution is to use a bus system (also known as a multi-drop network).  There are a number of existing and well supported methods for doing this.  In the automotive system the CAN Bus is used.  In industry the RS-485 system is heavily used.
Personally I prefer RS-485 since it is well established.  There are a number of standard protocols that run on RS-485, such as MODBUS, but for the Arduino world I wrote my own light weight protocol specially which is far simpler to get going with.  You can find out more here: https://github.com/MajenkoLibraries/ICSC

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


text:
how to detect 125khz tags with mfrc 522
I have just ordered MFRC 522 RFID reader from amzon, and I have also orders 5 RFID tags with keychains and a arduino uno board for my project, I have received RFID reader and tags and I have tested the tags with my Sony xperia NFC. The tags that I received with the readers are working fine but the key chain ones are not working. I think because of the frequency difference 13.56 MHz and 125 KHz. So, please tell will this key chain tags work with the Reader

than what would be frequency range of the card/tag the one which came with the mfrc522 reader???

You are correct NFC is 13.56MHz the key chain ones you are referring to are most likely 125kHz The reader you have will only read 13.56MHz this is the NFC and HID cards. If you want to read the Key Chain ones you will need a reader like this one. Weigand 26 Card Reader Most Phones will not read the 125kHz

You can buy a 125 kHz reader from eBay for around $7. I got one like this:

You can communicate with it (listen to it) with a single serial pin (plus ground and power of course). I have a post about that board which describes the connections.

So, please tell will this key chain tags work with the Reader

No, the 125 kHz tags won't work with the 13.56 MHz reader. However you can work around this (if you want to) by using the 125 kHz tags with a different reader.


text:
Yun did not connect to WiFi after configuration and restart
When examined we find that Yun is still in master mode and 0% signal.
Any procedure known to solve this problem manually?
We can access Linux command under Mater mode AP-mode and print WiFi status
/usr/bin/pretty-wifi-info.lua

We know procedure to change REST API access
Method II:  config file

opkg update
opkg install nano
nano /etc/config/arduino

config arduino
        option password '775e9f944188a7bcb36e9ca5dc51672b44bcceeb7d56d89dfb914e$
        option wifi_reset_step 'clear'
        option secure_rest_api 'true'
...

Merhod 1:  UCI API    need access to the Linux system by YSM program

PASSWORD
uci set arduino.@arduino[0].secure_rest_api=true

OPEN:
uci commit arduino

Is there any procedure manually to perform the configuration by hand for the mode:

change to client?
then restart?
from master mode where we have access to Linux command line?

This question has been left unanswered before in all forums examined.
Maybe someone knows the answer.
The problem lies in the Linux not in the hardware or routers or PC, as proven by testing.

My wireless config is in the /etc/config/wireless, not in the /etc/config/arduino
How do you configure your Wifi ?
There is at least 4 methods  :
you can do this through OSJS, through LUCI, through ARDUINO IDE, or with UCI.


text:
Arduino as voltage monitor shorts to ground
I need to monitor voltages of several DC circuits in a generator's contact box.  Whenever the generator has an alarm, a LED is lit in the box and voltage on the line drops to zero.  I successfully get readings using analogRead(), but whenever I connect a line it shorts to ground (which is shared between the contact box and the Arduino) and triggers the contact box's alarm.  I need to devise a way to monitor voltages without triggering the alarm.
Each 5V line and ground from the generator has a bus bar termination point that connects to a point in the proprietary alarm box that houses the LEDs and buzzer. I connected Arduino ground to generator ground, then used A0-A7 on a Nano to connect to individual lines on the bus bar. Arduino VCC is connected to 5V regulated DC power.

What is the voltage you are trying to measure, and how exactly are you wiring it up?

Matt, please edit that information into the question.  Also, say if you actually need to measure voltages or just want go/nogo signals as could be obtained using optoisolators.

Input impedance of the analog pins is pretty low. So either the signal is very very weak, or your connections/software is doing something wrong.

I can detect the signals without problem.  The issue is avoiding the short to ground when I add the arduino into the circuit.

Since I was able to read voltages between load and the shared ground using a voltmeter without tripping the alarm, I thought I could do the same with an arduino.

Please add a schematic of the circuitry. And how is the Arduino powered, battery as the voltmeter?

A voltmeter does not have a ground reference. An Arduino plugged into the USB port would have one. Conceivably a battery-powered Arduino might work, however a safer solution would be to use an opto-isolator to isolate the voltage being tested from the Arduino. Something like this:

In this case you connect the "data pin" to the thing you are sensing. If it is at 5V then the LED will conduct (taking around 7 mA) and the transistor in the isolator will drive the Arduino pin LOW. If the data pin goes to zero volts, the transistor will not conduct, and the 1k resistor will pull the Arduino pin HIGH. Thus you can detect if the pin has changed voltage.
The 560 ohm resistor is a current-limiting resistor for the LED in the isolator. A 1k resistor would probably also work, reducing the current draw on the data pin to around 3.8 mA.

I would think you could also delete the 1K resistor and use the Arduino internal pullup resistor.


text:
Can we connect 4 4-digit 7 segment LED Displays to a single Arduino board?
Can we connect 4 4-digit 7 segment LED Displays to a single Arduino board ? Is it possible without another component in between ?

There is an awfull lot to find about this on the internet... I suggest you check it out first. Try searching for IO extenders, shift registers etc. You'll find a lot of theory explained in led cube tutorials also. As @victor said, you're going to need a lot of pins if you don't use another component. So you'll be better off using external components.

Actually, this is dependent on the datasheet. Assuming it's 7 segment + dot, it will require 8 independent pins to control each of the segment. All of segments are connected to a common anode/cathode which can be connected to a pullup/pulldown.
If we have 4 digit, that means we need 4*8=32 pins, which is a lot for any microcontroller. However, if you map out the internal circuit, you'll find that the segments are multiplexed. (You can do this by touching the pins with a wire connected to a pullup resistor, and another wire connected to ground.
Generally, you'll find that all the segment pins are multiplexed together in such a way that if all anodes/cathodes are enabled, all of the digits show the same display.
So how then can we make use of this information? Here's an idea:
How about turning on each of the digits one at a time (by controlling the common anode/cathode), but doing it quickly?
An example sequence would be as follows:
Set the segments for digit 1, enable the corresponding common anode/cathode for 5ms. Turn off.
Set the segments for digit 2, enable the corresponding common anode/cathode for 5ms. Turn off.
Do the same for digit 3 and then 4.
Repeat.
Controlling in this manner means you only need 8+4 pins=12 which is available on an arduino uno. Refreshing at 4*5=20ms will hardly be visible to our human perception, thanks to persistence of vision.
My answer is really just a starting point. If you spend some time, you can try to put in other smarts which are suited for your application, using even less pins. You should try this as an exercise. ;-)
Edit:
As a precaution, it's important to limit the current running through each of the LED segments so that they can live a long and happy life.
Assuming a forward voltage of 2V, adding a 1k resistor at the common anode limits the current to 3mA. This means adding resistors for all 4 anodes.
The same could work for common cathode displays, as long as the reverse breakdown voltage is not exceeded.
As with all things you find on the net, don't take my word for it. You should do the maths to check.

You need 4*4+7 = 23 pins in common cathode configuration or 4 +7*4 = 32 in common anode and arduino uno only have 20 output/input pins so if you don't want to use any external component you are going to need an Arduino mega.
Anyway, the best idea is to use a max7219 matrix led driver. look for it in google.

You could charlie-plex it.. that would dramatically reduce pins but would require more components than just the displays and arduino.


text:
Is it possible to create an electromagnetic wave using PWM?
What would be the simplest way of making an Arduino emit EM waves using PWM (or without)? Theoretically, oscillating a current through a wire would result in an electromagnetic wave, but I don't know if this is possible using an Arduino and if so, how?

I had a toy project a while ago that generated AM radio.

Code
Code for Uno or any Atmega328 based boards:
const byte ANTENNA = 9;

void setup()
  {
  // set up Timer 1
  TCCR1A = bit (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = bit (WGM12) | bit (CS10);   // CTC, no prescaler
  OCR1A =  9;       // compare A register value to 10 (zero relative)
  }  // end of setup

void loop()
  {
  pinMode (ANTENNA, OUTPUT);
  delay (500);
  pinMode (ANTENNA, INPUT);
  delay (300);
  }  // end of loop

Wiring
Plug a wire into digital pin 9:

Theory
The 16 MHz clock is divided by 10 (that is, 1.6 MHz) and that is used to toggle pin 9 at that rate, giving a frequency of 800 kHz, since one toggle turns the output on, and second toggle turns it off.
Then by turning the output pin on and off slowly you effectively have "keyed" output.
Obviously this would not have a long range, but you could amplify the output signal.

What does the timer code do?

It's a bit easier to understand if you look at the datasheet. I did a summary for Timer 1 (and the other two timers on the Atmega328) a while back.
Timer 1

The lines assigning to TCCR1A and TCCR1B set various bits as per the chart / datasheet. Then OCR1A is the value that the timer counts to, zero-relative, so it counts to 10.
The prescaler is set to 1, so each "tick" is 1/16000000 of a second (62.5 ns). Count 10 of them and you have 625 ns per tick. The timer is configured to toggle an output pin automatically. Since it takes two toggles (on and off) for one frequency "cycle" the period is 1.250 µs. The inverse of that is 800000. Thus the output frequency is 800000 Hz (800 kHz).

What does the timer code do? It seems quite cryptic to me.. :P


text:
What is the I2C address of a sensor?
I have connected BMP180 sensor:

to Arduino and was able to read its values with appropriate samples (from Adafruit BMP085 Library and Adafruit BMP085 Unified).
Apparently, this sensor is sending information via I2C bus.
However, I2C protocol assumes addresses of connected devices.
What are addresses in my case? How to know and/or change them?
Is it possible to connect several BMP180 to a single Arduino?

Datasheet. Library source. Why think anywhere else?

It was hard to believe for me, that address is burned into IC once forever.

It isn't "burned", it's just part of the logic of the IC.

Anyway, I don't understand, what is the reason to have addressing system without an ability to assign addresses. It is somehow normal to have fixed MAC addresses, because they are long and can be done globally unique, but what is the reason to have fixed 8 bit addresses? There is a big chance that different devices will have same address and impossible to use together.

http://www.nxp.com/technicalsupport/

So, you don't know a reason?

I have yet to run into a conflict that causes me problems.

This just means that you were using much less than 256 device types in your life :)

Why would I want to use that many devices on a bus as slow as I2C?

You don't need to use 256 devices at once. You just need to meet collision once, for any of two devices. Since there are 256 addresses at all, hence you need to use 256 TYPES of devices in your life and you will meet a collision.

It's one of the features of the I2C protocol. The devices have a known address. And yes, if you have more than 256 devices you are going to have problems. From the datasheet: A pin compatible product  variant with SPI interface is possible upon customer’s request - but even SPI has issues. Look up I2C on Wikipedia - it is a nice idea but runs into problems once lots of people start using it. These are small and cheap devices. For a couple of dollars you could interface each one to an ATtiny processor. Then devise your own way of handling collisions in information.

From the datasheet:

4.2 Device and register address
The BMP085 module address is shown below. The LSB of the device address distinguishes between read (1) and write (0) operation, corresponding to address 0xEF (read) and 0xEE (write).

With the Wire library you divide that by 2 (because it handles the read/write bit) so the address for using with Wire is:
0xEE / 2 = 0x77

Which is mentioned in the Adafruit library:
#define BMP085_I2CADDR 0x77

Is it possible to connect several BMP180 to a single Arduio?

You can certainly connect two of them. From the datasheet:

There is an easy way to connect two BMP085 to the same I2C bus: You can use the XCLR input of BMP085 to set one BMP085 part silent while you communicate with the other BMP085 part via I2C and vice versa. The signals can be provided by two digital outputs of the microcontroller, or one digital output and one inverter.

If you have access to the XCLR input (the Adafruit board broke it out, I can't tell with the board in your photo) you could use that method. Otherwise do what some of the other answers suggested, and use an I2C multiplexer.

So, address is embedded into hardware and it is impossible to change it? I have read that BMP180 does not have XCLR input, so I can't connect even two of them is this is true?

What is the reason to embed several bits without any ability to change them? Isn't it normal to expect several sensors connected to single controller or this is bad practice?

There is a conflict here between trying to make cheap, simple devices, and having someone wanting to have 1000 of them in some sort of network. Some I2C devices have pins you can tie high or low to alter their addresses. This particular one, being small, does not seem to have that ability.

May be I still don't understand something. Why are you speaking about network of 1000 devices? From my point of view I require only 2 devices and bad luck. Suppose I bought device 1 and device 2 and accidentally they have same address which I can't change. I need to throw one of devices into trash can and order a new one, still having a big chance it will have same address again.

They won't accidentally have the same address. They will have the same address by design.

Look, say you bought 20 DVD players. They all have the same remote control. The remote control affects all of them at the same time because they have the same address. This is by design, not some sort of fault.

You bought these sensors for around $1 on eBay. What do you expect for that price?

This is what my point is. DVD players are not intended to be selectable by address. Usually one buy one player and use it in one room. If somebody buy 20 players and wish to use them in one big hall, his usage will be UNEXPECTED. This is opposite for devices with I2C (as I see it). An addressing is EXPECTED usage.

So, you mean, that more expensive sensors WILL have some option to select address, like jumpers or something, as you said?

Either connect the second one to separate pins, and use software (bitbanged) I2C. Or use some method of multiplexing I2C devices, like for example explained here

So, you mean, that more expensive sensors WILL have some option to select address - I cannot speak for every sensor ever made, however I know that the I2C port expanders have three jumpers, hence you can adjust them to have 8 addresses (2 * 2 * 2 addresses).

See 4 Channel I²C Multiplexer - for $US 6.50 you could connect up 4 I²C devices with the same address. Also see I2C - Wikipedia - there they state The assignment of slave addresses is one weakness of I²C. Seven bits is too few to prevent address collisions between the many thousands of available devices, and manufacturers rarely dedicate enough pins to configure the full slave address used on a given board. It's an acknowledged problem.

Line 30 in Adafruit_BMP085.h clearly give you the address of sensor. Looks like the address is fixed meaning the only way you can connect several of these sensors is using a i2c multiplexer


text:
Is it possible to make an arbitrary lake bottom generator?
I'm trying to generate an arbitrary lake bottom sonar returns using my Arduino.
I would like to seed a function with a "depth." This would be the starting depth. I would then like to randomize a set of parameters each time the function is called. The output would look something like a time-truncated sine wave. The parameters would include:

Randomized Amplitude of waveform (which wouldn't vary too much)
Randomized Period (or frequency) of waveform (also wouldn't vary too much)
Randomized exit point. Say the period is 10 seconds but function ends at 7 seconds. This would allow for a changing in depth over time even if random.
If possible, I would like to low pass filter the output to smooth any hard transitions.

Any suggestions on where to get started?

Not sure this is even related to Arduino. electronics.stackexchange.com might be better place.

A common method of generating realistic-ish 3d terrain is as follows:
Start with a square (as seen top-down), described by the lengths of it's side (all the same), and the height of each of the corners.
Divide each edge in half; for example, add a new point halfway between the north-west point and the north-east point; it's altitude will be the average of the altitude of the two existing points, plus or minus a random number.
Now add a point in the center of the existing square; it's altitude being the average of the north, east, west and south points you've just created, plus or minus a random number.
You now have 4 smaller squares. Repeat this process on the four smaller squares, then the smaller squares within that, and so forth.
You might want to manually do the first few points, tweaking it to get the shape you want, then leave the details to the algorithm. Your random number for the adjustments of the "middle point" heights should be proportionate to the length of the sides; for example, the random altitude adjustment might be a random number up to X% the length; then subtract half of X% of the length. Adjusting X% will give you an area that is more or less "pointy".


text:
What's wrong with my ESP8266?
After trying to upgrade firmware of ESP8266, it failed. I am not finding any response from it. It's just blinking a red LED.
What will I do now?

I had tried to upgrade the firmwire in different ways...but couldn't.The result is that i am not finding any wifi signal response in the network connection ...What's now?

The upgrade firmware on the ESP8266 is hardcoded. Attempting to reflash it with known good firmware should restore functionality.

Make sure you have the correct firmware depending on the version of the board you have, the family seems quite big:
esp8266 wiki
There's nothing stopping you from experimenting and flashing different versions until you find the one that works.

Make sure that GPIO0 is not shorted to ground. Otherwise, try to reflash the firmware and when finished, leave GPIO0 floating to get out of firmware upgrading mode.


text:
Fog Machine - On Command
I work with a marching band, and we want to use fog machines for a particular part of the show. I know how to code/program in Arduino, however I am not great in the electrical and technical end. I own two fog machines, and the issue is that we need them to start fogging on command without delay (at least not a long delay, just not early and not late). We cannot exactly stop the show in the middle of a competition to say "wait, the fog is coming soon." We also need them to stop fogging on command.
I have read this article, Motion Triggered Fog Machine and it seems simple enough, however, I do not need or want it to work with a motion sensor. I suppose the easiest way you could help me is to either point me to a tutorial or tell me how to modify that tutorial to my own needs.

we need them to start fogging on command; Where do the commands come from. A human pressing a button? A PC running some software? DMX controller? Smartphone? Without some additional info, we can't add anything that isn't already in the instructable you mentioned.

@Gerben Well, it would be nice if I could do it from a smartphone.

So basically you don't know yet. How then, are we supposed to be able to help you?

@Gerben I need help figuring out the best option. I need it as simple and easy as possible so that when the fog is necessary it is sent out, and when we need it to stop it stops.

What determines if it is necessary or not? Easiest solution is to just press the on/off button on the fog machine. You give us no information, but expect us to provide you the golden solution.

@Gerben it is necessary to send it out at particular parts of the show, and it is necessary to stop it at certain parts. You're making it more difficult than it has to be. My question was simply, for a show that requires fog to start and stop on command, what is the best option?

Perhaps use a small wireless board like the NRF24L01 (available for around $1 each on eBay). Have one at the fogging machine, similar to the Instructable, but instead of a sensor, you turn the machine on and off when a command arrives. For example, send "0" to turn it off and "1" to turn it on. There are examples with the NRF24L01 library.

Then you have an Arduino in the wings nearby where you press a switch when you need to turn the fogging machine on (this would transmit the signal).

Great modules those.  I have some with power amplifier and SMA antenna. I haven't found the maximum range yet, but it's certainly measured in the hundreds of meters.

@Nick This is wireless also?

Yes, they are wireless transceivers. They communicate using SPI so you would need another Arduino (or similar) to send the command. A small one (like a Mini or Micro) could fit into a small box. The transceiver is pretty small - 30 mm long and 15 mm wide.

@Nick So, I can use this along with the instructable by simply using this instead of the sensor. And, you're saying I would need two arduinos?

Well not exactly "simply using this" - you would need to change the code to read from the transceiver instead of reading from the sensor. You would need an Arduino at each fog machine, and one to have with you to command the others when to turn the fog on and off.

@NickGammon Okay, thank you, I will look more into this.

@NickGammon I suggest that you'd link the maintained fork of RF24 (by TMRh20) instead of the outdated maniacbug's one.


text:
High power consumption during power down mode
I try to use power down mode to extend battery life, but no matter what sleep library I use, the power consumption never goes below 3.4-3.6 mA. I'm using a chinese pro mini board with VCC input (but using the RAW results the same).
avr/power sketch:
#include <avr/power.h>
#include <avr/sleep.h>

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

  // Ensure no floating pins
  for(i=0; i<20 ; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }

  // Power-down board
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  sleep_enable();

  // Disable ADC
  ADCSRA &= ~(1 << ADEN);

  // Power down functions
  PRR = 0xFF;

  // Enter sleep mode
  sleep_mode();
}

void loop()
{
}

rocketscream/Low-Power sketch:
#include <LowPower.h>
void setup() {
}

void loop() {
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}

How are you powering it?

Using a 5V YwRobot breadboard power supply with VCC pin or a 9V battery with the RAW pin. Both are the same.

Are you measuring the current before or after the breadboard power supply?

After. Meanwhile I realized that the power led is always on even when the board is sleeping so I guess thats causing the power usage. I'll try to remove it and test again.

There is also a voltage regulator on that board, that has some quiescent current.

All I/O pins must be outputs and not driving a load OR inputs and terminated to high or low.

See Power saving techniques for microprocessors. The first things I would get rid of are the LED and the voltage regulator.

I tried your first sketch on my "bare-bones" board.

With the sketch exactly as written, it used 197 µA.
I wondered why it was that high, so I commented out this line:
  Serial.begin(9600);

That reduced consumption to 122 nA.
See Power saving techniques for microprocessors.
You need to get rid of any "power" LEDs, and disconnect any voltage regulators. If you want really low consumption you need to have minimal hardware.
Of course, if you need the voltage regulator, well so be it. But don't expect 100 nA consumption if you use it.


text:
AVR+Arduino ADC problem
I  have connected a circuit to analog pin 0 in the Arduino.I have this code ,which I understand partially(online resources).The problem is that it prints nothing neither on Tera Term nor on Cool Term .Where am I mistaking ?(I am new to AVR programming).Here is the code:
  #include<stdio.h>
 void InitADC()
 {
 ADMUX=(1<<REFS0);// For Aref=AVcc;
 ADCSRA=(1<<ADEN)|(7<<ADPS0);
  }

 uint16_t ReadADC(uint8_t ch)
 {

    //Select ADC Channel ch must be 0-7
     ch=ch&0b00000111;
     ADMUX|=ch;

     //Start Single conversion

     ADCSRA|=(1<<ADSC);

      //Wait for conversion to complete
      while(!(ADCSRA & (1<<ADIF)));

      //Clear ADIF by writing one to it
      ADCSRA|=(1<<ADIF);

     return(ADC);
}

int main()

  {

uint16_t adc_value;

InitADC();

while(1)

{

  adc_value = ReadADC(0);
  printf("%d",adc_value);

  }

   return 0;

  }

That doesn't look like Arduino code.  Are you using some other IDE instead of the Arduino IDE?

I don't think printf will output to the serial port. At least not by default.

Your code compiles, but as Gerben said, the printf won't do anything in its current state, as no output handlers are defined for it. Why go to all that trouble when you can do this?
void setup()
  {
  Serial.begin (115200);
  }

void loop()
  {
  uint16_t adc_value;
  adc_value = analogRead (0);
  Serial.println (adc_value);
  delay (100);  // stop output spamming your monitor
  }

You could conceivably make printf work by following the tutorial here: http://playground.arduino.cc/Main/Printf
However I don't really see the point, when what I posted is much easier.

If performance is an issue, you might want to use the "advanced" code.

That "advanced" code above doesn't give you any more performance, because is still blocks. You can do a non-blocking version easily and readably enough:
const byte adcPin = 0;  // A0

bool working;

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

  ADCSRA =  bit (ADEN);   // turn ADC on
  ADCSRA |= bit (ADPS0) |  bit (ADPS1) | bit (ADPS2);  // Prescaler of 128
  ADMUX =   bit (REFS0) | (adcPin & 0x07);  // AVcc
  }  // end of setup

void loop ()
  {
  if (!working)
    {
    bitSet (ADCSRA, ADSC);  // start a conversion
    working = true;
    }

  // the ADC clears the bit when done
  if (bit_is_clear(ADCSRA, ADSC))
    {
    int value = ADC;  // read result
    working = false;
    Serial.println (value);
    delay (500);
    }

  // do other stuff here

  }  // end of loop

Now that code (which admittedly fiddles with the registers) doesn't block so you could be doing other things during the conversion. I don't see any reason you wouldn't use that on a commercial product.
See ADC conversion on the Arduino (analogRead) for more details.

Nice answer illustrating the idea/potential behind Arduino.
The code given by the "Question Asker" would be the somewhat like the underlying code in the arduino analogRead() function.
If performance is an issue, you might want to use the "advanced" code. As it separates the ADC init from the actual reading and is more "tweakable" than the arduino code.
Though the arduino code is many times more readable. But on a commercial product it will be unlikely to use Arduino code.

Thanks! You can quite easily write it without blocking, see amended answer.

I meant that using the Arduino library functions would be unlikely. But indeed you can use it. Much appreciated that you actually took the time to work out a non-blocking function. Though it does have a delay after printing the result? Is it for the ADC to get ready again or just so that it won't spam the serial output?

For simple demos I usually put a delay in something that happens a lot to stop the serial output spamming, yes.


text:
Very easy Arduino code challenge for you brainiacs to solve
I've searched the forum for similar problems and still can't see my obvious issue. I'm working on a simple Halloween prop and I'm using an Arduino for the first time. I've tested each individual 'event' (i.e. fog machine, mp3, actuator, and LED strip) with a loop and all four have worked on continuous loop with no issue.
As soon as I combine them all together, the program runs successfully exactly one time. After that final 10 second delay, when I expect the program to start the loop again, it crashes. If it helps, right during the start of the next loop, the relay light turns on on the relay board for RELAY_1_A and sort of just flickers while the actuator hums. I usually shut it down quickly at this point. As soon as I turn the system back on, it successfully runs through another iteration until the loop hangs.
I'm happy to provide pictures or even a video of the issue if that helps. My guess is that you guys will spot my coding issue right away. Maybe some kind of memory overflow or something like that.
I know my code could be much more efficient but I'm just looking for the glaring problem that is keeping the loop from working.
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>

const int RELAY_1_A = 7; //the one with the issue
const int RELAY_1_B = 8;

SdFat sd;
SFEMP3Shield MP3player;
void setup() {
  // initialize the digital pins as an output.
  pinMode(10, OUTPUT); //Fog machine on Relay1 on 5V relay board
  pinMode(3, OUTPUT); //LED strip off breadboard MOSFET
   pinMode(RELAY_1_A, OUTPUT); //12V relay for actuator on Relay1 on 12V relay board
   pinMode(RELAY_1_B, OUTPUT); //12V relay for actuator on Relay2 on 12V relay board

  //start the shield
  sd.begin(SD_SEL, SPI_FULL_SPEED);
  MP3player.begin();
  MP3player.setVolume(10, 10);
}

void loop() {
  MP3player.playTrack(2);  // Play MP3. Track 1 is coffin and track 2 is bird
  delay(5000);              // wait for 5 seconds
  digitalWrite(10, LOW);   // Turns ON fog machine
  delay(3000);
  digitalWrite(10, HIGH);   // Turns OFF fog machine
  digitalWrite(3, HIGH);   // Turn the LED on (HIGH is the voltage level)

  delay(5000);              // wait for 5 seconds

  retractActuator();       //Open coffin
  delay (9000);
  stopActuator();      //Close coffin
  delay (9000);
  extendActuator();      //Close coffin
  delay(8000);
  digitalWrite(RELAY_1_B, HIGH);  //Turns off this relay during the wait period before next loop

  digitalWrite(3, LOW);    // Turn the LED off by making the voltage LOW
  delay(10000);              // wait for 20 seconds

}
void extendActuator() {
  //Set one relay one and the other off
  //this will move extend the actuator
  digitalWrite(RELAY_1_A, HIGH);
  digitalWrite(RELAY_1_B, LOW);
}

void retractActuator() {
  //Set one relay off and the other on
  //this will move retract the actuator
  digitalWrite(RELAY_1_A, LOW);
  digitalWrite(RELAY_1_B, HIGH);
}

void stopActuator() {
 //Set both relays off
 //this will stop the actuator in a braking
 digitalWrite(RELAY_1_A, HIGH);
 digitalWrite(RELAY_1_B, HIGH); }

My guess is you have a pin conflict between your MP3 shield and your relays. Looking at the MP3 library my guess is pin 7.

Majenko thank you so much! Absolutely incredible. You solved my issue less than an hour after I posted it. You response made me look up the schematic for the Sparkfun MP3 Shield and it turns out that shield hogs tons of pins which can't be used. In fact, only 0,1,5, and 10 can be used. As soon as I switched the 2 relays to 0 and 1, everything worked perfectly. Thank you so much again!

Excellent.  I'll craft that as an answer then.

You are attempting to use IO pins that are already in use by the MP3 shield.
According to your subsequent research, only digital pins 0,1,5, and 10 are available for use.
You should shy away from using pins 0 and 1 since they are also connected to the computer through the USB interface and are used for uploading sketches.  You will find that either you can't upload sketches with the relays connected to those pins, or the relays will "randomly" switch on and off while you're uploading a sketch.
Don't forget that the analog pins A0-A5 can also be used as digital pins, so you can quite happily drive your relays using any of those.

-Majenko, I hope you will appreciate this communication tip. It is much more effective to say "Remember to ..." rather than "Don't forget to ...".

@linhartr22 Not for a native English speaker. "Don't forget..." is far more common than "Remember...".


text:
Can Arduino Uno's serial handle to foward push through 1-wire protocol?
tl;dr on on digital ouput/input I would like to communicate with a 1-wire device, whose protocol requires precision to ~15 microseconds. My question is if Arduino Uno's serial communication can be as quick as to support to map the digital pin via serial->USB to my host computers app which should implement the 1-wire protocol?
long version
The mode in which I thought to use my Arduino was, to attach it to a host computer and run the logic of what should be done on the host computer, having the Arduino only receive the data (for the pins) and return the state of the pins.
The challenge which prompts me to this question is that the Serial communication is not really that quick, compared to the timing requirement of some protocols (e.g. 1 wire) I wish to implement.
For example: 1-wire-protocol's timing requirements (i.e. range of micorseconds) could easily be kept from code running on the Arduino Uno's Atmega328 directly, which at 16Mhz and assumed 2 cycles per command would allow somewhat a resolution of 2/16Mhz = 0,125 us.
If alternatively the data/instruction for the 1-wire protocol should be mapped via the serial interface to an application running on an PC attached to the Arduino I wonder if the time requirements of the 1-wire protocal can be reached?
It boils down to a question if the Serial communication can have a temporal granularity as small as the about 1 to 15 microseconds needed to implement the 1-wire protocol - not within arduino itself - but in the attached PC's application.

Ok, so there's two issues at stake here.

Can the Arduino generate a 1-wire protocol with enough accuracy?
Can you transfer the data fast enough through the UART to tell it to do that generation?

You can't just stream a 1-wire protocol through serial and expect it to work.  The low-level serial protocol would very much get in the way.  So you have to send instructions to the Arduino to say "Raise the IO pin" and "Lower the IO pin" and "Tell me when the IO pin changes level", and "Set the IO pin to input" etc.
Each of those actions would be a discrete item that you would have to send.  Given that you could have a single byte per action (send "I" for set to input, send "O" for set to output, send "L" for set to low, etc - Arduino sends "H" if the pin goes high, or "L" if it goes low, etc), what kind of response could you expect?
Well, at 8 bits + start + stop per byte (so 10 bits) at a good fast rate (say 1MBaud), you would expect one byte to take (1/(1000000/10) = 0.00001s (10µs) to transfer.  That's raw transfer speed.  On top of that you then have to add the processing of that incoming data - the Arduino adds it to a circular buffer to allow your sketch to read it, and that takes time, and your program then interpreting it, you could expect a latency of say 15µs.  At maximum stream rate (no breaks between characters being sent at all) you would have a basic granularity of 10µs (processing the last incoming character while the next one is being received).
That's not counting any other factors such as the UART buffers on your computer, latency before the character even gets to the USB port's endpoint, etc.
So all in all there might be a slim chance that you could do it, but it would be very slim and not easy to achieve a stable result.
Far better would be to implement the 1-Wire protocol on the Arduino and just send/receive the control information to tell it to go ahead and do the work and return the results.  After all, that's what the Arduino is designed for - low level interfacing like that.

I was fearing as much. I do loath somewhat to implement anything on the Arduino itself, because its limitations with multitasking, ideally I would have simply done the heavilifting on a PC and abuse Arduino via Serial simply as a way to set/get the pins (somewhat in bitflash or firmata style). your answer was helpful.

Your idea seems wrong-headed, if I may say so without giving offence.
The Arduino is quite capable of generating 1-wire protocol. It certain reads it easily enough with bit-banging.
Trying to send down HLHLHHHLL through serial because your PC is "more powerful" is just not the right way of doing it. Next you'll be wanting to generate PWM on the PC and have the Arduino relay it to an output pin.
Remember, the Arduino (Uno) runs at 16 MHz. The original IBM PC ran at 4.77 MHz (if I remember correctly) so you can regard the Arduino as being as powerful as an early PC.
The simple solution is to send from the PC the data you actually want communicated by 1-wire, and let the Arduino do the actual bit-banging.

You suggest well and I do appreciate Arduino and the Atmega328. Yet I think the IBM PC had longer registers (less cycles whenever 16bit/32bit.... calculations where done) and most importantly no 2000 Byte ram, which makes attempts to schedule multitasking and implementing bigger things, challenging for people not yet as good in reducing memory as me. thank you

It certainly is possible for an Arduino to do this.  For example, source code for Atmel's implementations of 1-Wire protocol via bit-banging, via polling UART, and via interrupt-driven UART, is available at github.com.
There is a 21-page PDF file, doc2579.pdf, available at Atmel.  It documents how the different implementations work.
However, the notion of communicating faster than serial via the 1-Wire protocol seems like a mistaken notion.  As I understand it, the serial implementations above use one serial character per 1-Wire bit, so necessarily are slower than serial.

thank you for the encouragement. After some research the numbers I figured were. Highest speed of Serial from Arduino Uno Rev3 is 2,000,000 bits per second, which means that a bit takes about 500nanosecs. Becoming available in a package of 1 Byte means 8500=4us. For my intented purpose it would need to work with packages for PORT(B,C,D) and DDR(B,C,D) and PIN(B,C,D) send back, which meant 9 bytes per interaction (forwarding PC-app to Arduino) and would be (ignoring yet any CRC overhead) at 98*500ns=36us and by this breaking the 1-wire required max 15us for sending a logical 1.


text:
how many processor cycles/time does it minimaly take to transmit 1 Byte via Serial?
My understanding has been that the Serial transmission is indeed done (on the Arduino Uno) via the pins named TX->1 and RX<-0?
With this I assume that the Atmega has a machine code that would allow in 1 or processor cycles (125 or 62.5 ns) to set a byte (i.e. Port byte DDRD) as to forward exactly one bit of information for further processing to the ATmega16U2 "serial to USB" chip?
If this is true I would expect that 1 Byte = being 8 bits would require a discouragingly slow 8 to 12 cpu cycles (500ns to 1us)? Is this true?

If 16 megabit is discouragingly slow then you are in for a big disappointment. The default serial setting is 9600 baud, and the normal max is 115200.

No, it is not true.
You are assuming (wrongly) that the CPU is doing the UART communication.  It isn't.
The UART is a completely separate piece of hardware inside the chip.  It runs by itself.  The CPU merely places the byte to transfer into a special function register (SFR).  The UART then takes that and clocks it out through the IO pins at the right rate for the serial communication.  While that is going on the CPU is free to perform other operations.
The CPU can then either consult another SFR to determine if the transmission has finished, or utilize an interrupt that the UART will trigger when the transfer has been completed.

great, any change that would allow to make any reasonable guess how many bytes can be writen in a processor cycle? Also was it another wrong idea that the DDRD would have bits related to the tx/rx see https://www.arduino.cc/en/Reference/PortManipulation? maybe you would be able to extent your else already helpful answer, thank you!

The number of bytes you can write per second depends entirely on the baud rate the UART is running at.

Given the Arduino Uno (I am unsure if the revision is of importance), would you know what would the UART be? Also I think that the data must be somewhere indicated to the UART by the Atmega328, which runs at 16Mhz, I thought it was unable to tell more than 16 million times a second something to the UART, which then could have baud rates higher than what could be indicated by the Atmega328 on the Uno, right?

The UART has a baud rate that is dictated by the 16MHz clock. Read the ATMega328P datasheet to find out all about the UART.  The baud rate is a tiny fraction of the 16MHz clock rate - typically measured in the KHz range.

maybe indeed my assumption was wrong to the point that I did not explicitly refer to the UART chip doing the eventual sending out of data. I assume anyway I was quite rightly assuming that the Arduino Uno's 328 yet has to bring the data to this UART chip. To what I can understand this is done via the TX RX pins linked to the 16U2 UART, hence the questions reasoning was somewhat right assuming that the it takes at least 8 CPU cycles to send 1 Byte, only that some 6 or 7 out of those 8 the Atmega can do whatever else and is not doing a read of RAM to that SFR.

According to the datasheet:

Running at 16 MHz (as the Uno does) you can get up to 2 Mbps.

If this is true I would expect that 1 Byte = being 8 bits would require a discouragingly slow 8 to 12 cpu cycles (500ns to 1us)? Is this true?

For a bit or a  byte? At 2 Mbps that is a bit every 8 clock cycles.

would you know what would the UART be?

The UART is built into the processor chip. I suggest you read the datasheet.

I thought it was unable to tell more than 16 million times a second something to the UART, which then could have baud rates higher than what could be indicated by the Atmega328 on the Uno, right?

You can't do anything more than 16 million times a second at 16 MHz. And the clocking out of bits (in SPI, serial, or I2C) itself requires clock cycles, although they are done in parallel with the processor instructions by the hardware.

This is related to your other thread Can Arduino Uno's serial handle to foward push through 1-wire protocol? isn't it? Your end objective, I am guessing, is to try to implement 1-wire reading/writing via sending each bit via serial. This is just not the right way to achieve that objective.
In fact this thread in particular is coming across as an X-Y problem - your stated objective of wanting high-speed serial, is not really the problem you are trying to solve, is it?

you tell it right Nick, indeed the quesiton was in line with the other inquiry about implementing a firmata/bitflash type of protocol related to pass on 1-wire data. As @Majenko pointed out, in addition to my own calculations the time requirements are at best hardly matched. I thank you for your answer, I liked it and maybe can inquire that if the I had another UART chip than the Arduino Uno's Atmega16U2-MU which worked at a higher at say 32Mhz I had changes to Serial sent more than one byte per cycle of the Atmega328P, did I get that right?

if I had another UART chip - no, because you need to communicate with this chip somehow. The fastest method would be SPI which can send one byte every 16 clock cycles.

communicate with the chip somehow As suggested in the answer from @Majenko there would be a SFR in which the Atmega328 but the 8 bits (complete 1 Byte). It seems that such a step would be atomic 1 or 2 Atmega328 cycles. So is the "fastest communication rate" between the Atmega328 and the Atmega16U2 the 1 byte each 16 clocks?

Most of the "store" instructions are two clock cycles, so yes, it would take two clocks to load up the UART register, so it can start sending. Then, remember, that serial has a start and stop bit, so that is 10 bits per byte, not 8. I'm not sure if the Atmega16U2 will support 2 Mbps rate when communicating with the Atmega328, but even if it did, it takes more than zero clock cycles to then send this data in/out the USB port. I think you are flogging a dead horse here.

I have already ordered for a black beagle bone. It combines in one device what I wanted to achieve via a "Arduino extended BananaPi". I simply could learn from your answer and comment and hence revisited and thought. thank you


text:
Bluetooth Stream to USB
I want to make a device that will take a Bluetooth stream and play it on speakers via the USB port for speakers that do not have Bluetooth.
I think it may be possible by taking the stream and using an Arduino to convert the stream to a virtual file so that the speaker will see the USB as a mass storage and play the file.
I am not sure that is just an idea, any thoughts or solutions?

What kind of speakers do you have that can play a file on a USB mass storage device?  I think you are barking up the wrong tree and need to examine your terminology and what can actually be done a little better.

What's an Arduino raspberry pi? I didn't know Arduino had bought out Eban and co...

If your target is a USB audio device - like a USB headset or USB speakers (NOT an MP3 player with USB interface) then you could connect it to something which can act as a USB host with USB audio device drivers.  That means not an Arduino, but something much more powerful like a Raspberry Pi or BeagleBone Black for instance.
If your target is basically an MP3 player that allows you to connect a USB stick with songs on it then you're completely out of luck.  There's this small thing called time that gets in your way.  You can't stream data to something that expects the data to already be there. You can't seek in a file that doesn't exist until the moment you try to read from it. Also you have to act as if you were a USB memory stick, and that's not easy, and certainly not something an Arduino can do. Even things like the Pi would have a lot of difficulty in managing that since they are hosts, not devices, as far as USB is concerned.
The key word here is stream.  Your target as to be able to receive a stream of data rather than request blocks of data from a file.  USB audio devices can do that, but USB audio hosts cannot.

Thank You majenko, one more question. So when you stream via bluetooth to any bluetooth speaker, how is the music able to play live? as in how does the speaker read the stream and play it live?
And above you mentioned that if the target is a usb audio device. if it is a usb audio device, how would that be able to take a live stream via the  rasberry pi and play it. Isn't that the same idea as if it was an mp3 player that plays music off an usb? I appreciate your help, I am just trying to figure this out.

The concept is completely different.  An MP3 is like a CD. A stream is like the radio. A bluetooth or USB audio device is sent a digital representation of the sound at that instant in time. An MP3 player reads blocks of compressed audio data, decompresses them, and generates the digital audio representation.

Ok that make a lot of sense. Thank You so much.


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

?>

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

...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Yes, you are right: Arduino > PHP > MySQL

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

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

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


text:
Arduino connecting relay has no power output
I'm a newbie trying to control something through a relay. I've tried two relays with two different setups.
Setup 1
External 12V dc input to the relay (SRD-12VDC-SL-C) and signal pin from arduino to the IN pin, GND of ext. power supply to the GND of the Arduino, NO and COM to the load object (i.e. an LED).
Setup 2
Similar to setup 1, but using SRD-05VDC-SL-C, 5V from Arduino (Vin from Arduino also tested).
Test program
Modified version of the 'blink' example.
Symptom

The load object has been verified to be working before the testing.
Both setup can be verify the input is working, the power led and switch led of the two relay module are lighted as expected, and I can hear the click sound while switching.
No output can be obtained, both from the load object and using a multimeter.

Update

Sorry, I'm supposed to upload a Fritzing schematic, but I can't find a proper relay as I'm using.

The DC+ (red) of the relay is connected to the external ATX 12V.
The DC- (black) of the relay is connected to the external ATX ground.
The IN (blue) of the relay is connected to the Arduino pin 8.
The external ATX ground (white) is connected to the Arduino ground.
The NO (red) of the relay is connected to the load object Vcc.
The COM (black) of the relay is connected to the load object ground.

Sketch
A simple modified version of Blink example is used for testing.
const int relaySignalPin = 8;

void setup() {
  // put your setup code here, to run once:
  pinMode(relaySignalPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(relaySignalPin, HIGH);
  delay(1000);
  digitalWrite(relaySignalPin, LOW);
  delay(1000);
}

Question
I have no idea on why there's no voltage can be obtain between NO and COM while the switch is on, what's wrong with my setup?

Can you draw a schematic please? Even if you have to use pencil and paper and take a photo of it. Or a clear photo of your actual wiring.

It sounds, from your textual description (please post a schematic or at least a photo of your setup) that you aren't providing power to the relay.
A relay doesn't have a power output.  It never provides power - it is merely a magnetically operated switch.  It is used to switch an external source of power on and off.
Treat the NO and COM pins as either side of a normal button or switch and wire it accordingly - that is (for example) connect COM to the positive of your power supply, NO to one side of your load, and the other side of your load to the negative of your power supply.
You can share the same power supply as you are feeding to the logic / drive side of the relays.

So basically there are two wires connected to the same positive 12v source, one connected to VCC on the input side of the relay board and the other connected to the output side common terminal.
And there are three connections from the same negative 12v source, one connected to the ground of the relay board, one connected to the ground of the arduino, and the other connected to the ground of the load.
Then, of course, the connection to the relay to one of the digital pins of the arduino.
Well I'm pleased to report it works!
Now to discover what the jumpered COM/GND connection on my relay board does or does not do. I will report back.


text:
Can a Ethernet USB Dongle be instead of ethernet shield for arduino?
Can a Ethernet USB Dongle be instead of Ethernet shield for arduino in order to cut costs?

No.  Arduino can't behave as USB host.

No, not directly. As @Majenko pointed out its possible but most likely over your head. I am not a big fan of the ethernet shield as I like to use my Arduino for prototyping and then build the project with the components. There are a 2 easy alternatives which are inexpensive options for accessing a network or internet via the Arduino

ENC28J60 Ethernet LAN Network Module
Esp8266 Serial Wifi Wireless Transceiver

Both are inexpensive (between $5 and $7 USD). There are tons of tutorials on line to get you up and running

One more alternative would be Wiz5100, cause it already have IP layer implementation. If you dont want to read lot of RFC-s :)

Its an option, but at  $24.95 USD I can get 3 Esp8266

Actually, you can get it for around 14$ from ebay. Still more expensive then two you mentioned...

Possibly with an Arduino Due in USB OTG mode if you want to spend months and months (or even years) delving into the USB specs, reverse engineering the driver for the USB dongle and writing the software to get it working.
"Possible" but certainly not worth it when you can use a simple Ethernet shield and have it all working within a day.
And definitely not possible on anything like an Uno, etc.
Also it's possible on an Arduino that runs a full operating system (Linux) like the Edison or (possibly) the Yun (OpenWRT side of the operations, not the Arduino side).


text:
Can we use serial communication in arduino only for RX pin
Can we use serial communication in arduino only for RX pin, so that I am free to use pin 1(TX) as digital I/O:
Serial.write('a');
pinMode(1,OUTPUT);
digitalWrite(1,LOW);

HardwareSerial takes over the Tx and Rx pins. However you can use SoftwareSerial.
Arduino forum user whiteglint143 made an adaptation of SoftwareSerial that does read-only.
http://gammon.com.au/Arduino/ReceiveOnlySoftwareSerial.zip
See Receive Only Software Serial  - Arduino Forum

You can regain control over the TX or RX pins by unsetting the TXENn or RXENn bit in the UCSRnB register.

Like this?
const byte LED = 1;

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  UCSR0B &= ~bit (TXEN0);  // disable transmit
  Serial.println ("Testing");
  pinMode (LED, OUTPUT);
  }  // end of setup

void loop ()
  {
  digitalWrite (LED, HIGH);
  delay (500);
  digitalWrite (LED, LOW);
  delay (500);
  }  // end of loop

Gerben's suggestion works, in a sense. The pin flashes, but rather disconcertingly, the Tx LED on the board also flashes, out of sync with pin 1. Clearly the signal is making its way to the ATmega16U2 chip, which then flashes the indicator LED. This may not be desirable if you have something connected to the serial port, as it may be interpreted as low-speed serial communications.

You can regain control over the TX or RX pins by unsetting the TXENn or RXENn bit in the UCSRnB register.

Nice, simple solution! Good idea.

See amended post, using that pin as a digital pin may have side-effects.

Great finding. Though calling Serial.println, after disabling TX is kind of silly.

I hoped you wouldn't notice that. :P

authors: Сергій Іванов


text:
How to rsync my node.js project to my intel edison board, through ssh?
I would love to get rid of Intel's heavy XDK software, and be able to quickly push the updates of my node.js code into my Intel Edison (arduino compatible) board.
I tried this: rsync -avz ./ root@192.168.100.177:/node_app_slot/
But rsync is not installed on the board.
How would you do this?

By installing rsync onto the edison?  I am not familiar with the flavour of Linux that Intel chose - what is it?

It's based on Yocto, which makes it not exactly trivial to add stuff, if one doesn't have previous exposure.

You have few options:

use the Yocto sdk to compile rsync and then deploy it
switch to Debian and then use the standard way to deploy rsync
use scp, like the OP wrote, using the answer from Rick

If you are already looking for a more typical Unix way of doing things, option 2 might be the most efficient for you, in the long run.
I have not tried it, but AFAIK it should be possible to revert easily, since Edison uses dfu for system upgrades, so you should be able to go back to the stock SW, in case you do not like the Debian installation.

How can you not like a Debian installation?!

Heh, I like it so much that I wrote the full howto for Galileo: https://sourceforge.net/p/galileodebian/wiki/DebianOnGalileo
Probably it sort of works also for Edison, assuming one has a microSD adapter, for supporting a less space limited installation.
But I haven't had time to try it.

rsync works by talking to the rsync executable running on the remote target; without said executable you will need to drop to either scp or a tar pipe.


text:
Why did my program stop working when I eject the serial cable like it did an auto reset?
Arduino Uno based on 328p micro-controller board only works while I am inserting the serial cable between the board and the computer and I can control the speed of my two motors and every thing is work properly, but when I eject the serial cable it works badly and there is no control, is that some thing occurs like auto Reset?
There is always 5 volt feeding the Arduino, I get 5 volt regulated from the battery using "5v regulator", this regulated voltage is always connected to the Arduino board.

What is powering the arduino when its not connected to the computer? the arduino might be browning out without the usb power.

there is always 5 volt feeds  the arduino, i get 5 volt regulated from the battery using "5v regulator", this regulated voltage always connected to the arduino board.

5V is good, but it's not enough. Power (in this context, current) matters.
You mention 2 motors. Those things tend to draw relatively a lot of current.
Are you sure that the battery you are using can support the power requirements of the system?

@lgor Stoppa my 2 Motors feeding directly from the battery which  is 11.30 v, i know that I have just to feeds the arduino  by 5v.so no relation between the number of Motors I use.

Yes you can use the 12V battery I have found this in th Arduino Uno specs: Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V

Try increasing the voltage of the power supply. Maybe there might be a problem with the current. The Arduino has a 5V regulator on-board, try using a 9V battery. MAKE SURE THAT YOU CONNECT TO THE DC BARREL CONNECTOR.
Good luck!

can I use 12V Battery to Feeds The arduino.

@omran You should be able to.

If you have a problem with current, a 9V battery doesn't supply much (current).


text:
Communicating Via Serial1 on Arduino Mega
Apologies if this a relatively simple question, but I am rather new to Arduino's and cannot seem to find any concise information on the topic.
This is my XBee, mounted on a shield and placed onto a MEGA 2560. I want to leave Serial for USB debugging and use the Serial1 for XBee communication.

Just to confirm, the two XBee's do communicate if I use SoftwareSerial.   This is the code that works using SoftwareSerial:
#include <SoftwareSerial.h>

// XBee's DOUT (TX) is connected to pin 10 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 11 (Arduino's Software TX)
SoftwareSerial serial1(10, 11); // RX, TX
boolean nextLine = false;
void setup()
{
  Serial.begin(9600);
  serial1.begin(9600);
}

void loop()
{
   while(serial1.available()){ // there is data being sent from the xBee
    char read = char(serial1.read());
    if(read == 'A'){
      //Where ~ is the EOT character
      serial1.write("55.134~");
    }
  }
}

How do I communicate using Serial1?

If you take a look at the headers on the Mega, you'll notice that one of them has labels of "RX1" and "TX1" through "RX3" and "TX3". You'll also notice that the XBee shield does not connect to that header, therefore you cannot use Serial1 through Serial3 with the shield. Either switch to a breakout board that you can connect manually or stick to software serial.

Or pop off the jumpers on the shield and use a couple of jumper wires to connect the right pins of that header to the RX1 and TX1 pins on the Mega.

Thanks, I think I will do as Majenko has suggested and connect it through to Serial1 with some wires.

There is a good example on the Arduino site, but in short, you'd use the Serial1 (or -2 or -3) object the same way you use the Serial object:
Serial1.begin(9600);
if( Serial1.available() ){ ... }

etc.


text:
Using Piezzo Electric buzzer 10V with an Arduino Lilypad USB
I bought a 10 V Piezzo electric buzzer and I wonder how to connect it to an Arduino (in my case a Lilypad USB, but the question stands for any Arduino I guess...).
I hadn't realized this was a 10V buzzer, whereas the Arduino will support at most 5V.
I tried a simple layout such as below, with the sample code from a sparksfun tutoral, but that's not working!

So, how can I do it? ... or should I use another buzzer ?
Thanks

Your options:

Try it anyway with 5V: the buzzer might still produce loud enough sounds for your needs.
Use the line from the arduino to drive an "amplifying" stage (ex: 2N2222 in ON/OFF mode) - but this will also require a 10V source (like a step-up voltage converter)
Get a piezo that is designed to operate at 5V

I'll try next week-end and let you know, thanks.

I haven't managed to get any sound, but I'm probably doing it wrong.
I connected the buzzer to output pin 9 (and the other one to GND), and used the code here : no sound.
I also tried with another 5V buzzer : no sound.


text:
10k ohm Potentiometer vs 10k ohm Resistor on LCD Display
I'm trying to use a LCD Display with my Arduino, but I don't have a potentiometer and all of the guides I find always require one, usually a 10k ohm potentiometer.
The point is that I'm not very good at this stuff, but I understand that the potentiometer is actually a resistor that can vary, am I correct? In that case, if I use a simple 10k resistor I would have the same result as if I was using that potentiometer at the higher resistance (10k).
Would it be correct to use the resistor instead of the potentiometer? Then I would have to plug the positive on one side of the resistor and both the negative and output to the LCD on the other side of the resistor?

I understand that the potentiometer is actually a resistor that can vary - more like a voltage divider where you can vary the ratio.

No, it would not be correct to use a single resistor to replace a potentiometer.
On an LCD the potentiometer is used to adjust the bias level of the LCD - that is the contrast.  You need to use it to set a voltage between Vcc and Vee, which you feed into Vo.  That is, a voltage somewhere between +5V and -5V.
You can't do that with one resistor.
You can, however, do it with two resistors.  Some experimentation will provide the right values to use.  Pick a pair of resistors which add up to around 10K (the exact value doesn't matter that much) and join them together end to end.  The two ends are the equivalent to the ends of the track of the potentiometer, and the join in the middle is the wiper.
To change the "value" of the potentiometer you then need to change the value of both resistors.  If you reduce one resistor you need to increase the other so that they still add up to around the same value.  What you are working with here is not the actual values of the resistors, but the ratio of the values of the two resistors.

Thanks a lot for the explanation. I will try that and see what i can do. It's very interesting, but i still suck in physics/electric.

@GeorgeRappel You can read more about the theory here: https://en.wikipedia.org/wiki/Voltage_divider

you can use the digital pin to do this instead of resistance or potentiometer. I used a delay 500 which gave me good readable display. a value of 100 was to bright
void setup() {
  pinMode(13, OUTPUT);
}

void loop()
{
 digitalWrite(13, HIGH);
  delayMicroseconds(500);
/* 100 gives Approximately 10% duty cycle @ 1KHz with 500 i get a good value for screen text brightness*/
  digitalWrite(13, LOW);
  delayMicroseconds(1000 - 500);

/* now you can add your LCD code to print what ever you like.*/
}

This is both somewhat impractical, and quite misleading.  For this to work, your processor will be largely tied up in performing this software pulse-width modulation, and you entirely fail to state that.  Such a scheme could still be useful if the display is allowed to blank while other operations are performed and only resumes when the sketch is idle waiting for input to act on.  But it would be far better to use one of the hardware or interrupt-based software PWM schemes the Arduino offers.

why not just analogWrite() a value to the pin?