text:
Wifi Data Logger without Delay
I am really new to Arduino so please bear with me.
I am running an Arduino Uno with several sensors to capture some data related to a fish tank. Here is basically what it does:

Capture data (light, temperature, etc.)
Display data on an LCD screen when a button is pressed
Upload data to thingspeak every 5 minutes, using a ESP8266
Feed the fish every 4 hours through a servo
An RGB led blinks at various colors to let me see what's happening (e.g. red when connecting to wifi).

Everything is working reasonably well. That being said, my code is super messy and I am not sure I have the right approach. With the code I have:
 - Nothing can be done while the Arduino uploads the wifi
 - Nothing can be done when the fish are fed.
This is not so much about the servo, it is more about the wifi problem. How would you suggest that I rewrite my code so that (1) I can run the wifi more than once every 5 minutes and (2) it does not block my sensors and LCD display while I am doing it.
Sorry for the poor quality of the code. Newbie here.

//Include LCD Libraries
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <stdlib.h>

//Include Water Probe library
    #include <OneWire.h>

//Include DHT11 Libraries
    #include <dht11.h>

//Include Servo Libraries
    #include <Servo.h>

//Set Peripherals
    dht11 DHT11;
    LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
    Servo myservo;  // create servo object to control a servo

//Pins for LCD are SDA=A4 and SCL=A5

//Variables for sensors
    String sunlight;
    String watertemp;
    float airtemp;
    float airhumid;
    OneWire  ds(10); //water temperature, pin 10

//Variables for LCD button
    #define BUTTON_PIN A3    // Set pin Buttons for Backlight LCD.
    unsigned int currentLcdLightOnTime = 0; // For calculating the lcd light on time.
    unsigned long lcdLightOn_StartMillis;
    boolean isLcdLightOn;
    int buttonState = 0;// For checking push-button state.

// Variables for Status LED
    int ledState = LOW;             // ledState used to set the LED
    long previousMillis = 0;
    long interval = 1000;           // interval at which to blink (milliseconds)

//Variables to display LCD Numbers
    char bufferhours[5]; //Output of the itoa function for hours
    char bufferminutes[5]; //Output of the itoa function for minutes
    // We don't care for seconds. It's irrelevant.
    int moisture;

//Variables for Wifi Update
    //long DELAYWIFI = 10000; //For test purposes
    long DELAYWIFI = 300000; //Every 5 minutes
    long endtimewifi;
    long nowwifi;

//Variables for Servo
    long FEEDINGDELAY = 14400000; // Feed every 4 hours
    //long FEEDINGDELAY = 30000; //For test purposes
    int pos = 0;    // variable to store the servo position
    long endtime;
    long now;
    long timeuntilfeeding;

//Variables for Sunlight
    float percent; //transform number above into a percent

// Variables for Wifi Updates

    #include <SoftwareSerial.h>

    //Hardware Serial
    #define _baudrate 9600

    //Software Serial
    #define _rxpin      0
    #define _txpin      1
    SoftwareSerial esp8266( _rxpin, _txpin ); // RX, TX

    //Thingspeak and Wifi Information
    #define SSID "xxx"
    #define PASS "yyy"
    #define IP "zzz" // ThingSpeak IP Address: 184.106.153.149

    // GET /update?key=[THINGSPEAK_KEY]&field1=[data 1]&filed2=[data 2]...;
    String GET = "GET /update?key=www";

// Initiates special characters. http://omerk.github.io/lcdchargen/

byte thermometer[8] = //icon for thermometer
{
    B00100,
    B01010,
    B01010,
    B01110,
    B01110,
    B11111,
    B11111,
    B01110
};

byte droplet[8] = //icon for water droplet
{
    B00100,
    B00100,
    B01010,
    B01010,
    B10001,
    B10001,
    B10001,
    B01110,
};

byte degree[8] = { // degree centigrade
  B01000,
  B10100,
  B01000,
  B00011,
  B00100,
  B00100,
  B00011,
  B00000
};

byte sun[8] = {
    0b00100,
    0b10001,
    0b01110,
    0b11111,
    0b11111,
    0b01110,
    0b10001,
    0b00100
};

void setup()
{
  lcd.init();// initialize the lcd

//Initialize DHT/
    DHT11.attach(2);

// set the digital pin as output for LED:
    pinMode(13, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(11, OUTPUT);

//Connect to Wifi
    Serial.begin(9600);
    esp8266.begin(9600);
    boolean wifi_connected=false; //not connected yet...

    sendesp8266("AT");
    delay(2000);
    for(int i=0;i<5;i++) //attempt 5 times to connect to wifi - this is a good idea
    {
    if(connectWiFi()) //are we connected?
    {
    wifi_connected = true; //yes
    break; //get outta here!
    }
    }

//Initiate characters
    lcd.createChar(0, thermometer);
    lcd.createChar(1, droplet);
    lcd.createChar(2, degree);
    lcd.createChar(3, sun);

}

void loop(){
    now = millis();
    endtime = now + FEEDINGDELAY;

    while(now < endtime) {   // While loop for the feeding
    timeuntilfeeding = endtime - millis();
    now = millis();

    nowwifi = millis();
    endtimewifi = nowwifi + DELAYWIFI;

    while(nowwifi < endtimewifi) {   // While loop for wifi update
    nowwifi = millis();

//We capture sensors

    //Sunlight
    float value_sunlight = analogRead(A2);
    percent = value_sunlight / 1024.0 * 100;  //Convert dryness score into moisture percentage
    String sunlight =String(percent);// turn integer to string

    //Water Temperature
    float value_watertemp = getTemp();
    String watertemp= String(value_watertemp);// turn integer to string

    //Air Temperature and Humidity
    int chk = DHT11.read(); //Read DHT11 Sensor
    float airtemp=float(DHT11.temperature);// turn integer to string
    float airhumid=float(DHT11.humidity);// turn integer to string

    // LED Blinking
    unsigned long currentMillis = millis();
    if(currentLcdLightOnTime == 0){ //We only blink when LCD is not on
    if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    // set the LED with the ledState of the variable:
    digitalWrite(11, ledState);
    }}

  buttonState = digitalRead(BUTTON_PIN);// Check the state of the push-button.

  if (buttonState == HIGH){// Button pressed.

      digitalWrite(11, LOW);

    lcdLightOn_StartMillis = millis();
    currentLcdLightOnTime = 0;
    isLcdLightOn = true;
    lcd.setBacklight(1); // switch on the backlight

    //Screen 0 Presentation

    lcd.setCursor(0, 0);
    lcd.print(" Aquaponics Bot ");

    lcd.setCursor(0, 1);
    lcd.print("  Version 1.0      ");
  }

  else{
    // Button not pressed.

    //Serial.println("Button not pressed - LOW");

    if(isLcdLightOn){
      currentLcdLightOnTime = millis() - lcdLightOn_StartMillis;

        //Screen 2
        if(currentLcdLightOnTime > 3000 && currentLcdLightOnTime <= 6000){

    //Screen 2 - Air Temperature & Humidity

    //Line 1
    lcd.setCursor(0, 0);
    lcd.print("  Air Sensors  ");

    //Line 2
    lcd.setCursor(0, 1);
    lcd.write(0);
    lcd.print(": ");
    lcd.println(airtemp);
    lcd.setCursor(5, 1);
    lcd.write(2);

    lcd.print(" - ");
    lcd.write(1);
    lcd.print(": ");
    lcd.print(airhumid);
    lcd.setCursor(14, 1);
    lcd.print("%   ");

        }

        //Screen 3
        if(currentLcdLightOnTime > 6000 && currentLcdLightOnTime < 9000){

     //Screen 3 - Water Data

    //Line 1
    lcd.setCursor(0, 0);
    lcd.print(" Water Sensors ");

    //Line 2
    lcd.setCursor(0, 1);
    lcd.write(0);
    lcd.print(": ");
    lcd.println(watertemp);
    lcd.setCursor(5, 1);
    lcd.write(2);

    lcd.print(" -  soon   ");

   }

    //Screen 4

        if(currentLcdLightOnTime > 9000 && currentLcdLightOnTime < 12000){

   //Screen 4 - Light Sensors

    //Line 1
    lcd.setCursor(0, 0);
    lcd.print(" Light Sensors  ");

    //Line 2
    lcd.setCursor(0, 1);
    lcd.write(3);
    lcd.print(": ");
    lcd.println(sunlight);
    lcd.setCursor(5, 1);
    lcd.print("% - soon   ");

      }

            if(currentLcdLightOnTime > 12000 && currentLcdLightOnTime < 15000){

     //Screen 5 - Next Feeding

                long hours=0;
                long mins=0;
                long secs=0;

                secs = timeuntilfeeding/1000; //convect milliseconds to seconds
                mins=secs/60; //convert seconds to minutes
                hours=mins/60; //convert minutes to hours
                secs=secs-(mins*60); //subtract the coverted seconds to minutes in order to display 59 secs max
                mins=mins-(hours*60); //subtract the coverted minutes to hours in order to display 59 minutes max
                //Display results
                itoa(hours, bufferhours, 10);//Convert the number of hours into readable by LCD
                itoa(mins, bufferminutes, 10);//Convert the number of minutes into readable by LCD
                lcd.setCursor(0, 0);
                lcd.print("Fish Feeding: ");
                lcd.setCursor(0, 1);
                lcd.print(bufferhours);
                lcd.print(" hours ");
                lcd.print(bufferminutes);
                lcd.print(" min.   ");

   }

        // Turn Off the Screen
      if(currentLcdLightOnTime > 15000){
        lcd.clear();
        isLcdLightOn = false;
        lcd.setBacklight(0); // switch off the backlight

        currentLcdLightOnTime = 0; //So that the blinking can start again.
        ledState = LOW;
      }
    }
  }

    } // End of the while wifi loop

    // Make sure we are still connected to the internet

    esp8266.begin(9600);
    boolean wifi_connected=false; //not connected yet...

    sendesp8266("AT");
    delay(2000);
    for(int i=0;i<5;i++) //attempt 5 times to connect to wifi - this is a good idea
    {
    if(connectWiFi()) //are we connected?
    {
    wifi_connected = true; //yes
    break; //get outta here!
    }
    }

    digitalWrite(13, HIGH);

    //We capture sensors again to send the value

    //Sunlight
    float value_sunlight = analogRead(A2);
    percent = value_sunlight / 1024.0 * 100;  //Convert dryness score into moisture percentage
    String sunlight =String(percent);// turn integer to string

    //Water Temperature
    float value_watertemp = getTemp();
    String watertemp= String(value_watertemp);// turn integer to string

    //Air Temperature and Humidity
    int chk = DHT11.read(); //Read DHT11 Sensor
    String airtemp=String(DHT11.temperature);// turn integer to string
    String airhumid=String(DHT11.humidity);// turn integer to string

    updateTS(sunlight,watertemp, airtemp, airhumid);
    delay(3000); //
    digitalWrite(13, LOW);

  } // End of the while feeding loop

  // Double Swipe to Feed the Fish

    //Intialize Servo
    myservo.attach(3);  // attaches the servo on pin 3 to the servo object
    //Display that the fish is being fed.
    digitalWrite(13, HIGH);

    for(pos = 0; pos < 180; pos += 5)  // goes from 0 degrees to 180 degrees
      {                                  // in steps of 1 degree
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
       }

    for(pos = 180; pos>=0; pos-=5)     // goes from 180 degrees to 0 degrees
       {
         myservo.write(pos);              // tell servo to go to position in variable 'pos'
         delay(15);                       // waits 15ms for the servo to reach the position
       }

    myservo.detach();  // detattaches the servo from pin 3
    //Clears display
    digitalWrite(13, LOW);

    // SEND AN EMAIL OR UPDATE A DATABASE..

    }

    //----- update the  Thingspeak string with 4 values
    void updateTS( String L, String W , String T, String H)
    {
    // ESP8266 Client
    String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
    cmd += IP;
     cmd += "\",80";
    sendesp8266(cmd);
      delay(2000);
    if( Serial.find( "Error" ) )
    {
      esp8266.print( "RECEIVED: Error\nExit1" );
    return;
    }

     cmd = GET + "&field1=" + L +"&field2="+ W + "&field3=" + T + "&field4=" + H +"\r\n";
     Serial.print( "AT+CIPSEND=" );
     Serial.println( cmd.length() );
     if(Serial.find( ">" ) )
     {
     esp8266.print(">");
     esp8266.print(cmd);
     Serial.print(cmd);
     }
     else
     {
     sendesp8266( "AT+CIPCLOSE" );//close TCP connection
     }
     if( Serial.find("OK") )
     {
     esp8266.println( "RECEIVED: OK" );
    }
    else
    {
    esp8266.println( "RECEIVED: Error\nExit2" );
     }
     }

    void sendesp8266(String cmd) //Send info to esp8266
     {
    esp8266.print("SEND: ");
     esp8266.println(cmd);
     Serial.println(cmd);
     }

     boolean connectWiFi()
      {
     digitalWrite(11, LOW);
     digitalWrite(12, HIGH);
     Serial.println("AT+CWMODE=1");//WiFi STA mode - if '3' it is both client and AP
     delay(5000);
     //Connect to Router with AT+CWJAP="SSID","Password";
     // Check if connected with AT+CWJAP?
     String cmd="AT+CWJAP=\""; // Join accespoint
     cmd+=SSID;
     cmd+="\",\"";
     cmd+=PASS;
     cmd+="\"";
     sendesp8266(cmd);
     delay(15000);

     digitalWrite(12, LOW);

     if(Serial.find("OK"))
     {
      esp8266.println("RECEIVED: OK");
      return true;
     }
     else
     {
       esp8266.println("RECEIVED: Error");
       return false;
     }

     cmd = "AT+CIPMUX=0";// Set Single connection
     sendesp8266( cmd );
     if( Serial.find( "Error") )
     {
     esp8266.print( "RECEIVED: Error" );
      return false;
     }
   }

   float getTemp(){ //Get the water temperature
    //returns the temperature from one DS18S20 in DEG Celsius

    byte data[12];
    byte addr[8];

     if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
     }

    if ( OneWire::crc8( addr, 7) != addr[7]) {
     Serial.println("CRC is not valid!");
     return -1000;
    }

    if ( addr[0] != 0x10 && addr[0] != 0x28) {
     Serial.print("Device is not recognized");
      return -1000;
    }

    ds.reset();
    ds.select(addr);
    ds.write(0x44,1); // start conversion, with parasite power on at the end

     byte present = ds.reset();
    ds.select(addr);
    ds.write(0xBE); // Read Scratchpad

    for (int i = 0; i < 9; i++) { // we need 9 bytes
     data[i] = ds.read();
    }

    ds.reset_search();

    byte MSB = data[1];
    byte LSB = data[0];

    float tempRead = ((MSB << 8) | LSB); //using two's compliment
    float TemperatureSum = tempRead / 16;

    return TemperatureSum;

    }

I'd suggest to use the timer one to do stuff as well. Since the timer one can be used to do things along side with the main program. Just search on Google for timer one arduino and read the tutorial.

You're sending AT commands hea? Usually they'll give an response, I'd rather check the response instead of using a delay and then another AT command to verify it?

If i follow you correctly, why would you read sensors while uploading data? Even on a full pc you would first collect data then act and report.

As already pointed out,
You can use a while loop for your purposes:
while(adc/send/recive_flag == 1){
// do stuff
}

instead of the very bad habit of using delay. (You don't need to wait any longer than you have to)
As for LCD and RGB leds, use them inside an interrupt. Make interrupt timer something like 50 ms. This way, whatever main code you are running, ISR will timout and LCD and RGB will be updated.

Capture data (light, temperature, etc.)

Use dedicated atmega registers to read ADC. AnalogRead is SLOW. I think you can find information about this all over google.

Upload data to thingspeak every 5 minutes

This should be fine. Increase transmission BAUD RATE if necessary.
To me the way it looks, you have to wait for data capture, theres no solution for that so make it faster.
As for Wifi, disable ISR, send a single message, enable ISR and wait for a bit and so on. Something like this could work.
As for feeding the fish, all you do is send PWM to servo, right? Use dedicated PWM registers on atmega for faster execution but it doesn't matter anyway for the LCD and RGB LED because they are in interrupt routine so they will be updated anyways.

You can use several approaches.
Lesto already pointed out the finite state machine, but this approach will run the code as fast as possible and this might not be the behaviour you want. It's a good approach to manage, for instance, wifi connections and other communications but it won't let you schedule a task in a fixed pace.
Other options:
1) In the arduino default examples there's "Blink without delay" (\examples\digital), here you can read the code explanation. It's different from what you used
(while(now < endtime))
because your code execution is kept inside the while.
If you otherwise use an
if (currentMillis - previousMillis >= interval)
the code will do the check but it  continues to run other instructions until the right time has come.
2) Use a scheduler!
This is handy if you have several different tasks that should run at a constant (and relatively slow for the MCU) pace.
For instance:
#include "leOS.h"
leOS myOS

void setup() {
  myOS.begin();
}
void setup() {
  myOS.begin();
  myOS.addTask(updateTS, scheduleTime[30000, SCHEDULED]);
}

With this code you'll run the updateTS function every 5 min, without blocking the execution of other tasks.

Instead of using a delay, you may use some variable (maybe a struct or an object) to keep the status of your transmission or reading; every things that need a delay became a new state in this state-machine, every loop, based on witch status you have, you check if there are the information to execute the next step.
You may have multiple thing with status, but if they share a resource you'll need to add an abstraction layer on that resource to take care of that. (Like an event system or a message router or an output buffer)
Also you may have a status in witch you wait for a status in another state machine.

Thanks for your message. Would you have an example?

i think you need to learn some basic programming pattern, in this case we are talking about a "finite state machine", see http://en.wikipedia.org/wiki/Finite-state_machine


text:
Bluetooth hc-06 and Standalone Atmega168(possible?)
I am making a project that requires bluetooth communication between a Raspberry Pi(equipped with a bluetooth dongle) and a standalone atmega168 circuit.
I want to be able to transfer information serially between the two devices over bluetooth.
I have selected the hc-06 for the arduino and some usb bluetooth dongle for the PI.
I would like to know if connecting the hc-06's TX and RX pins to the RX and TX (respectively) pins of my atmega will work or not. If not, I would like to know how to achieve that (bluetooth on a standalone arduino-powered microcontroller)

Sound fine to me.

The HC-0x Bluetooth transceivers are a drop-in replacement for a serial connection. Once the transceiver is configured (with baud-rate, device name, and pairing PIN #) you can plug it in in place of a serial line and expect to communicate. The device will take care of pairing and accepting a connection from the master device with no need for any code support from the AVR.
I use a separate program on an Arduino or a breadboarded AVR to configure my HC-06es. They retain their configuration across a power-down, and in fact, there is no hardware support for resetting them to a standard configuration; you need a program that figures out their current baud-rate in order to reconfigure them. It can save a bunch of hassle if you write down their configurations whenever you change them.

I have read somwewhere that a circuit for usb to serial is needed. I think that is for converting usb to serial(and back). Is it so ?

You'll need a USB to serial converter to connect your at mega to a computer through USB. But when you want to reprogram your atmega just use the arduino as ISP tutorial.

No circuitry is needed on the Arduino or AVR side; the HC-0x devices are directly pin-to-pin compatible, making them very convenient for standalone AVR devices. If you were thinking of the FTDI (or similar) serial to USB converters on Arduino boards, HC-0x devices don't need one.

source: Stack Exchange

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

sort: votes


text:
Compile problem when using keyword 'new' on Raspberry Pi
I have the following line of code in my Arduino sketch:
static double *temps = new double[arraySize];  //Declare array to hold tempratures, place the array on the heap where it will not be deleted and keep the pointer as a static
//double temps[arraySize];

When I compile with the Arduino IDE on Ubuntu it compiles just fine. However, when I compile on the Raspberry Pi, it throws up the following error:
xxx.cpp.o: In function `last Function in file()':
xxx.cpp:[last line in file]: undefined referance to `operator new[] (unsigned int)'
collect2: error: ld returned 1 exit status

Is this a bug? If so, how do I report it? If not, why is it throwing this error or how else can I declare a static array of doubles (needs to be static, I calculate an average of some incoming data over several function calls)?

What version of arduino is the Pi running?

The Arduino uses AVR libc which does not provide a complete C++ environment.
Among other things AVR libc does not support new and delete. See the FAQ for more information.
Some versions of the Arduino libraries may provide new and delete but they are just wrappers around malloc and free. I suggest not using new and delete on arduino because they do not have the same behavior as C++. For example destructors will not be called on the arduino when delete is called.

how else can I declare a static array of doubles (needs to be static,
  I calculate an average of some incoming data over several function
  calls)

When you find a bug in the Arduino software, please do report it to the appropriate place -- http://arduino.cc/en/Main/ContactUs has the contact details.
One way to declare a static array of doubles is like this:
double boxcar_average(double new_sample) {
  const int arraySize = 3;
  static double old_sample[ arraySize ] = {0};
  double sum = new_sample;
  for(int i=0; i<arraySize; i++){
    sum += old_sample[i];
  }
  old_sample[0] = old_sample[1];
  old_sample[1] = old_sample[2];
  old_sample[2] = new_sample;
  return( sum / 4 );
}

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


text:
What do these operators do?
Going through the "timeouts" example of the elapsedMillis library (https://github.com/pfeerick/elapsedMillis) I found the following statement:
digitalWrite(LEDPIN, flashPattern[ledIndex++] ? ledBrightness : !ledBrightness);

flashpattern is an array of boolean variables  (boolean flashPattern[] = { 1,1,1,1,1,1,1,0,1,1,0 };)
ledBrightness is a boolean as well.

What does the "?" and the ":" do there? are these boolean operators?

A ? B : C;

is shorthand for
if(A) {
    B;
} else {
    C;
}

It is not. B and C are not allowed to be statements or blocks, and if is not a valid RHS.

They are the conditional operator. If the expression before the ? is true then the result is the expression before the :, otherwise it is the expression after.

Also known as Ternary Operators http://www.cprogramming.com/reference/operators/ternary-operator.html


text:
How to power both arduino and 1 color led strip from single power source

I'm trying to understand and adapt this tutorial:
https://learn.adafruit.com/rgb-led-strips/current-draw
to my own use. I am doing essentially the same thing, except I have this single color LED strip, and I don't fully understand how to power both the arduino and the led strip from the same power source.
I tried to wire it using the diagram above, and something started smoking (I think the IR transmitter). I don't know much about circuits, but I'm pretty sure that's not good.
In this diagram, the 9v represents DC power, the IR sensor on the left represents the transmitter, the IR on the right is the receiver, and the white LED is the LED strip, with two outputs (+ - )
In the fritzing diagram for that tutorial, they have the + from the LED strip going straight in to Vin on the uno, but they don't show how either the LED strip or the uno themselves are being powered.
Do I need two power sources?
Do I need a mosfet considering I'm only using a one color LED strip?
I've got the IR sensors working, so I don't need help with that, and I can connect one of these 12V switching power supplies to one of these DC power screw terminals to power the lights without any arduino control, so all I'm missing is how to turn the lights on and off with arduino, IE, how to go from the power supply to the arduino to the LED strip.
I don't need to PWM the LED strip - just shut it off and on.
If anyone can help me correct the fritzing diagram or explain what I'm doing wrong / what I should be doing instead, I'd greatly appreciate it.

Note that VIN pin and the 2.5mm DC Jack are connected. So in the tutorial one of these is getting power from a +12Vdc source and the other is supplying +12V to the +12v labeled pin on the LED string. Where the R G and B pins of the strip should be connected to Collectors of NPN's. Each of the NPN's bases are driven by Arduino Output pin and all the Emitters are connected to Ground.
So +12V supplies the DC Jack (aka Vin) the Arduino's local regulator converts that to Ground. The +12V via Vin supplies the LED's. And the Digital Outputs drive the base's of the NPN's. Which in turn act like a relay closing the perspective LED's to Ground, so they can illuminate. Where a Digital ONE or HIGH or TRUE on the BASE results in 5V above ground, which causes it to have low resistance.

Sorry, I don't understand your diagram. Also, I think the details of my project are different. I am using a MOSFET (http://www.adafruit.com/datasheets/irlb8721pbf.pdf) so I'm dealing with G D S, and I'm using a single color LED strip - so + and - vs R G B + .  Is it possible to explain your answer as it relates to the fritzing diagram? Sorry, I'm trying to understand but I'm not clear on a few things: is the 7805 the IC of the arduino? How does the power split both to the IC and the Vin? what is the R? What are the two resistors resisting? What about the breakbeams?

You can use a mosfet instead of the transistor in the circuit. If you use a mosfet you can keep out R1. Since you only have one color, you can ignore the 3x part. Only the dash-outlined circuit, you need to build. The rest is part of the arduino board. Including the Vin pin (which is connected on the board to the jack). R1 is to limit the base-current going into the transistor. Without it the transistor will burn out, and possibly the output-pin. R2 is a pull down, so the led doesn't light up during power-up
I think the values for the two resitors are wrong. I'd use 1k for R1 and 10k for R2.

You asked: "Do I need a mosfet considering I'm only using a one color LED strip?"
Yes, absolutely. An Arduino logic line can only put out about 20 mA of power at 5V. That's not an unreasonable amount of power for a single low-power LED. An LED strip is likely to draw a lot more current than that, and it's pretty common for LED strips to use 12V, not 5V.
What LED strip are you using, and what input voltage and current requirements does it have?
You should be able to use a single power 12V power supply for your project. (assuming your LED strip needs 12V.) You'd feed it into the barrel jack of the Arduino. The Arduino's voltage regulator would use that to generate its 5V power. You'd also feed 12V into the power for your LED strip. You'd use a logic-level MOSFET to switch the power to the LED strip on and off. A logic level MOSFET is able to use a low current 5V signal from the Arduino to switch higher voltage, higher current loads like your LED strip with very little resistance, and thus with very little waste heat generated.

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


text:
Data Loss over Serial Communication thru GSM SIM9000A Modem
I have an Arduino Megs 2560 board and using Serial 2 for communication with SIM9000A GSM Modem. I send over a HTTP get request by using appropriate AT command strings.
The GSM modem TX/RX pins are crossed with Arduino's Serial 2 port while the GSM modem card which also has DB9 pins is connected to a Hyper terminal - to see what it is receiving / rendering.
My issue is when I have to read after I get a response for my HTTP Get request.
Below is my code:
int Read(String message)
{
      char temp = '\0';
      int i=0;
      numbytes = 0;
      message= "";
      int endCnt = 0;
      debug_println("Reading Data!");
      Serial2.println("AT+HTTPREAD");
      delay(200);
      while(endCnt < 4) {
      while((Serial2.available())>0) {
          temp = Serial2.read();
          Serial.print(temp);
          switch(temp) {
            case '\r' : endCnt = 1; break;
            case '\n' : if(endCnt == 1) endCnt = 2; else endCnt = 0; break;
            case 'O'  : if(endCnt == 2) endCnt = 3; else endCnt = 0; break;
            case 'K'  : if(endCnt == 3) endCnt = 4; else endCnt = 0; break;
            default   : endCnt = 0; break;
          }
          if(endCnt == 4) break;

        }
     }
     debug_println("Read Data Ret: ");
     return i;
}

Note the Terminal shows me correctly when a HTTPREAD command is passed to GSM modem:
+HTTPACTION: 0,200,286

+HTTPREAD: 286

{"first_name":"dddddddddddddd","last_name":"dddddddddddddddd","start_date":"2000-12-31","chargeamt":"09.80","status":"ok","id":"68"}

<!-- Hosting24 Analytics Code -->

<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>

<!-- End Of Analytics Code -->

OK

But Serial port printing shows me :
Reading Data!

+HTTPREAD: 286
{"first_name":"dddddddddddddd","last_name":"ds Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

OK

So after reading 45-46 th character at Serial2 port I am loosing data. I have tried all ways but unable to understand why my data at serial port is lost / overwritten?
Please let me know how can I resolve this?
====UPDATE====
After struggling a lot I was able to resolve the issue.
The code "delay(200);" after Serial2.println("AT+HTTPREAD"); was causing the issue. When I reduced the time I got the response as required.

You probably shouldn't use that delay at all - it certainly isn't needed, unless your reading code is buggy.  Also note that if you are re-echoing characters, your "Serial" baud rate needs to equal or exceed that of your "Serial2" or you will start to fill up your receive buffer and possibly overflow it for longer messages.


text:
Motor Shield with 4 DC motors + small servo, which battery is suitable?
I am building my first 4wd vehicle with Adafruit motor shield with one Ultrasonic sensor and one small servo to move sensor.
I am facing some problems.

Bought 4 motors (2 GM9 and 2 GM3), found the difference when start running and GM9 were running double the speed of GM3. Tried to slow down th eGM9 with speed in code but now one of the motor stop many times while other run.
Running spearate power for Arduino (now USB) and 9v batteries for motorshield. Should I remove the jumper on motor shield as found that after removing 9v battery, its getting some volts from Arduino and motors running very slowly.
Servo motor is not running at all. While its pins are according to the circuit.
Should 9v batteries will be OK to run 4 GM9/GM3 motors + 1 small Servo? if not please recommend any other.
When running I feel small smell from boards, nothing is hot, is it a problem?

Too many questions but tried to put in one place.
Thanks

9v batteries can't produce much current. Better use a pack of AA NiMH batteries. If a new board gets warm it might smell a bit. Should go away after a while, but keep checking that nothing gets too hot.

Thanks for reply. what about the jumper on motor shield? its removed now but still getting current from Arduino.

Removing the jumper would be a good idea. With the jumper, the arduino would run on the same 9v battery instead of the usb power. Sudden spikes in power draw could crash/hang the arduino. I don't see how the motors could be running without the 9v battery attaches. That one puzzles me.

The Arduino is connected to USB to PC, but motorshield is with 9v battery. When I disconnect motorshield from battery the wheels runs and green light on sheild is still on.

From my understanding that shouldn't happen, so I guess my understanding is wrong (-: . Does this also happen without the jumper attached?

yes I checked with/without both. I am afraid if I connect 6 AA cells now it could burn one or both boards. I checked the adafruit site as well for connections.


text:
Location of examples folder in Ubuntu
I'm trying to add some additional example files to the Arduino IDE in Ubuntu 14.04. However, I can't for the life of me find where the examples are stored in my system. I checked the Arduino website, but can't find any information there. Does anyone know where I need to put my additional files?

Usually there is no good reason to know where the folder is. The examples are available in Arduino IDE in Files->Examples menu and it doesn't make much sense to add more sketches to built-in examples in local installation.

After some more searching I found it in /usr/share/arduino/examples.

I found mine in Linux Mint 17.3 under opt/arduino/examples

In Ubuntu I found arduino library on
/home/MYUSERNAME/snap/arduino
where MYUSERNAME is user name

don't install Arduino IDE with snap. it installs some old version

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


text:
ADXL345 Arduino UNO data_ready interrupt
I would like the sensor values to be updated each 10ms(100Hz) and then run the algorithm and repeat the same process. However, after timing the algorithm it is taking only 2ms, I think the data_ready interrupt is not working as expected. Physical hardware connection is from INT1 of ADXL345 to pin2 of the UNO.
edit:
I have configured the accelerometer to have a data rate of 100Hz. I have set up an interrupt with data_ready to run the algorithm present in the loop each time a new sample comes that is each 10ms. However each sample is coming every 2ms which shows the interrupt is not working and I would like to know why. I have timed the interrupt with the millis(); function before and after calling the interrupt, also I have stored the samples in an array and printed it on the serial interface and the samples were repeated as it was updated every 2ms instead of 10ms. The algorithm I have developed needs the sampling rate to be 100Hz.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <avr/io.h>
#include <avr/power.h>

#define F_CPU 16000000UL

volatile int sensor_update=0;

//-----------------------------------------------------------------------------------     -----------
//Write to ADXL345 registers
void writeTo(int device, byte address, byte val) {
Wire.beginTransmission(device); //start transmission to device
Wire.write(address);        // send register address
Wire.write(val);        // send value to write
Wire.endTransmission(); //end transmission
}

//----------------------------------------------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////////////////////

//ISR function

void interrupt(void){
sensor_update=1;

}

//////////////////////////////////////////////////////////////////////////////////////////////////

void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000/frequency/2; // calculate the delay value between     transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since

  //// there are two phases to each cycle
  //// calculate the number of cycles for proper timing
  long numCycles = frequency * length/ 1000;

  //// multiply frequency, which is really cycles per second, by
  //// the number of seconds to get the total number of cycles to produce
  for (long i=0; i < numCycles; i++){ // for the calculated length of time...
    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value
  }
}

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup(void)
{
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  Serial.begin(9600);
  //Serial.println("Accelerometer Test"); Serial.println("");

  pinMode(4, OUTPUT);// buzzer output pin

  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    //Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL345_RANGE_16_G);
  accel.setDataRate(ADXL345_DATARATE_100_HZ);
  // displaySetRange(ADXL345_RANGE_8_G);
  // displaySetRange(ADXL345_RANGE_4_G);
  // displaySetRange(ADXL345_RANGE_2_G);

  //Create an interrupt that will trigger when a tap is detected.
  attachInterrupt(0, interrupt, RISING);

  writeTo(0x1D, 0x2E, 0);
  writeTo(0x1D, 0x2F, 0);
  writeTo(0x1D, 0x2E, 128);
  writeTo(0x1D, 0x2F, 127);
}

void loop(void)
{

  if(sensor_update==1 ){
    //When sensor_update is set to 1 in the ISR,the algorithm process the data from the accelerometer being updated every 10ms(100Hz)
     sensor_update=0;//reset
  }
}

It looks like some of your code got cut off; could you add that? also, can you try and give a more detailed description of what you want the code to do? what did you use to time your code?

basically my algorithm needs a sampling rate of 100Hz and that is what I used to develop it in the first place. The interrupt even though configured with this data rate is not working as expected, I am guessing it is an interrupt setup problem.

Should you be manually running the interrupt function in the loop, or should that only run when the sensor causes the interrupt to happen?

I actually just spotted that. After removing the interrupt call from the loop, the interrupt simply never kicks in now. The enable and map registers are set up correctly,could someone confirm that please.

after some troubleshooting: putting pin2 as an input doesn't change anything.
testing if the output from ADXL INT1 is toggling with 1Hz output rate with a multimeter give 0V so the problem is coming from the accelerometer, somehow it is not generating anything.
edit: I have changed the device to 0x53 instead of 0x1D and now the LED is always on, still not toggling tough.

According to the data-sheet:

The interrupt functions are latched and cleared by either reading the
  data registers (Address 0x32 to Address 0x37) until the interrupt
  condition is no longer valid for the data-related interrupts or by
  reading the INT_SOURCE register (Address 0x30) for the
  remaining interrupts.

Therefore, an ISR that just sets a flag will not be called a second time. At the very least, you need to read the INT_SOURCE register. If you are using the SparkFun ADXL345 library, then this would be a call of the form:
ADXL345 adxl = ADXL345();
void setup() {
  adxl.powerOn();
  adxl.setInterruptBitLevel(true); // active low
  attachInterrupt(digitalPinToInterrupt(interruptPin), isr, LOW);
  pinMode(interruptPin, INPUT);
  adxl.singleTapINT(1);
  ...
}

void isr(void) {
  detachInterrupt(digitalPinToInterrupt(interruptPin));
  interrupts();
  byte source = adxl.getInterruptSource();
  ...
  attachInterrupt(digitalPinToInterrupt(interruptPin), isr, LOW);
}

Note that I use a level-triggered interrupt here and re-enable interrupts before calling adxl.getInterruptSource(). The issue is that this call may take some time to talk over the I2C bus. To ensure that there are no reentrant calls, I detach the interrupt first. Without this, the level-triggered mode causes an interrupt loop.
The use of a level-triggered interrupt makes sense because the ADXL won't produce another interrupt until you read from INT_SOURCE. It also avoids the problem of missing an edge detection, which tends to cause subtle bugs that are hard to find.
I was unsure about the soundness of turning on interrupts within the ISR and so asked a question about this - What is the right way to query an I2C device from an interrupt service routine?

Been bashing my head with this one. And have searched the internet for a solution And tried for hours to program a solution.
From my tests the problem seems to be the Register 0x30—INT_SOURCE is populated with triggers. But the INT pin is only triggered when the  Register 0x30—INT_SOURCE is read.
This means that firstly the Arduino can't be woken from sleep by the INT1 or INT2 pins because they don't change unless the Arduino is already awake and reading the Register 0x30—INT_SOURCE
Second problem is to trigger an interrupt INT pin to jump to the ISR interrupt service routine you have to read Register 0x30—INT_SOURCE. And if you are going to do that then you might as well forget the interrupt and just jump into the ISR() and check registers in that. Which is how the example in the Sparkfun_ADXL345_Example for arduino ended up with the  ADXL_ISR(); call in the main loop. To sum up. Unless some one knows away to get the ADXL345 to change state on its INT pins without the need to read Register 0x30—INT_SOURCE, then the device is useless for use with the INT pins. I have given up on it and looking for another device to wake my ESP32 from sleep. Such as the BMI160 - Bosch which looks like a contender and has a arduino library for.


text:
Can't figure out the error to this code
I've written up this very simply code to control transistors in an inverter circuit. The editor is flagging up errors which I can't see myself. I'm pretty new to Arduino programming but it's very simple code and can't see why it's being shown as having errors.
At first glance, what am I missing? I've pasted a section below:
int Phase1pos = 13;
int Phase2pos = 12;
int Phase3pos = 11;
int Phase1neg = 10;
int Phase2neg = 9;
int Phase3neg = 8;

void setup() {
pinMode(Phase1pos, OUTPUT);
pinMode(Phase2pos, OUTPUT);
pinMode(Phase3pos, OUTPUT);
pinMode(Phase1neg, OUTPUT);
pinMode(Phase2neg, OUTPUT);
pinMode(Phase3neg, OUTPUT);
}

void loop() {
    delayMicroseconds(16);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(16);

    delayMicroseconds(7);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(7);

    delayMicroseconds(2);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(2);

    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(104);
    digitalWrite(Phase2pos, HIGH);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(208);
    digitalWrite(Phase1pos, LOW);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(104);
    digitalWrite(Phase3neg, LOW);

    delayMicroseconds(2);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase3neg, LOW);

    delayMicroseconds(7);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(7);

    delayMicroseconds(16);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase3neg, LOW);
    digitalWrite(16);

    delayMicroseconds(28);
    digitalWrite(Phase3neg, HIGH);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(180);
    delayMicroseconds(180);
    digitalWrite(Phase1pos, LOW);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(28);

    delayMicroseconds(16);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(16);

    delayMicroseconds(7);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase1pos, LOW);

    delayMicroseconds(2);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(2);

    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(104);
    digitalWrite(Phase2neg, HIGH);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(208);
    digitalWrite(Phase3neg, LOW);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(104);
    digitalWrite(Phase1pos, LOW);

    delayMicroseconds(2);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(2);

    delayMicroseconds(7);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(7);

    delayMicroseconds(16);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(16);

    delayMicroseconds(28);
    digitalWrite(Phase1pos, HIGH);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(180);
    delayMicroseconds(180);
    digitalWrite(Phase2neg, LOW);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(28);

    delayMicroseconds(16);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(16);

    delayMicroseconds(7);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(7);

    delayMicroseconds(2);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(2);

    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(104);
    digitalWrite(Phase1pos, HIGH);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(208);
    digitalWrite(Phase3pos, LOW);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(104);
    digitalWrite(Phase2neg, LOW);

    delayMicroseconds(2);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(2);

    delayMicroseconds(7);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(7);

    delayMicroseconds(16);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase1pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase1pos, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(16);

    delayMicroseconds(28);
    digitalWrite(Phase2neg, HIGH);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(180);
    delayMicroseconds(180);
    digitalWrite(Phase3pos, LOW);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(28);

    delayMicroseconds(16);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(16);

    delayMicroseconds(7);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(7);

    delayMicroseconds(2);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(2);

    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(104);
    digitalWrite(Phase1neg, HIGH);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(208);
    digitalWrite(Phase2neg, LOW);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(104);
    digitalWrite(Phase3pos, LOW);

    delayMicroseconds(2);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(2);

    delayMicroseconds(7);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(7);

    delayMicroseconds(16);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase2neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(16);

    delayMicroseconds(28);
    digitalWrite(Phase1neg, HIGH);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(180);
    delayMicroseconds(180);
    digitalWrite(Phase3pos, LOW);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(28);

    delayMicroseconds(16);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(16);

    delayMicroseconds(7);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(7);

    delayMicroseconds(2);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(2);

    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(104);
    digitalWrite(Phase2pos, HIGH);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(208);
    digitalWrite(Phase3pos, LOW);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(104);
    digitalWrite(Phase1neg, LOW);

    delayMicroseconds(2);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(80);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(47);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(159);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(47);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(80);
    digitalWrite(Phase2neg, LOW);
    delayMicroseconds(2);

    delayMicroseconds(7);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(93);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(108);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(93);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(54);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(7);

    delayMicroseconds(16);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase3pos, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase3pos, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(16);

    delayMicroseconds(28);
    digitalWrite(Phase1neg, HIGH);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(180);
    delayMicroseconds(180);
    digitalWrite(Phase2pos, LOW);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(28);

    delayMicroseconds(16);
    digitalWrite(Phase2pos, HIGH);
    delayMicroseconds(27);
    digitalWrite(Phase1neg, HIGH);
    delayMicroseconds(138);
    digitalWrite(Phase3neg, HIGH);
    delayMicroseconds(54);
    digitalWrite(Phase3neg, LOW);
    delayMicroseconds(138);
    digitalWrite(Phase1neg, LOW);
    delayMicroseconds(27);
    digitalWrite(Phase2pos, LOW);
    delayMicroseconds(16);
}

Welcome to Arduino SE. It would be helpful if you could post the error messages that you're getting.

Hi, thanks!  In function 'void loop()':
99: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
109: error: at this point in file

I've found the one at line 109 but the one at 99 I can't seem to see

I copy/pasted it, fixed 109, it compiled...

Here's line 109:
 digitalWrite(16);

As the error message says, there aren't enough arguments. It looks like you meant to call delayMicroseconds() there instead of digitalWrite().


text:
delay() vs delayMicroseconds()
I just started using Arduino and so far I've used both delay() and delayMicroseconds(). I was wondering what the difference between these two is, because it seems to me that they're the same.

From the documentation:

delay()
Description
Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.)

So... milliseconds vs. microseconds.

Wow. Can't believe I missed that.


text:
Why doesn't the Micro OLED library compile on my DUE?
I have an Arduino DUE and just got a Micro OLED display from SparkFun.
Using their library, when I try to compile I get the error below.  Other example code works just fine and I've programmed this thing a million times with my code.  So it's clearly in the SparkFun code.
Here is the SparkFun tutorial page with a description of the product:
https://learn.sparkfun.com/tutorials/micro-oled-breakout-hookup-guide?_ga=1.19136059.2055231411.1404437767
Here is the library I am using:
https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED
Here is the error I get:
Build options changed, rebuilding all

/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp: In member function 'void MicroOLED::spiSetup()':

/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:46:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
    ssport  = portOutputRegister(digitalPinToPort(csPin));
            ^
  /Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:48:51: error: 'portModeRegister' was not declared in this scope
    ssreg  = portModeRegister(digitalPinToPort(csPin));
                                                     ^
  /Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp: In member function 'void MicroOLED::i2cSetup()':
  /Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:84:2: error: 'TWBR' was not declared in this scope
    TWBR = ((F_CPU / I2C_FREQ) - 16) / 2;
    ^
  /Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp: In member function 'void MicroOLED::parallelSetup()':
  /Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:109:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
    ssport  = portOutputRegister(digitalPinToPort(csPin));
            ^
  /Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:111:51: error: 'portModeRegister' was not declared in this scope
    ssreg  = portModeRegister(digitalPinToPort(csPin));
                                                     ^
  /Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:114:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
    wrport  = portOutputRegister(digitalPinToPort(wrPin));
            ^

/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:119:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
    rdport  = portOutputRegister(digitalPinToPort(rdPin));
            ^
  Error compiling.

That library is uses some AVR specific methods, that aren't implemented for the ARM processor in the Due.

Ah, that makes sense.  If you want to put this as an answer I will accept.  Thanks

That library is uses some AVR specific methods, that aren't implemented for the ARM processor in the Due.
I don't see a real easy way to port those methods.

This sucks because the DUE has a ton of RAM, 3.3v native so no converters, and is super fast.  Would make an awesome mini-OLED console.  :-)  And yes, I'm old enough that 96K is a lot of RAM.  lol


text:
High Frequency Sine Wave Generation
I'm new to the world of Arduino and I'm working on a wireless charging project that needs a 5.7MHz sine wave. I've tried using a Due and changing the PWM and DAC, but I can't get a clean sine wave at that frequency using anything I've found online. My signal is either way too low, or too high and horribly distorted.
Any help would be appreciated. I have access to a Mega, Due, Uno, and Mini.

That's much too fast for any Arduino. Have you considered an external DDS like AD9850?

Would the http://electronics.stackexchange.com/ be a better place for this question?

To generate a square wave, you only need to update the output at a rate of two points per cycle. (Technically, when the Arduino's PWM output is configured for 50% duty cycle, that's a square wave at some frequency.)
But to generate a clean sine wave (without a lot of distortion), you need to update a lot more frequenclly than two points per cycle. Personally I wouldn't want to go much below 20 points per cycle.
Imagine the sine wave is generated by a wheel that spins at some rate. Viewed from the edge, a point on the edge of the wheel traces out a sine wave. Viewed from the axle, you see the point going around in a circle.
Now instead of spinning the wheel continuously, suppose the wheel moves in steps of 30 degrees, 12 steps for a complete turn. Instead of a continuous sine wave, you get discrete steps of 0, 0.5, 0.866, 1, 0.866, 0.5, 0, -0.5, -0.866, -1, -0.866, -0.5, 0, 0.5, ...   Although this sequence approximates an ideal sine wave, it's pretty coarse because the steps are so large.
Now try 15 degrees per step (24 steps per cycle). Now you get 0, 0.259, 0.5, 0.707, 0.866, 0.965, 1, ... Much smoother, although the steps are still fairly noticeable.
So there will be less phase error, the more steps there are per cycle of the signal. That's not the only source of distortion however. There is also round-off error due to the limited resolution of the Digital-to-Analog Converter (DAC). For example, the value 0.866 I mentioned above should actually be an irrational value, half the square root of 3. Since it's an irrational number, there's no way for a real DAC to get this value exactly right. DAC output step values are ideally based on powers of two (1/2, 1/4, 3/4, 1/8, 3/8, 5/8, 7/8, etc.). And furthermore a real DAC can have offset error, gain error, non-linearity, as well as uncertainty about precisely when the new programmed value is reached.
There's also frequency error when the system's highest-frequency master clock is divided by an integer. If the Arduino UNO's master clock frequency is 16MHz, and the SPI setup function setClockDivider() is used to divide the master clock by 2, that's 8MHz. Divide by 3 and you get 5.333MHz. Divide by 4, that's 4MHz. Divide by 5, that's 3.2MHz. There's no way to get a clock frequency that's between these discrete steps. For small divisors, there's a big jump between steps. So if you needed to be able to smoothly adjust the frequency, you'd need a much higher master clock frequency. And, if you needed to configure the 16MHz Arduino UNO to an SPI clock frequency of exactly 5.7MHz, that's just not possible -- setClockDivider(2) is too fast, setClockDivider(3) is too slow, and setClockDivider(2.807017543859649) isn't supported by the hardware.
If your system could write to a DAC at an update rate of 12MHz, then 12 points per cycle gives a 1MHz output, and 24 points per cycle gives a 500kHz output. Or taking it the other way round, if you need to generate a 5.7MHz output waveform, then the DAC update rate needs to be somewhere around 100MHz to get a clean, low-distortion waveform. This is probably beyond the limit of what you can directly synthesize in software using something like an Arduino or a Raspberry Pi. A 16MHz Arduino UNO could maybe synthesize a few 100kHz using software synthesis, but at 1MHz there's going to be significant distortion.
Software-controlledDirect Digital Synthesis is very sensitive to timing, so the actual DAC update would need to be implemented in an interrupt service routine, run by a periodic timer. ( See https://electronics.stackexchange.com/questions/26363/how-do-i-create-a-timer-interrupt-with-arduino )  If you just used a while loop with a delay statement, then whenever the code needs to do something else, the waveform would just freeze up. This is more of a problem if the Arduino is trying to manage several other tasks at the same time as it is synthesizing the waveform.
Hardware Direct Digital Synthesis (DDS) is possible. Same principles. There needs to be a phase accumulator, which is just a counter that keeps track of the phase angle of the "wheel" that's generating the sine wave. (The phase accumulator needs to be modulus 360 degrees or 2 pi radians, but there's no requirement to count in 1 degree steps. Better to divide the circle into 2^N slices so that 360 degress maps to the natural counter overflow value.) And there also needs to be a lookup table with the sine value for each of those steps. This lookup table only needs to cover 90 degrees of the sinewave, because the waveform is symmetrical -- the other three quadrants can be found by 2's complementing the values and indexing from the other end of the table. Or, the sine can be approximated by a polynomial calculation. More steps x more DAC resolution requires a deeper, wider lookup table. There are integrated circuits available that perform the timing-critical actions, all the software needs to do is send some initial configuration to set it up. Changing the frequency only requires configuring a new frequency divisor value into the DDS chip, so the Arduino can manage other things without causing distortion.
If the original problem only needs one fixed frequency under 200MHz, and doesn't need any adjustment to that frequency, then the hardware gets a whole lot simpler. The crystal oscillator circuits that we use to generate the timing for digital circuits, are in fact analog to begin with. You can contact a crystal vendor and request a custom AT cut crystal; google custom quartz crystal frequency for quartz crystal vendors. Construction requires a careful printed circuit board layout; the white solderless breadboard commonly used in Arduino projects just doesn't work well above 10MHz. Granted, this fixed-frequency solution doesn't involve Arduino in any way, but if it solves the problem, that's what's important.

I wonder for which purpose you would use a micro controller at all.
If you need a fixed frequency circuit, you could design just that.
If you need a generator with variable frequency, that would justify the Arduino, but in this case I would use the Arduino to control the frequency indirectly.
Ex: create a VCO and use the Arduino to adjust the voltage, through a DAC

One problem (for me) is to know how much time lines of (C) code take to execute on a (16) MHz Arduino. This and the coding you use would set an upper limit to the sinewave frequency you could synthesise at a given quality.
You probably can't beat assembly language when time is tight.


text:
Connect Arduino via TX RX Pins to Computer's USB Port
I want to avoid using the big USB B connector to program my Arduino Mega. Since there are those RX TX Pins I thought, it would be possible, to connect my USB - Wires from my PC directly to those RX TX Pins. D+ -> TX and D- RX. This Post on Arduino Stackexchange says, those wires are just connected, while this post says the exact opposite.
I'm confused. Is it possible or would I damage my board when connecting USB wireq to RX / TX pins on my Arduino?

The first answer that you cite that you say says it is possible is in fact not talking about  what you are referring to  - it is discussing the use of the RX & TX pins directly when they are not being used for USB connection.
The second answer you cite is technically incorrect but "correct enough" in the context.
The answer to your question  is "It can be done but it requires a different boot loader, its slower, its technically inferior, it's less standard, it requires a degree of understanding (on someone's part) to get it going, and it can be done
It IS possible to access USB directly from digital I/O pins. As TX & RX are also standard digital I/O pins they could be used for this purpose BUT you need dedicated bootloader code to do this and it has inferior performance if a USB to serial converter is available. The eg ADAFruit Arduino Trinket uses this system.

Here is how the (or a)  ADAFRUIT Trinket Bootloader works. (The Trinket is not mentioned here but I'm told that this is what it uses. If not, it works in functionally the same manner).
This is in turn based on the USBaspLoader
A (very) simple "more or less Arduino compatible" development board which can use this system is Metaboard. It's circuit diagram is shown below. As can be seen - it uses an ATMega168 and the USB connection is made to two standard digital I/O pins.

"Metaboard" using ATMega168

note USB connection to pins PD2 & PD4 - NOT via RXD on PD0 and TXD on PD1 via a serial to USB converter, as is more usual.

AND another version:  AVRUSBBOOT

And again
BootloadHID   They say  -

BootloadHID is a USB boot loader for AVR microcontrollers. The uploader tool requires no kernel level driver on Windows and can therefore be run without installing any DLLs.
BootloadHID is a USB boot loader for AVR microcontrollers. It can be used on all AVRs with at least 2 kB of boot loader section, e.g. the popular ATMega8. The firmware is flashed into the upper 2 kB of the flash memory and takes control immediately after reset. If a certain hardware condition is met (this condition can be configured, e.g. a jumper), the boot loader waits for data on the USB interface and loads it into the remaining part of the flash memory. If the condition is not met, control is passed to the loaded firmware.
This boot loader is similar to Thomas Fischl’s avrusbboot, except that it is built on top of the HID device class. This implementation is more user friendly on Windows, since no kernel level drivers need to be installed.

I thought about the 'EDIT' Part of the Answer where it is from jfpoilpret: EDIT: Serial data over USB goes through copper traces connected to the rx and tx pins, connecting them to the USB to serial converter chip. This got me thinking about this post.

@Joel Telling me that it got you thinking is nice - but telling me WHAT you were thinking is liable to be more useful. Maybe you were thinking what I said was wrong. It's not. A problem is that you are reading what somebody has written and adding words and thoughts that are not actually there. This is easily done (ask me how I know :-) ) and needs to be watched for, always. He says that you can use the TX and RX pins as standard digital I/O if TX and RX are not being used to connect to a serial to USB connection. This is not saying anything remotely like that you can connect to USB directly...

@Joel Somebody else notes that the pins connect directly on board to the onboard converter. That also does not in any way say that the pins can connect to USB. Read what they say, draw a picture - DO NOT ADD ANYTHING they do not say. DO NOT remove anything they do say. See what the picture tells you. | NOTE that I have told you that you CAN do what you are trying to do BUT it is harder slower and less capable. And you will need to know special magic or know somebody who does to do it. | QUESTION: WHY do you want to do this?

first: thanks for your tips, i will keep them in mind.
I want to put my Arduino in a case and i will need a bigger case if the big USB Plug is plugged in. I wanted to connect the wires from the USB cable going to my PC with the RXTX Pins on my Board, to save space. But this is not possible, since i need a lot more utilities to achive that, which need more room, than an USB Plug.

@Joel For a "one off" it would be far easier to add a custom socket (maybe a micro USB or mini USB) or even use a short wire tail to an off-board socket which can be more conveniently located.

Strictly Serial interfaces use ±15V, although this is uncommon these days (but then so are PCs with serial ports). ±12V, ±5V or even 0/+5V also exist. Connecting a ±15V interface to the Pi would destroy it. There are RS232 adapters to ensure safety.
If you are talking about connecting USB data lines to serial forget it. The voltages are the least of your worries, the USB serial encapsulates the data in a protocol.

I Thought since USB is the Universal Serial Bus, I could connect it. There is no way in connecting the Arduino to my PC in order to upload programs to it, without additional hardware?

See my answer - he's talking about an Arduino, not a RasPi. It is possible to use std digital I/O pins to implement low speed USB functionality and bootloaders to do this are available. See links in my answer. Not a path most would want to follow. This is what the ADAFruit Trinket Arduino look alike does.


text:
Arduino Yun - Problem with bridge and client
I'm using this simple code
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

YunServer server;

void setup() {
  Serial.begin(9600);
  Bridge.begin();
  server.listenOnLocalhost();
  server.begin();
}

void loop() {
  YunClient client = server.accept();
  if (client) {
    Serial.println("client");
    process(client);
    client.stop();
   } else {
     Serial.println("no client");
   }
   delay(50);
}

void process(YunClient client) {
  String command = client.readStringUntil('/');
  Serial.println(command);
  if (command == "turnLeft") {
    Serial.println("Gira a sinistra");
  }
  if (command == "turnRight") {
    Serial.println("Gira a destra");
  }
  if (command == "goTo") {
    String value = client.readStringUntil('/goTo/');
    Serial.println(value);
  }
}

but it seems to have problem with bridge (or server, or client, i cannot understand) because it only write "no client" on the serial.
I can not understand what is wrong.

Probably too late to answer your question. Your problem is on line
if (client)

Change it to
if(client.connected())

which actually returns true when client is connected.

I presume you are wanting the print output to show up on the Serial Monitor but you have connected the Arduino IDE to the Yun via the WiFi port on your network. If this is the case, then change all refs of Serial.print to Console.print
This will direct the ASCII text to the Serial Monitor.


text:
Connecting to Nano via USB3
I have a Uno (third party) that I connect to my Dell laptop with no problems at all. But I've just received a Nano (also third party) that I just can't get to upload. After lots of interneting, I hit Windows normally-useless troubleshooting tool. That tells me that the USB device (the Nano) doesn't understand USB3 and I should plug it into a USB2 port. Unfortunately, being a new machine there IS no USB2 port.
Is Windows Troubleshooting lying? Is there a problem interfacing with a Nano via USB3?
Edit: Error message is:
stk500_recv(): programmer is not responding

A third party board may well have a different USB-serial chip than the FTDI part used on a nano from Arduino.cc and so may well require a different USB driver.  Your posted error message could quite easily be a result of pointing your software at a serial device other than your arduino clone.

It happened to me: https://kongduino.wordpress.com/2015/08/17/where-are-you-clone/ Turns out that the chip was not the regular FTDI. You might have to look at the USB chip and install drivers for it.

What USB "controller" is on your Arduino

I have run in to similar symptoms while using USB based Arduino clones connected to USB3 ports. Connecting them to a USB2 port on the same PC worked (where this was an option).
For computers that only have USB3 ports, I found that connecting the device via a cheap USB 2.0 hub (not USB3 hub) solved the issue.
I'm not sure why these devices behave like this, but there seems to be something about USB3 ports that these boards don't like.

Windows troubleshooter is just trying to tell you that you've plugged a USB2 device into a USB3 port, thus wasting its USB3 capabilities which could be useful for another device. Of course, if you only have USB3, you can't do otherwise.
USB3 is fully backward-compatible with USB2, so whatever your problem is, it is not related to the fact that you plug the Nano into a USB3 port. Perhaps your problem comes from the fact that your Nano is "third party" - I suppose that means it's not the original device and thus it may not be fully compatible. If my guess is right, try to find out what programmer your Nano clone supports: chances are you just need to select a different programmer type in Arduino settings, or buy a separate programmer supported by your device.

While USB3 is supposed to be backwards compatible, that isn't always true in practice.  Sometimes using a USB 2 hub in between the computer and a legacy device can make things work where a direct connection would not.

1- Check your COM ports, make sure it is correct
2- Arduino Nano will somethime require a driver, download it
3- Reboot your system and see what happens


text:
Why does avrdude error appear when interfacing GLCD with arduino uno in ubuntu
I want to interface a GLCD with arduino uno. The GLCD is JHD12864E.   The connections are as shown in this image
I downloaded the OpenGLCD library and uploaded HelloWorld program from it.
I got the error:
        stk500_recv() : programmer is not responding
Then I googled it and also tried to upload using ISP using another arduino. The program uploaded successfully, but i did not get any output on GLCD.
I am not getting this error when uploading any other sketches. Can anyone explain to me why do we get this error? And what is the solution to it?

Have you read the 'reset function note' here http://playground.arduino.cc/Code/GLCDks0108? It may desribe your problem.

@DaveP Yes i have followed it.


text:
Didn't have MAC address on Wiznet based ethernet shield (cloned)
My Ethernet shield dont have any MAC address, please tell me how to find the MAC address, I'm stucked! Here is the link from where I bought the Ethernet shield.
http://www.amazon.in/gp/product/B00AXVX5D0?ie=UTF8&at=&force-full-site=1&ref_=aw_bottom_links

You can set the Mac address to whatever you want.  Many of the example sketches will have one already present, but as long you follow the standard mac format it should be happy (I am using the same shield).  In the Examples menu, you should see Ethernet then Webserver where you can find the following example.  You can change it a bit, but most of the time I just leave it alone.
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

"You can set the Mac address to whatever you want." Yes, if you don't care about duplicated addresses, already assigned addresses or even broadcast addresses. To do it right, read a bit about MAC addresses, e.g. starting with Wikipedia about MAC addresses

Ethernet will work as long as two different machine in the LAN don't have the same MAC address, as @Nathan wrote in his answer.
The MAC address is built by two parts, a prefix which are given to manufacturers of network devices and is called OUI, and a suffix that is the node part that manufacturers can use as they wish.
If you want to build an MAC address yourself, use a Locally administered address.  Universally administered and locally administered addresses are distinguished by setting the second-least-significant bit of the most significant byte of the address.
That will make this address to not use any OUI prefix, as that bit is zero on OUI, which minimize the risk of two or more devices have the same MAC address in same LAN.
If you get the same MAC addresses you will get very strange results if they happen to be in the same LAN, I tell you.  Been there, done that, and it wasn't fun to debug.
Here are a site that looks up MAC addresses (and generate random ones).  But if you want to see which manufacturer have that MAC address, you read it from IEEE and their list.

so can i use the mac address which is generated by random mac address generator from the link u provided?

Yes, you can.  But it is still up to you to know that the MAC address is unique for your LAN, because you could theoretically end up with two equal addresses,  even though the risk are rather slim. But still slimmer than to use one that are used in examples, like DE:AD:BE:EF:FE:ED. ;-)


text:
Internet of Things at home only
My question isn't specific to Arduino but can concern Raspberry Pi and all Internet of Things homemake projects.
As I'm preparing a personal projet with sensors, data storage and visualisation/reporting web page (not yet Android app) I'm looking about Internet of Things platform.
It seems all that I can find are cloud related system. I would prefer a home localized solution but I'm not able to find one (and maybe open source) where datas don't go outside home.
The goal is to be able to :
    send datas from my Arduino to a home storage server
store these data into database for later query (may be MySql)
trigger some computation or aggregation job over datas
prepare some graphs
generate some html page from template
option: allow Android client to connect and get datas/graphs
Before starting thinking how to create my own (non standardized) system is anyone can give me some advice ? some name of such existing system ?
Thanks
Thomas

I recently worked extensively on a Home Automation Project and here's what I would recommend based off of that:

Use Arduino for hardware interfacing.
Use Raspberry Pi for hosting your server.
Write your server using Node.js (or Python if you wish).
Use Express, Socket.io (or Python simple server). Google these.
Use Serial (USB) for communication between Arduino and Raspberry Pi
Use RF/BLE if you want to go wireless.
Use Redis or MySQL for database.
Use a graph JS API for charting.
To build an android app, send http requests (or a Socket.io link), for communication.

This is a simple to implement, but you'll need to put some time. Good luck.
All of the above steps are abstracted from each other. This means that if you want to incorporate additional features, you can change any stage without affecting the whole.

Setting up a basic webserver on the Raspberry Pi is fairly straightforward, and as long as you have a firewall and aren't port-forwarding the data will be restricted to your home network.  You can also setup the firewall on the Pi to allow only local access fairly easily.  I did a similar project, and here was my process.

Get the Arduino to output the data in a standard way.  I used CSV format, but as long as it easy to parse you should be fine.
Get the Arduino to make the data available.  I ended up using the webserver sketch to generate a page with all of my values, but you could just as easily have it send data instead.
Insert the data into a database.  I had a cron job that every x minutes would pull the webpage, parse the data, and insert it into the database.
Make the webpage.  There are a ton of open source graphing projects, and I chose a PHP based one as that is the language I am most comfortable with.  Javascript, Python, and CSS can also do it if you prefer.
Since I used PHP it was fairly easy to setup a template system.  Basically it had some standard include statements, then worked off of $_GET variables to call a variety of graphs.


text:
Arduino-like boards with other microcontrollers
Are there any Arduino-like board designs that are NOT using an AVR chip, but perhaps a chip like the Z80 or the 6502?

Can you elaborate on what you mean by "Arduino-like"? Pin layout, IDE, etc. E.g. TI launchpad can be programmed using Energia which is an Arduino-like IDE and library based on Wiring but doesn't have the same pin layout.

What meaning do you put in Arduino-like ?  Support for Arduino development environment?

If you want to use PICs, maybe chipKit is worth a look.

Today is your lucky day: http://hackaday.com/2015/02/17/non-arduino-powered-by-a-piece-of-computing-history/

Z80 and 6502 are CPUs (not MCUs) of another time; I am not even sure you can find some to buy now! Why one would create some board around them today?

Teensy or Arduino Due (both ARM). TI Launchpad Series. Just to name a few.

You have to define what you mean by "Arduino-like" beyond just not using an AVR.
There's the Arduino Galileo using an Intel chip and supports the Arduino development tools, as well as the Arduino Due which is an Arm-based chip.
There's the Netduino which uses ARM chips (STMicro's) and is pin compatible with Arduino shields, but I don't know what the development framework is (other than it being in .NET), though this doesn't necessarily say much because not even all Arduino boards have the same pin compatibility (Nano boards are much smaller, LilyPad Arduinos which are round and semi-flexible, etc.)
Then there are related boards, but don't support the Arduino environment or any pin compatibility (TI Launchpad springs immediately to mind, but pretty much every manufacturer has some sort of demo board or development board for their MCU's).
There's a huge list of Arduino-like boards here (split into levels of compatibility, includes the official Arduino boards).

By Arduino-Like I mean a small board with the same or very similar physical dimensions of an Arduino Uno and a very similar feature set related to Analog and Digital I/O, memory, video, etc.

Define 'very similar'? And what video features does an Arduino have??


text:
USB to TTL with switchable 5v and 3.3v in one
are there any USB to TTL with switchable 5v and 3.3v
i need to use it for raspberry pi and arduino

Many 3.3V FTDI based devices are 5V tolerant and will work with both:

Adafruit's FTDI friend
Sparkfun FT231X Breakout

Here is general information about logic levels: https://learn.sparkfun.com/tutorials/logic-levels

so the HIGH for arduino is 3v to 5v and LOW is 0v to 1.5v , can i used USB to 3.3v TTL for both arduino and RPI

Yes, in general 3.3V logic output is compatible with 5V input.  Some, but not all 3.3V devices are tolerant of 5V input. Check the datasheets to be sure. Always be careful when combining 3.3V logic and  5V logic it is possible to damage components.


text:
Adafruit motorshield disconnected but getting current from Arduino
my Adafruit motorshield is getting current from Arduino board even after disconnected from battery. I was planning to give separate dc power from 6 AA cells to motor shield but not sure if extra current will enter into Arduino and damage it. I have Ultrasonic sensor connected to motorshield which is getting +5v from board (may be Arduino).
Please suggest how to solve this problem.
Thanks

How did you get on with this?

If all else fails, read The Manual
The manual indicates that it is intended that the MS electronics may be operated by the Arduino power supply while using a separate external supply for the motor.
Pages 37 to 39 explain about powering options.
The Arduino and the shield interconnect all of : 3V, 5V, Vin.
3V may not be used by the shield.
Arduino Vin to MS V+ is broken by jumper "PWRJMP" - purple rectangle in diagram below.
Arduino 5V to MS Vcc is not interrupted by a jumper - See labels in red squares below.

You did not say what version shield you had or which Arduino or what you mean by "disconnected from battery" or supply any links to relevant documents. ALL of these things will help people to help you better.
Assuming latest MS version,
adafruit motor shield v1.2  - discontinued.
github v1.2 schematic this appears to be pre V2 BUT is linked to from a ference in the V2 manual so is probably "more or less correct".
adafruit motor shield v2 manual - probably what you have
adafruit current MS page
This probably tells you what you need to know.  Manual page 37-38

How to set up the Arduino + Shield for powering motors
Servos are powered off of the same regulated 5V that the Arduino uses. This
is OK for the small hobby servos suggested. If you want something beefier, cut the trace
going to + on the servo connectors and wire up your own 5-6V supply!
The DC motors are powered off of a 'high voltage supply' and NOT the regulated 5V.
Don't connect the motor power supply to the 5V line. This is a very very very bad idea unless you are sure you know what you're doing!
There are two places you can get your motor 'high voltage supply' from. One is the DC jack on the Arduino board and the other is the 2-terminal block on the shield that is
labeled EXT_PWR. The DC Jack on the Arduino has a protection diode so you won't be able
to mess things up too bad if you plug in the wrong kind of power. However the EXT_PWR
terminals on the shield do not have a protection diode (for a fairly good
reason). Be utterly careful not to plug it in backwards or you will destroy the motor
shield and/or your Arduino!

I am using Adafruit motor shield V 1.0 and Arduino UNO which comes with starter kit. When I say disconnected means that I am supplying 9v from 6 AA cells to motor shield on power terminals 'EXT_PWR' and removed the power jumper on motor shield. But as defined here it is still getting +5v from Arduino and its green LED is lit.

@qazifarhan We are slowly getting there. The extra information is useful. All the information will be even more so  |1. Please post links to documents describing what you say you have. If you do not have them then having you locate them makes more sense than expecting someone else to dos so. IF you can't find then then others will no doubt help. | 2. Read the material I posted and the manual. What it says sounds very likely to be completely applicable to what you have. | 3. Then ask again if still uncertain

@qazifarhan Here is the circuit diagram for V1.0 I suggest you add a link to it in your question. The advice I offered re V2 also applies to this. Here is the V1.2 shield page that lists the V1.0 diagram  - I suggest you add it to your question.