# Question
Title: What is the execution context of the function registered via the Wire.onReceive() method?
I'm basically wondering if it's OK to `Serial.write()` or print in the function I register to be called when I2C data is received. I can't seem to find the execution context or any warnings.

http://arduino.cc/en/Reference/WireOnReceive

# Answer
Looking at `twi.c` in the Arduino libraries, it seems the callback function is called from within the I2C interrupt service routine (ISR). Any code in the call back will lengthen the ISR so it will have to be short. I don't think `Serial.write` will be too much of a problem; the TX interrupt will be delayed to the end of the I2C ISR which finishes straight after the callback and the `Serial.write` function is fairly short.

If you need to have a longer function run, you could instead have the callback store bytes in a ring buffer, then check for any available bytes in the main `loop()`.. but this is what the `Wire` class helps with already.
> 2 votes

---
Tags: i2c
---


# Question
Title: Newbie has difficulty compiling unedited svn Arduino code that should work
I'm having some trouble getting this arduino code to compile. It's not my project, but it should compile totally fine. Having never worked with the Arduino before, these errors are a bit intimidating, but I'll try to be specific enough for someone to get a guess. So...

I have this directory with these files: .

I found that the ArduCAM\_OSD.ino has the loop and setup functions. When I try to compile the ino and solution I get these errors:

```
In file included from ArduCam_Max7456.cpp:4:

ArduCam_Max7456.h:78: error: expected class-name before '{' token

ArduCam_Max7456.h:84: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:84: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:87: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:91: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:91: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:98: error: 'size_t' does not name a type

ArduCam_Max7456.h:99: error: 'uint8_t' has not been declared

ArduCam_Max7456.h:100: error: 'BetterStream' has not been declared

ArduCam_Max7456.h:102: error: 'uint8_t' does not name a type

ArduCam_Max7456.cpp: In member function 'void OSD::init()':

ArduCam_Max7456.cpp:38: error: 'video_mode' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'void OSD::setMode(int)':

ArduCam_Max7456.cpp:109: error: 'video_mode' was not declared in this scope

ArduCam_Max7456.cpp:110: error: 'video_center' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'int OSD::getMode()':

ArduCam_Max7456.cpp:123: error: 'video_mode' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'int OSD::getCenter()':

ArduCam_Max7456.cpp:138: error: 'video_center' was not declared in this scope

ArduCam_Max7456.cpp: At global scope:

ArduCam_Max7456.cpp:162: error: prototype for 'void OSD::setPanel(uint8_t, uint8_t)' does
not match any in class 'OSD'

ArduCam_Max7456.h:84: error: candidate is: void OSD::setPanel(int, int)

ArduCam_Max7456.cpp: In member function 'void OSD::openPanel()':

ArduCam_Max7456.cpp:177: error: 'row' was not declared in this scope

ArduCam_Max7456.cpp:177: error: 'col' was not declared in this scope

ArduCam_Max7456.cpp: In member function 'void OSD::closePanel()':

ArduCam_Max7456.cpp:206: error: 'row' was not declared in this scope

ArduCam_Max7456.cpp: At global scope:

ArduCam_Max7456.cpp:212: error: prototype for 'void OSD::openSingle(uint8_t, uint8_t)' does
not match any in class 'OSD'

ArduCam_Max7456.h:91: error: candidate is: void OSD::openSingle(int, int)

ArduCam_Max7456.cpp:236: error: no 'size_t OSD::write(uint8_t)' member function declared in
class 'OSD'

ArduCam_Max7456.cpp:251: error: prototype for 'void OSD::control(uint8_t)' does not match
any in class 'OSD'

ArduCam_Max7456.h:87: error: candidate is: void OSD::control(int)

ArduCam_Max7456.cpp:268: error: prototype for 'void OSD::write_NVM(int, uint8_t*)' does not
match any in class 'OSD'

ArduCam_Max7456.h:99: error: candidate is: void OSD::write_NVM(int, int*)

```

The most notable of these is the first error. Here's the class, in a header file, throwing the error:

```
class OSD: public BetterStream
{
  public:
    OSD(void);
    void init(void);
    void clear(void);
    void plug(void);
    void setPanel(uint8_t start_col, uint8_t start_row);
    void openPanel(void);
    void closePanel(void);
    void control(uint8_t ctrl);
    void detectMode(void);
    void setMode(int mode);
    void setBrightness();
    void openSingle(uint8_t x, uint8_t y);
    int getMode(void);
    int getCenter(void);
    virtual int     available(void);
    virtual int     read(void);
    virtual int     peek(void);
    virtual void    flush(void);
    virtual size_t write(uint8_t c);
    void write_NVM(int font_count, uint8_t *character_bitmap);
    using BetterStream::write;
  private:
    uint8_t start_col, start_row, col, row, video_mode, video_center;
};

```

Now, since I know confidently that this should compile, I'm convinced that I've made some small syntactical error that can be fixed easily. In case anyone needs to see more of the files, you can access them all on the google code page here. Alternatively, please feel free to ask any questions.

# Answer
> 1 votes
It sounds like you are missing the libraries that the project was build for. BetterStream was part of the library system of the Ardu projects at diydrones.com

Normally for Ardu projects they use a modified version (their own) of the Arduino IDE but I don't know if the Arducam project works the same way.

I think you will find a better answer over in the support forum as http://www.diydrones.com which is where Arducam comes from.

Some of the source files look like they replace libraries so it might be that you just need a different core from diyd

---
Tags: c++
---


title: Problems with substring loop

text:
# Question
Title: Problems with substring loop
Hey folks … I was hoping some of you might cast your eye over my code.

It splits up a string read from EEprom into an array of separate strings. Based on String length information stored in a separate array. (tempArray\[\])

It reads fine … and also seems to process fine (ie. it does turn one long string into separate array items) for some reason it stops working no the 8th array item?

The splitting code (problem) starts on line 80 and i have included the output above it in comments.

http://pastebin.com/Ax4R6t6J \<\< Full code also available here.

```
void reJigFromMemory(){

  Serial.print("Eeprom read 1 :");
  Serial.println(eepromReadOne);
  Serial.print("EEprom read 2 :");
  Serial.println(eepromReadTwo);
  String tempArray[10];

  int charLength=eepromReadOne.length()+1;
  char charBuff[charLength];
  eepromReadOne.toCharArray(charBuff, charLength);

  //// GET MEMORY LOCATIONS
  /*
converts long string of numbers:
   13161717171717252533
   into separate strings:
   13
   16
   17
   17
   17
   17
   17
   25
   25
   33

   And stores them in an array.
   */
  for (int i = 0; i <10 ; i++){
    tempArray[i]+=charBuff[i*2];
    tempArray[i]+=charBuff[(i*2)+1];
    Serial.print("I just translated :");
    Serial.println(tempArray[i]);
  }
  /// GET THE STRINGS USING THE ABOVE ARRAYS
  /*
converts long list of data ie:
   |0|Bingo#999#|1|Retest2#9222#|2|Retest3#92299#|3|Retest4#99339#|4|Retest5#95599#|5|Retest6#96699#|6|Retest7#99119#|7|User Defined eighth#0#|8|User Defined ninth #0#|9|User Defined tenth (last) .#0#

   into individual array strings:

   From Number = :0
   To number : 13
   Record 0 :          |0|Bingo#999#
   From Number = :13
   To number : 29
   Record 1 :          |1|Retest2#9222#
   From Number = :29
   To number : 46
   Record 2 :          |2|Retest3#92299#
   From Number = :46
   To number : 63
   Record 3:           |3|Retest4#99339#
   From Number = :63
   To number : 80
   Record 4:           |4|Retest5#95599#
   From Number = :80
   To number : 97
   Record 5:           |5|Retest6#96699#
   From Number = :97
   To number : 114
   Record 6 :          |6|Retest7#99119#
   From Number = :114
   To number : 139
   Record 7 :               <<<<<< THIS ONE IS MISSING ? WHY?
   From Number = :139
   To number : 164
   Record 8 :               <<<<<< THIS ONE IS MISSING ? WHY?
   From Number = :164
   To number : 197
   Record 9 :               <<<<<< THIS ONE IS MISSING ? WHY?

   */
  String tempArray2[10];
  int fromLocation = 0;
  int toLocation=0;

  for (int i = 0; i <10 ; i++){                 /////// LINE 80

    toLocation += tempArray[i].toInt();

    fromLocation += tempArray[i-1].toInt();
    tempArray2[i]=eepromReadTwo.substring(fromLocation,toLocation);
    Serial.print("From Number = :");
    Serial.println(fromLocation);
    Serial.print("To number : ");
    Serial.println(toLocation);
    Serial.print("I just translated :");
    Serial.println(tempArray2[i]);

  }
}

```

# Answer
> 1 votes
Your 2nd for loop should look something like this:

```
int fromLocation = 0;
int toLocation=0;

for (int i = 0; i <10 ; i++)
{                 /////// LINE 80

    toLocation += tempArray[i].toInt();

    tempArray2[i]=eepromReadTwo.substring(fromLocation,toLocation);
    Serial.print("From Number = :");
    Serial.println(fromLocation);
    Serial.print("To number : ");
    Serial.println(toLocation);
    Serial.print("I just translated :");
    Serial.println(tempArray2[i]);
    fromLocation += tempArray[i].toInt();
  }
}

```

On the first pass through the loop, fromLocation is 0. toLocation starts at 0 and gets the value in tempArray2\[0\] added to it.

After extracting a string, you add the current array value to fromLocation to advance the pointer to the beginning of the next string.

Note that String objects are very inefficient way to save 2 digit numbers. It would be better use an array of ints, and write code that extracts 2 characters at a time into int values.

With only 20 String objects it's not a huge deal, but bear in mind that String objects take a lot of memory overhead on a memory-starved platform like an Arduino. Better to learn how to use C strings.

---
Tags: c++, string
---


# Question
Title: While using Arduino Ethernet shield, do we need to explicitly select/Deselect SD and W5100 in our code?
It has been mentioned here http://arduino.cc/en/Main/ArduinoEthernetShield that corresponding libraries take care of chip select between SD and W5100 in Arduino Ethernet shield. Does it take care properly all the time? What happens if the Chipselect is not properly managed by libraries? Does that cause blocking of code?

# Answer
> 2 votes
Here we have a nice example of a single Shield requiring TWO libraries. The Ethernet.h and SD.h where the later appears as an after thought and is not demonstrated by the Example. As it is done so in the SD examples. However, their styles are slightly different.

The Ethernet libary as mentioned (provided within) the IDE is hardcoded to implement the Chip Select for the W5100 on corresponding pin. When using the typical purchased Ethernet Shield, there is no need to configure it. Unlike the SD library, which requires the pin to configured using the SD.begin(4) member function.

```
if (!SD.begin(4)) {
  Serial.println("initialization failed!");
  return;
}

```

Where again on the typical Ethernet shield the SD card is at pin D4.

Note being hardcode that the Ethernet library selects the matching pin to corresponding shield.

```
private:
#if defined(ARDUINO_ARCH_AVR)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };
#elif defined(__AVR_ATmega32U4__)
  inline static void initSS()    { DDRB  |=  _BV(6); };
  inline static void setSS()     { PORTB &= ~_BV(6); };
  inline static void resetSS()   { PORTB |=  _BV(6); };
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };
#else
  inline static void initSS()    { DDRB  |=  _BV(2); };
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif
#endif // ARDUINO_ARCH_AVR

```

And in the case of the UNO (or the else case) Port B Bit 2 is D10.

---

worth noting that SD library has an alternate method of initializing and using the SD card

```
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  Serial.println("initialization failed. Things to check:");

```

where chipSelect would be D10 in this case.

---
Tags: arduino-mega, shields, ethernet
---


title: Problem uploading to Arduino Yun

text:
# Question
Title: Problem uploading to Arduino Yun
I have an Arduino Yun. I am trying to upload the code in Arduino but after I click on Upload, I get the error message shown in the image.

At first it showed the Arduino Yun under the port tab, after this message no Arduino is showing in port tab.

The portion of the error visible in the image:

> Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload.

# Answer
In the Arduino IDE, click on `Tools` (on the menu bar). Then, open the submenu `Board` and make sure "YUN" is selected.
> 1 votes

# Answer
Seems like you havent chose the appropriate serial port.

Under tools, you'll also find serial port - make sure the appropiate one is selected.
> 0 votes

---
Tags: arduino-yun, uploading
---


# Question
Title: Are there any reasons to pick Nano over Micro?
Nano is from 2008, and micro from 2012. Micro seems better on every parameter, in particular in having a better (I think) microcontroller, ATMega32u4, over ATMega328P.

However, all the shops I've checked out, both local and online, sell the Nano, and only some sell Micro. And Nano is always more expensive than Micro. E.g. at RS-Online 26GBP for Nano (link) and 16GBP for Micro (link).

Why do many shops only sell the inferior product?

Why is the older and less capable Nano more expensive?

Why would anyone buy the Nano over the Micro?

# Answer
The main difference between the ATmega32u4 and the ATmega328P is that the 32u4 has onboard USB. When ATmega328P are used in an Arduino they are often coupled with an FTDI USB to serial chip. The FTDI chip is about $5 so this may be where the extra cost comes in.

Having the USB chip separate is actually not a bad thing:

* The Atmega328P consumes less power than the ATmega32u4
* FTDI chips are common, so the drivers are on most computers, whereas the 32u4 requires an .inf file to be loaded on Windows.
* The FTDI chip uses the FTDI vendor and product ID and thus can be used in large-quantity commercial projects whereas the ATmega32u4 would require purchase of a vendor id and product id from the USB group. (My conclusion after reading around the net a bit, please correct if wrong).
> 12 votes

# Answer
I'd buy the NANO and STEER CLEAR of the micro with that 32u4 chip. The good ol' 328p chip also has a FTDI chip to handle USB to serial while the other chip handles it on its own. The problem is that the Micro's bootloader ONLY allows trying to program it with USB and requires a special driver. With Linux, only a few select versions have the needed driver. If your Linux version doesn't have the driver, you're out of luck. In that case, take it back or donate it to a hackerspace. You will NEVER make it work.

I was at the arduino.cc site about this and tried everything only to get increasingly annoyed about that lemon of a card. You know it's time to give up when you get flamed.
> 3 votes

# Answer
It depends on what's your focus on. From pure microcontroller view, the 328P compared to the 32u4

* is 4MHz faster
* has two Touch Channels more
* has picoPower technology
* has an RTC
* has a lower minimum supply voltage

If one or more of these features are essential for your project, the Nano may be the better choice.

Regarding the price:
I'm not sure if it can have such a high influence, but there may have been a technology shrink. That's why a modern 32bit micro is cheaper than an old-fashioned 8 or 16bit micro, at least in B2B pricing.
> 2 votes

---
Tags: arduino-nano, arduino-micro
---


title: Arduino Due SD Card

text:
# Question
Title: Arduino Due SD Card
I have an Arduino Due and want to save data to an SD card. For this I use a 3.2 'display of ITead with integrated SD slot (http://imall.iteadstudio.com/im120419006.html). This I connected to the Arduino.

However, the Arduino doesn’t detect the SD card (I've tried two different cards and also reformatted both). I wired the three SD ports correctly to the SPI. I wired the CS output on to pin 4, 10 or 52 (each one once tested), without success. I have also tried using ICSP instead of SPI, which the Arduino website suggests. Again, without success.

The test program I used is a test program on the Arduino website for SD cards (the program in the end of the post, changes marked in bold). Is the problem in the program code or is it a hardware problem? If it is a software problem, could you send me a test program that is designed for Arduino Due?

I have invested several hours and read tens of forums but found nothing comparable. Also, the proposed solutions never worked.

```
/*
  SD card test

 This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.

 The circuit:
  * SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
        Pin 4 used here for consistency with other Arduino examples

 created  28 Mar 2011
by Limor Fried
 modified 9 Apr 2012
by Tom Igoe
*/
// include the SD library:
#include <SD.h>
**#include <SPI.h>**

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = **10**;

void setup() {
// Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(**chipSelect**, OUTPUT);     // change this to 53 on a mega
  **SPI.begin(chipSelect); //habe ich eingeführt, da es in einigen Foren erwähnt wird, funktioniert jedoch mit und ohne nicht. //I made this, becaus it’s mentioned in severals forums, but it didn’t workt wiht it and whitout it**     // change this to 53 on a mega

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }
  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
  volumesize *= volume.clusterCount(); // we'll have a lot of clusters
  volumesize *= 512; // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

```

# Answer
Thank you very much. I solved part of the problem. I tried it whit a new SD Card. When I use pin 52, I am able to read the card information with the program above. But only if I use SPI.

Pin 10 doesn't work at all and Pin 4 a bit. If I work with Pin 4, it accepts the card, but it can't find out what format the SD card has. This is kind of weird, I think, because Arduino say alls three pins should work (http://arduino.cc/en/Reference/SPI). Does anybody knows something about this?
> 1 votes

# Answer
I use SD card with Arduino UNO. I connected SD card to the Arduino and I saw the Arduino don’t detect the SD card. Then I see this tutorial and Arduino detect the SD card now. Don't connect the SD card breakout board to Arduino and use non-inverting hex buffer(4050).
> 0 votes

---
Tags: arduino-due, spi, sd-card, icsp
---


title: Debugger for Code::Blocks + Arduino

text:
# Question
Title: Debugger for Code::Blocks + Arduino
I am not very experienced in this, but I was wondering if Code::Blocks has a way of getting a debugger that runs for Arduino chips, specifically. I understand there is Arduino IDE for but does it allow debugging specific to those microcontrollers (Amtel and such)?

# Answer
> 0 votes
If you are interested in on-board debugging or off-board debugging, you will need a programmer/debugger. I would recommend the Atmel AVR Dragon. Atmel AVR Dragon uses the Atmel Studio 6.2, which is a great IDE.

# Answer
> 1 votes
Answer: Code blocks does not currently have an Arduino debugger. The Arduino IDE does not have a debugger.

There is an Arduino debugger in Atmel Studio using the Visual Micro plugin.

That said, you have to use Ms Windows to use Atmel Studio which might not be available to you.

The Visual Micro debugger is simple and uses usb so does not require additional hardware but as your experience grows you might also like to progress to fully blown hardware debug using the native Atmel Studio Tools

Visual Micro debug in Atmel Studio

Atmel Studio Download

---
Tags: debugging
---


# Question
Title: Arduino Leonardo Upload issue with ubuntu 14.04
I got a bare conductive board ( which is based on arduino leonardo ) . I was trying to upload a blink sketch using arduion 1.5.7. But its always failing and here is the log. I never work a leonardo before. Any ideas what is happing with this ?

```
Build options changed, rebuilding all

/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /tmp/build5447563659949358969.tmp/Blink.cpp -o /tmp/build5447563659949358969.tmp/Blink.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_analog.c -o /tmp/build5447563659949358969.tmp/wiring_analog.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_digital.c -o /tmp/build5447563659949358969.tmp/wiring_digital.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_shift.c -o /tmp/build5447563659949358969.tmp/wiring_shift.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WInterrupts.c -o /tmp/build5447563659949358969.tmp/WInterrupts.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/hooks.c -o /tmp/build5447563659949358969.tmp/hooks.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_pulse.c -o /tmp/build5447563659949358969.tmp/wiring_pulse.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring.c -o /tmp/build5447563659949358969.tmp/wiring.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial3.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial3.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Tone.cpp -o /tmp/build5447563659949358969.tmp/Tone.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial1.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial1.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial2.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial2.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Print.cpp -o /tmp/build5447563659949358969.tmp/Print.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HID.cpp -o /tmp/build5447563659949358969.tmp/HID.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/USBCore.cpp -o /tmp/build5447563659949358969.tmp/USBCore.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/IPAddress.cpp -o /tmp/build5447563659949358969.tmp/IPAddress.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WMath.cpp -o /tmp/build5447563659949358969.tmp/WMath.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WString.cpp -o /tmp/build5447563659949358969.tmp/WString.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/main.cpp -o /tmp/build5447563659949358969.tmp/main.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial0.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial0.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/new.cpp -o /tmp/build5447563659949358969.tmp/new.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Stream.cpp -o /tmp/build5447563659949358969.tmp/Stream.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/CDC.cpp -o /tmp/build5447563659949358969.tmp/CDC.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_analog.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_digital.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_shift.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WInterrupts.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/hooks.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_pulse.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring.c.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial3.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Tone.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial1.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial2.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Print.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HID.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/USBCore.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/IPAddress.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WMath.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WString.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/main.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial0.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/new.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Stream.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/CDC.cpp.o
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega32u4 -o /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.o /tmp/build5447563659949358969.tmp/core.a -L/tmp/build5447563659949358969.tmp -lm
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.eep
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.hex

Sketch uses 4,798 bytes (16%) of program storage space. Maximum is 28,672 bytes.
Global variables use 157 bytes (6%) of dynamic memory, leaving 2,403 bytes for local variables. Maximum is 2,560 bytes.
Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, } / {} => {}
PORTS {} / {} => {}
PORTS {} / {/dev/ttyACM0, } => {/dev/ttyACM0, }
Found upload port: /dev/ttyACM0
/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avrdude -C/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/build5447563659949358969.tmp/Blink.cpp.hex:i

avrdude: Version 6.0.1, compiled on Apr  3 2014 at 21:52:43
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .avrdude: Send: . [1b]
avrdude: Send: S [53]
avrdude: Recv: C [43]

avrdude: ser_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding

```

And My dmesg output is

```
[ 3616.984079] usb 4-2: new full-speed USB device number 11 using uhci_hcd
[ 3617.155216] usb 4-2: New USB device found, idVendor=2a6e, idProduct=8003
[ 3617.155224] usb 4-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3617.155229] usb 4-2: Product: Touch Board
[ 3617.155234] usb 4-2: Manufacturer: Bare Conductive
[ 3617.158323] cdc_acm 4-2:1.0: This device cannot do calls on its own. It is not a modem.
[ 3617.158359] cdc_acm 4-2:1.0: ttyACM0: USB ACM device
[ 3617.166427] input: Bare Conductive Touch Board as /devices/pci0000:00/0000:00:1a.1/usb4/4-2/4-2:1.2/input/input22
[ 3617.166675] hid-generic 0003:2A6E:8003.0007: input,hidraw1: USB HID v1.01 Mouse [Bare Conductive Touch Board] on usb-0000:00:1a.1-2/input2

```

And My lsusb output

```
Bus 002 Device 002: ID 04f2:b179 Chicony Electronics Co., Ltd
Bus 002 Device 004: ID 18d1:4ee2 Google Inc. Nexus 4 (debug)
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 002: ID 03f0:171d Hewlett-Packard Bluetooth 2.0 Interface [Broadcom BCM2045]
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 011: ID 2a6e:8003
Bus 004 Device 002: ID 1d57:0008 Xenta
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

```

# Answer
Try the arduino.cc forums. Post your logs, and you MIGHT get an answer that'll work. The guys who developed the Leonardo got it to work with Ubuntu 10.04 without a special device driver. I use Ubuntu like you but not the magic 10.04 version and was forced to give up on the Leonardo despite heroic effort.

The problem is that 32u4 chip the Leonardo (and Micro) use. Instead of having a separate FTDI chip like a good ol' UNO, it handles USB on its own. With a bootloader on a Leonardo that enables only USB to be used (besides ICSP) Windows needs a funny .inf file to make it work. But Linux? In this case, Windows of a given version is Windows is Windows. Linux boxes are more like people in that each has its own personality, given the zillion distributions and versions thereof.

I'm convinced that the Leonardo developers merely got lucky with Ubuntu 10.04.
> 0 votes

---
Tags: arduino-ide, bare-conductive
---


# Question
Title: Extract .hex from ATtiny45 using Arduino
As it is possible to program a ATtiny45 using Arduino as ISP Programmer, is there a way to backup an ATtiny45 program to a .hex file using Arduino?

# Answer
Assuming the lock bits on the device haven't been set, sure. Simply prepare the Arduino for ArduinoISP, hook up the ATtiny45, and perform a read using AVRDUDE instead of a write (`-U flash:r:foo.hex:i`).
> 5 votes

---
Tags: attiny, avrdude
---


title: Cheap Wired Multipoint Mesh Network

text:
# Question
Title: Cheap Wired Multipoint Mesh Network
I'm looking to make a 15 x 15 grid of load sensors and RGB LEDs for an interactive dance floor. Each node will be driven by an arduino and the entire floor will be managed by a RaspberryPi. I'm trying to figure out the best way to have the nodes communicate with the Pi. Ideally the network would have these characteristics:

* Low cost per node
* Raspberry Pi as the master, arduino nodes as slaves
* Ability to know where each node is in the grid
* Healing: If a node goes down it doesn't take out all the others.
* Can easily replace broken nodes
* The electronics for each node will be ~12 inches apart
* The master will be 5 - 10 feet away from the matrix.

So far I have been toiling over a few ides.

**I2C** This would allow each node to be addressable, however, it seems that Arduino will only allow up to 127 addresses and this matrix will have at least 225 nodes.

**SPI** If daisy chained it would be easy to know where each node is in the matrix. But if one node were to break all the nodes after it would stop communicating. (right?) I could have each row daisy chained separately, so if one goes down it only affects that row.

**1-Wire** 1-wire also looks promising. I'd have to figure out my own way of determining node placement, which could be achieved a variety of ways.

**Custom Serial** Each node has a serial connection (rx/tx) for each of it's four sides. This would allow it to communicate to each of it's neighbors directly and pass along messages that are not addressed to it. If one node were to go down, the message would be automatically routed around the broken node since there are several paths to each destination. This option is a little crazy and I'd prefer to avoid something so custom and convoluted.

**USB** This would require a USB hub in each node.

**XBee** Too expensive.

Other thoughts or options?

# Answer
For I2C you can try http://www.linear.com/product/LTC4312

This will allow you to make two I2C networks to address all the nodes.

However, the wiring for I2C will be a nightmare, but it might be necessary if you want the nodes to be independent.
> 1 votes

# Answer
I think I would use RS-485.

With this standard, you can write your own communication-protocol and with arduino it is easy to use with the Serial class. As extensions for the Arduino you only use the MAX485 because it uses the UART-cip of the Arduino.

I have absolutely no experience with the rasperypi but I think it does also have an UART-Cip what would mean, that you can also connect the MAX485.
> 1 votes

---
Tags: serial, i2c, spi, networking
---


# Question
Title: Arduino NRF24L01+ arduino to netmf transmit issue
I want to communicate between Arduino Mini Pro (china import) and a stm32f4 running netmf runtime. At the moment I'm able to communicate between SPI1 and SPI2 on the stm32 board.

After that I switched on the Arduino. I'm using the RF24 library and modified the GettingStarted sample to simply open pipes and send the same byte array again and again to the stm32.

It works for the first transmit but after that I did not receive any interrupts on the receiver side.

Both NRF24L01+ are power supplied by a breadboard power supply module which supplies 500ma (max USB bus). The Arduino is connected and power supplied by a CP2102 USB/Serial adapter.

NETMF Address: 0F0F0F0F0F Arduino Address: 0F0F0F0F0E

As arduino uses little endian, I reverse the bytes on stm32 side before writing the address into the pipe. But I'm already unsure if I need that step (adding the Arduino address on netmf side).

Here's my Arduino code:

```
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

RF24 radio(9,10);

const int payload_size = 4;
const char payload[] = "PING";

void setup(void)
{

    Serial.begin(57600);
    printf_begin();
    radio.begin();
    radio.enableDynamicPayloads();
    radio.setChannel(77);
    radio.setAutoAck(true);
    radio.setRetries(15,15);
    radio.setDataRate(RF24_2MBPS);
    radio.openWritingPipe((uint64_t)0x0F0F0F0F0FLL);
    radio.openReadingPipe(1,(uint64_t)0x0F0F0F0F0ELL);
    radio.stopListening();
    radio.printDetails();
}

void loop(void)
{
    unsigned long time = millis();
    bool ok = radio.write( payload, payload_size );

    if (ok)
        printf("SUCCESS %lu...\n",time);
    else
        printf("fail %lu...\n",time);

    // Try again 1s later
    delay(1000);

}

```

Here's my NETmf code

```
NRF24L01Plus _module = new NRF24L01Plus();

public override void Init()
{
    _module.Initialize(SPI_Devices.SPI2, Pins.GPIO_PIN_D_8, Pins.GPIO_PIN_D_10, Pins.GPIO_PIN_B_12);
    _module.Configure(new byte[] { 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }, 77, NRFDataRate.DR2Mbps);

    // both handlers are never executed
    _module.OnDataReceived += this.OnReceive;
    _module.OnInterrupt += _module2_OnInterrupt;

    _module.Enable();

}

```

# Answer
I have a couple of projects that use the NRF24L01+ and the RF24 Library.

As I mentioned in my comment, the examples provided is not asynchronous. I am not sure if the library supports asynchronous operations. Nevertheless, in your example, one radio should be in transmit mode and the other receive. If you look at the examples, the author uses modes (role\_ping\_out and role\_ping\_back). Basicly, the author wrote the code so you can both send and receive. But you can't do send and receive at the same time.

If you look at the example cope in the library, you can see where you need to stop receiving and start sending:

```
radio.stopListening();

// Send the final one back.
printf("Sent response.\n\r");
radio.write( &got_time, sizeof(unsigned long) );

// Now, resume listening so we catch the next packets.
radio.startListening();

```

And on the other radio stop sending and start receiving:

```
radio.startListening();

// Wait here until we get a response, or timeout (250ms)
unsigned long started_waiting_at = __millis();
bool timeout = false;
while ( ! radio.available() && ! timeout ) {
__msleep(30); //add a small delay to let radio.available to check payload
  if (__millis() - started_waiting_at > 200 )
    timeout = true;
}

// Describe the results
if ( timeout )
{
  printf("Failed, response timed out.\n\r");
}
else
{
  // Grab the response, compare, and send to debugging spew
  unsigned long got_time;
  radio.read( &got_time, sizeof(unsigned long) );

  // Spew it
  printf("Got response %lu, round-trip delay: %lu\n\r",got_time,__millis()-got_time);
}

```

If this is a bit confusing, I would suggest you load the Getting Started example on both your radios. Once you get that working, you can get a better idea on how it works.

Good Luck
> 1 votes

---
Tags: arduino-pro-mini, nrf24l01+
---


title: Send Processing color data into Arduino

text:
# Question
Title: Send Processing color data into Arduino
I am trying to send color() data from Processing to Arduino.

Here is my code from Processing:

```
import processing.serial.*;
Serial myPort;

void setup(){
  myPort = new Serial(this, Serial.list()[7], 9600);
}

void draw(){
  color[] c1 = {color(99,0,0),color(255,0,0) };
  for (int i = 0; i < c1.length; i++ ){
    int value = int(red(c1[0]));
    myPort.write(value);
    println(value);
    delay(2000);
  }
}

```

It sends the 99.0 data to Arduino. Here is the Arduino code for getting:

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

void loop(){
  while(Serial.available() > 0){
    int recieved = Serial.read();
      Serial.print(recieved);
    }
}

```

The problem is when Arduino receive data it doesn't take one by one. When i watch Arduino serial monitor, the data comes at different chunks like, 9...99...999..9.. etc.

I am trying to send several color info from Processing into arduino, it might be a long array of value. What is the best way to achieve this?

# Answer
> 5 votes
The 'best' solution depends on many things, your skill, the performance of the system, and the other tasks it needs to do in the available time. There are some examples of doing data transfer between Processing and the Arduino in the Arduino example programs. So it is worth looking through them.

There seems to be some inconsistencies in your question.

You wrote "It sends the 99.0 data to Arduino", which has a decimal point.

Yet the code is printing an `int` i.e.

```
int value = int(red(c1[0]));
myPort.write(value);

```

Further, the processing code only looks at the red component of c1\[0\]:

```
int value = int(red(c1[0]));

```

so it can only send a sequence of '9'. So that looks like a bug.

There are a few basic strategies to write data that can be easily read. Two popular ways are:

* send fixed length messages, or prefix a message with the size of the data, and have a fixed format of data. For example, use a one byte count to say how many colours are being sent, then send three bytes, in the same order, for each colour
* use non-data bytes to separate the data. For example use a ',' between R, G or B and '\n' to mark the end of the data. To keep things simple, never use those values as data values. That is pretty much how programming languages work. It is much more complex to read than fixed format data, but can give more flexibility.

Data is often sent as printable characters (e.g. 173 would be three bytes havig the ASCII values '1', '7', '3'). If it is fixed format, it would always be three bytes. For your purposes, I'd probably send each data byte as two hex characters (ASCII '0' to '9' and 'A' to 'F'. This is slightly more complex than pure binary. However it is fixed format, and more importantly it is easier to test by hand using the Arduino serial monitor, you can just type stuff and it is relatively easy to do.

Pure binary data is much more difficult to fully test, and often relies on a piece of software which also needs testing.

Summary: There are a couple of ways, it is hard to say which is best. For simplicity try to make it simple by being fixed format.

# Answer
> 4 votes
You have to implement a serial protocol.

This can be either binary or ASCII. Binary has the advantage that the messages are short and well structured due to fixed parameter size. ASCII has advantage that you can type the messages into the serial monitor for debugging and typically data bytes are numerical ('0', '1' etc) while message bytes are text ('setcolour' etc) which means conflicting bytes do not have to be escaped.

To get started, try the Messenger library. Note that `#include "WProgram.h"` has to be changed to `#include "Arduino.h"` in the `.cpp` and `.h` files.

For the set colour message, if you used something like:

`setcolour,99,0,0,255,0,0\n`

You could use `Messenger` to parse it like:

Preamble:

```
#include "Messenger.h"
Messenger message = Messenger(','); //Message values separated by ','

```

In `setup()`:

```
message.attach(messageCompleted);

```

In `loop()`:

```
while(Serial.available()) {
    byte inbyte = Serial.read();
    message.process(inbyte);
}

```

Then implement the callback function:

```
void messageCompleted()
{
    if (message.checkString("setcolour")) {
        colour1[0] = message.readInt();
        colour1[1] = message.readInt();
        colour1[2] = message.readInt();
        colour2[0] = message.readInt();
        colour2[1] = message.readInt();
        colour2[2] = message.readInt();
    }
}

```

where `colour1` and `colour2` store the two RGB values.

# Answer
> 1 votes
`int value = int(red(c1[0]));` gives you **99** not **99.0**

You could read a byte (that's what `Serial.read` returns; **not an int**), and make some decision based on that character, then read again.

Or, you could read all the available data till `'\n'` new line character comes. What `println(value);` line does it sends `99`+`'\n`

Code:

```
// Buffer to store incoming commands from serial port
String inData;

void setup() {
    Serial.begin(9600);
    Serial.println("Waiting for Processing color...\n");
}

void loop() {
    while (Serial.available() > 0)
    {
        char recieved = Serial.read();
        inData += recieved;

        // Process message when new line character is recieved
        if (recieved == '\n')
        {
            Serial.print("Arduino Received: ");
            Serial.print(inData);

            inData = ""; // Clear recieved buffer
        }
    }
}

```

In case this is not working change your processing code line:

`myPort.write(value);`

to

`myPort.println(value);`

or

```
myPort.write(value);
myPort.write('\n');

```

# Answer
> -1 votes
The communication between the arduino and processing is 9600bit/s I suppose.

This will mean, that one bit needs 0.104ms to be sent. But with your Arduino code and the while-function you don't wait till the 8 bits of your byte are arrived and the arduino-loop is to fast for the serial connection. Wit other words: you cant use our wihile() function, use an if statement:

```
int x;
if (Serial.available()>0) {
  x = Serial.read();
}

```

and for debugging you can include once more the Serial.print()-function

(Sorry for my terrible English...)

---
Tags: serial
---


# Question
Title: How do send sketch updates to devices without the editor?
I'd like to update the sketch of a device that a friend out of state is testing. I could have them install the full editor and send the source code but I'd rather not require them to do something so technical.

Is there a way to compile the firmware binary and push that out to a device over the COM port more directly?

# Answer
In general, yes.

The compile routine creates a .hex file in a temporary directory that contains the flash image for the device. One can use AVRDUDE to upload this .hex file to the Arduino from the command line. It is simply a matter of getting the command arguments correct in order to tell it where and how to upload the image. Enabling verbose output in the IDE will tell you both exactly where the .hex file is located and what arguments are required for the board selected.
> 4 votes

---
Tags: uploading, firmware
---


# Question
Title: Arduino Uno R3 Bluetooth Shield is not discovering in any of the device
I have a problem regarding Seeedstudio Bluetooth shield http://www.seeedstudio.com/depot/Bluetooth-Shield-p-866.html

I can't detect its presence by any other devices.

The code I uploaded to Arduino is a standard example for slave device from the library:

```
#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 6
#define TxD 7

#define DEBUG_ENABLED  1

SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{
    Serial.begin(9600);
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);
    setupBlueToothConnection();
}

void loop()
{
    char recvChar;
    while(1)
    {
        if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
            recvChar = blueToothSerial.read();
            Serial.print(recvChar);
        }
        if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
            recvChar  = Serial.read();
            blueToothSerial.print(recvChar);
        }
    }
}

void setupBlueToothConnection()
{
    blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
    blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
    blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
    blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
    blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
    delay(2000); // This delay is required.
    blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
    Serial.println("The slave bluetooth is inquirable!");
    delay(2000); // This delay is required.
    blueToothSerial.flush();
}

```

I've uploaded it to Arduino UNO, connected the shield.

LED marked as D1 is blinking green, and D2 is switched off. The device is not detected by none of the devices I've tried

Please Help Me

# Answer
> 1 votes
As per this site: http://www.rjanick.com/2012/11/26/seeed-studio-bluetooth-shield/

Try switching the `#define rxd` and `#define txd` pin numbers in the code, inversely corresponding to the ones that the jumpers are connected to on the board.

For instance: my pins are jumped from the BT\_TX line to digital 6 (and BT\_RX to pin 7), so in the code I write `#define TxD 7`, and `RxD 6`. This made the board's LEDs blink differently (red blinks on D2 until connection).

---
Tags: bluetooth, arduino-uno
---


# Question
Title: 2.4" TFT LCD Shield isn't working on Arduino Mega
Even on ebay's website it is mentioned that I can't use 2.4" TFT LCD Shield display on attach to Arduino Mega. The problem is that I bought this shield by mistake. I want to put this shield onto Arduino Mega 2560. Is there a way to combine Mega and 2.4" Display Shield?

note: I tried on my friend's Arduino Uno. Shield is working very good.

note: The photo below is determining my question. The display not runs my Arduino's code. It only runs its LED.

```
    // UTFT_Demo_320x240 (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for modules with a screen resolution
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

#include <UTFT.h>
#define ILI9320_16 18
// Declare which fonts we will be using
extern uint8_t SmallFont[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(UNO_24,A2,A1,A3,A4);   // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT myGLCD(ILI9320_16,38,39,40,41);   // Remember to change the model parameter to suit your display module!

void setup()
{
  randomSeed(analogRead(0));

// Setup the LCD
  pinMode(A0,OUTPUT);       // for the UNO_SHIELD_1IN1
  digitalWrite(A0,HIGH);    // the RD pin must be set high
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
}

void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;

// Clear the screen and draw the frame
  myGLCD.clrScr();

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.fillRect(0, 226, 319, 239);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
  myGLCD.setBackColor(64, 64, 64);
  myGLCD.setColor(255,255,0);
  myGLCD.print("<http://electronics.henningkarlsen.com>", CENTER, 227);

  myGLCD.setColor(0, 0, 255);
  myGLCD.drawRect(0, 14, 319, 225);

// Draw crosshairs
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);
  for (int i=9; i<310; i+=10)
    myGLCD.drawLine(i, 117, i, 121);
  for (int i=19; i<220; i+=10)
    myGLCD.drawLine(157, i, 161, i);

// Draw sin-, cos- and tan-lines
  myGLCD.setColor(0,255,255);
  myGLCD.print("Sin", 5, 15);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
  }

  myGLCD.setColor(255,0,0);
  myGLCD.print("Cos", 5, 27);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
  }

  myGLCD.setColor(255,255,0);
  myGLCD.print("Tan", 5, 39);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);

// Draw a moving sinewave
  x=1;
  for (int i=1; i<(318*20); i++)
  {
    x++;
    if (x==319)
      x=1;
    if (i>319)
    {
      if ((x==159)||(buf[x-1]==119))
        myGLCD.setColor(0,0,255);
      else
        myGLCD.setColor(0,0,0);
      myGLCD.drawPixel(x,buf[x-1]);
    }
    myGLCD.setColor(0,255,255);
    y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
    myGLCD.drawPixel(x,y);
    buf[x-1]=y;
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled, rounded rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled circles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillCircle(100+(i*20),60+(i*20), 30);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some lines in a pattern
  myGLCD.setColor (255,0,0);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(1, i, (i*1.44)-10, 224);
  }
  myGLCD.setColor (255,0,0);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(318, i, (i*1.44)-11, 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(1, i, 331-(i*1.44), 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(318, i, 330-(i*1.44), 224);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random circles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=32+random(256);
    y=45+random(146);
    r=random(30);
    myGLCD.drawCircle(x, y, r);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRect(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rounded rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRoundRect(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(209);
    x2=2+random(316);
    y2=16+random(209);
    myGLCD.drawLine(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<10000; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    myGLCD.drawPixel(2+random(316), 16+random(209));
  }

  delay(2000);

  myGLCD.fillScr(0, 0, 255);
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRoundRect(80, 70, 239, 169);

  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("That's it!", CENTER, 93);
  myGLCD.print("Restarting in a", CENTER, 119);
  myGLCD.print("few seconds...", CENTER, 132);

  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 255);
  myGLCD.print("Runtime: (msecs)", CENTER, 210);
  myGLCD.printNumI(millis(), CENTER, 225);

  delay (10000);
}

```

# Answer
I just happened to buy the same LCD Shields a few days ago, looking for a library to use it with a MEGA 2560 board I found https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code which supports both **UNO** and **MEGA** boards.

Usage is very, simple if we want to use it for **MEGA** we should change the header `#include "uno_24_shield.h"` in **SWTFT.cpp** to `#include "mega_24_shield.h"`

**Description (useful for adding suppport for the shield in other libraries):**

Incompatibility comes from different Port mappings for Arduino pin-out between Mega and UNO.

in **UNO** LCD shield will be connected through:

```
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| LCD Data Bit  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Digital pin # |  7  |  6  |  5  |  4  |  3  |  2  |  9  |  8  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Uno port/pin  | PD7 | PD6 | PD5 | PD4 | PD3 | PD2 | PB1 | PB0 |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+

```

in **MEGA** it will be connected through:

```
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| LCD Data Bit  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Digital pin # |  7  |  6  |  5  |  4  |  3  |  2  |  9  |  8  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| MEGA port/pin | PH4 | PH3 | PE3 | PG5 | PE5 | PE4 | PH6 | PH5 |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+

```
> 7 votes

# Answer
A way to proceed is to create a spreadsheet showing the pin positions used by this board, and the Arduino shield signals they plug into. Next to these, you need columns showing the actual signals on the ATMega2560 (for Mega2560) and ATMega328 (for Uno) that these shield pins attach to. You can get this info from the Uno and Mega2560 schematic drawings.

In a quick look, it seems that the Arduino shield pin names for Uno and Mega are the same: for example, shield pin '0' (digital zero) is in the same location on both boards, and likewise for other pins.

However, on the Uno digital-0 attaches to ATMega328 Port D bit 0, while on the Mega2560, it attaches to ATMega2560 Port E bit 0. And things get more obtuse with digital 2..7.

Now, when twiddling bits individually using digitalWrite(pin, value), the Arduino library no doubt takes care of translating to the appropriate port/bits that need to be set for the ATMega chip and Arduino board that's in use. However, libraries that use lower-level functions (especially if they need to write entire bytes to ports, as a fast LCD library might) will need to take their own steps to make this translation.

So... first step is to determine whether there is a separate LCD driver library for Mega2560.

Next, investigate whether the library you have has initialization code that is supposed to determine what board it's running on (and is your board included?), or requires you to set some flag to tell it what board is in use.

Failing that, you *could* create a mess of jumpers or some other wiring scheme to jumper the Mega's ATMega2560's signals so that it's wired up like a Uno would be. It's not clear that this is possible, since some of ATMega2560's Port D is not even wired to a header.

Or you could look at the source code for the library and see what it's actually doing, and what it would need to do different to operate the ATMega 2560 pins that the shield does connect to.
> 4 votes

# Answer
Have you checked out the Library homepage? Henning Karlsen's library page

He has made a user manual for the library. There is also a reference to what pin goes where in the requirements document.
> 2 votes

# Answer
You need to compare the pins' functions between your Mega and your friend's Uno. Then you need to make those electrical connections happen. I talk about this a little in the "pin locations" section of my answer here.

This requires "hacking". Something needs to be done to reroute those physical connections. I normally use an intermediate shield to translate pins as needed. There was a shield specifically made for this purpose but I couldn't find it. Maybe this one would work?
> 0 votes

---
Tags: arduino-mega, shields, lcd
---


title: PWM generation using Registers

text:
# Question
Title: PWM generation using Registers
I'm using the Registers of the Arduino micro to get a signal for Electronic Speed Controllers (ESC) for brushless motors. As far as I read, ESCs interpret everything they can, while just ignoring too fast update rates. If somebody knows better, this would be a great time to yell.

The goal is to get a digital signal, where a timespan between 1 and 2 ms is HIGH and the rest low. Ideally I want this at 50-400Hz, since 488Hz is the fastest possible frequency, and 50 Hz the standard Servo frequency.

I try to use Phase Correct Mode to count up and down continuously. As the value in the counter reaches my set OCRnx on the way up, it sets the output pin LOW, as it reaches the same value on the way down, after reaching TOP(value), it sets the output HIGH. In ATmega documentation terms, this is NON-inverted Phase-Correct-PWM.

So I set the Registers DDR (to set the pin as output), TCCR1A and TCCR1B and ICR1 (TOPvalue = between 20000 and 2500).

Now using OCR1A = 1000 should give me a pulse width of 1000ms. This is the expected or target behaviour.

My testing code is:

```
// using a 16-bit timer to generate PWM signals for ESCs

// Phase Correct Mode counts from Bottom to Top and back to Bottom
// with a prescaler of 8
// motor signal (OCRnx) uses values of 1000 (idle) - 2000 (max)
// which directly corresponds to microseconds HIGH-time
// setting the range to (BOTTOM) 0 - TOPvalue sets the frequency

// two important formulas are:
// frequency(PWM) = F_CPU / (2*Prescalar*TOPvalue)
//
// PulseWidth [s] = High-tick-count / (F_CPU/Prescalar)
// High-tick-count = 2 * OCR-value

// n = number of timer (1,3)
// x = A,B,C

#include "Arduino.h"
// #include <Arduino.h>
// #define DEBUG
// #include <Moto.h>

#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)

uint16_t dutytime = 1000; // this gives idle throttle signal

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

  // TIMER 1
  // TIMSK1 = 0; // disable Interrupts for timer1
  DDRB |= (1<<DDB5); // D9 Output
  DDRC |= (1<<DDC6); // D5 Output

  // set 1000ms to start motors in idle mode
  OCR1A = 1000L;
  OCR3A = 1000L;

  // bits 7,5,3 PWM Output on pins A,B,C respectively
  // bits 1,0 WGM_1,0: phase correction mode
  // TCCR1A |= B10000010; // in hex: 0xAA for all 3 = B 1010 1010
  TCCR1A |= (1<<COM1A1)|(1<<WGM11);
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  // TCCR1B |= B00010010; // in hex: 0x12; B 0001 0010
  TCCR1B |= (1<<WGM13)|(1<<CS11);
  ICR1 = TOP_VALUE;

  // TIMER 3
  // TIMSK3 = 0; // disable Interrupts for timer3
  // bit 7 PWM Output on pin A
  // bits 1,0 WGM_1,0: phase correction mode
  TCCR3A |= B10000010; // in hex: 0x82; // B 1000 0010
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  TCCR3B |= B00010010; // in hex: 0x12; B 0001 0010
  ICR3 = TOP_VALUE; // TOPvalue = 2048

}//setup

void loop(void) {

  // Serial.println(TOP_VALUE);
  // delay(500);
  while (dutytime < 2000) {
    dutytime += 150;
    OCR1A = dutytime;
    OCR3A = dutytime;
    Serial.println(dutytime);
    delay(1500);
  }
  while (dutytime > 1000) {
    dutytime -= 150;
    OCR1A = dutytime;
    OCR3A = dutytime;
    Serial.println(dutytime);
    delay(1500);
  }

}//loop

```

I repeated the settings for timer3 to get something to compare to. Both do give the same: if i delete the loop and just write `loop{}` nothing happens. The pins are high and seem to stay so. With the while loops activated, my multimeter gives me 1Hz (which are the changes of course) and between 99.9% duty cycle and 96%. An led, which i connected to it blinks every second a very short time.

What am I doing wrong?

# Answer
> 0 votes
What I did wrong was using `|=` instead of `=` . Apparently Arduino set some of these Bits on start, which didn't change. Now it works like a charm and I added a frequency choice, which works for at least 50,200,400,488 Hz. Everything in between should work aswell!

Working testcode for timer1 with serial input of HIGH-time:

```
#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)

uint16_t dutytime = 1000; // this gives idle throttle signal

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

  // TIMER 1
  DDRB |= (1<<DDB5); // D9 Output

  // set 1000ms to start motors in idle mode
  OCR1A = 1000L;

  // bits 7,5,3 PWM Output on pins A,B,C respectively (COMnx1)
  // bits 1,0 WGM1(1,0): phase correction mode
  TCCR1A = B10000010; // in hex: 0xAA for all 3 = B 1010 1010
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  TCCR1B = B00010010; // in hex: 0x12; B 0001 0010
  ICR1 = TOP_VALUE;
}//setup

void loop(void) {
  // Serial.println(TOP_VALUE);
  dutytime = serial_input();
  if (dutytime) {
    OCR1A = dutytime;
  }
  delay(500);
}//loop

float serial_input() {
  double num = 0;
  while(Serial.available()) {
    delay(2);
    char ser = Serial.read();
    if(isDigit(ser)) {
      num = (num*10)+(ser-48);
    }else{ break; }
  }
  if (num) {Serial.println(num);}
  return num;
}

```

---
Tags: motor, pwm
---


title: Arduino can't create file in sd card

text:
# Question
Title: Arduino can't create file in sd card
I need to write and read some data from SD card. I link SD card(LC STUDIO) to Arduino (UNO). I use this link for create my project. In first day I don't have any problem and data correctly save to file. But now my circuit isn't work nicely. When Arduino is running the sketch I don't saw any error message.But when I link the SD card to my laptop, I don't saw any file on card!! The code is here:

```
#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

File file;

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

  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
  }
  Serial.println("card initialized.");
  //creating file
  file = SD.open("test.txt",FILE_WRITE);
  file.close();
  //write data to file
  file = SD.open("test.txt",FILE_WRITE);
  if(file){
    file.println("OK!!");
    file.println("1");
    file.println("2");
    file.println("3");
    file.println("OK!!");
    file.close();
  }
}
void loop()
{
}

```

# Answer
> 1 votes
Thank you all... I found solution for my problem. The circuit and the sketch isn't any problem. But I saw this and I think problem is because of LC Studio's SD card. In previous circuit I connect 5v pin of SD card to 5v pin on arduino. But now I disconnect that and connect 3v3 pin on card to 3v3 on arduino. Now it's work very nice. And I don't know "why?" . Any idea?

# Answer
> 0 votes
If there is no file on the card, you must first create the "test.txt" file and put it in the main directory of your SD card. Your code doesn't create a file and I don't think you can even do that with the SD library. If you want to create a file, you are going to have to use the SDfat library. Also take out this part of your code : `file.close();` `file = SD.open("test.txt",FILE_WRITE);`

You are just opening, then closing, and then reopening.

---
Tags: arduino-uno, sd-card
---


# Question
Title: How to wait for next n bytes in I2C exchange?
I'm trying to get data from a sensor, but don't see how I can get data back. I'm looking at the data on the I2C bus with a logic analyzer, and I'm sending what I expect, but I seem to cut off the slave before he can respond. My understanding from the datasheet is that I need to send this command to wake it up and request a measurement:

`0xD8 0x30 0x0A`

and then I need to send this command to get the data:

`0xD8 0x06 0xD9`

```
#define HEARTBEAT_PIN            (13)

#define 7BIT_ADDR                (0x6C)
#define ADDR_WRITE               (0xD8)
#define ADDR_READ                (0xD9)

#define MAX_NUM_RX_BYTES         (8)
#define MAX_NUM_TX_BYTES         (8)

static uint8_t tx_buffer[MAX_NUM_TX_BYTES];
static uint8_t rx_buffer[MAX_NUM_RX_BYTES];
static uint8_t new_rx_data;

void setup(void) {
  // Clear any module memory
  memset(tx_buffer, 0, MAX_NUM_TX_BYTES);
  memset(rx_buffer, 0, MAX_NUM_RX_BYTES);
  new_rx_data = false;

  Wire.begin();
}

void loop(void) {
  RequestMeasurement();
  delay(10);
  GetData();
  delay(500);
}

void RequestMeasurement(void) {
  // MR: 0xD8 0x30 0x0A
  // Internal (to IC) register address?
  tx_buffer[0] = 0x30;
  // Request-measurement command
  tx_buffer[1] = 0x0A;
  Wire.beginTransmission(7BIT_ADDR);
  Wire.write(tx_buffer, 2);
  Wire.endTransmission(true);
}

void GetData(void) {
  // GD: 0xD8 0x06 0xD9 0x?? 0x?? 0x?? 0x?? 0x?? (0x?? => slave data)
  // Slave address + 'write' indication bit
  // Internal (to IC) register address?
  tx_buffer[0] = 0x06;
  // Slave address + 'read' indication bit
  tx_buffer[1] = ADDR_READ;

  Wire.beginTransmission(7BIT_ADDR);
  Wire.write(tx_buffer, 2);
  Wire.endTransmission(true);

  // HOW DO I LEAVE THE BUS OPEN LONG ENOUGH
  // FOR THE SLAVE DEVICE TO RESPOND WITH THE DATA?
  //Wire.requestFrom(7BIT_ADDR, 3, true);
}

```

# Answer
> 0 votes
Ensure pullups (see datasheet for min acceptable resistance) are on I2C lines.

What I didn't understand at first was where the Wire library would bit shift and add read/write indication bits. And those start/stop booleans. After some testing and a closer read of the docs, I got this to work:

```
#include "Wire.h"

#define BAR_7BIT_ADDR         (0x6C)
#define MAX_NUM_RX_BYTES      (5)
#define MAX_NUM_TX_BYTES      (3)
#define FIRST_TEMP_BYTE_INDEX (3)

uint8_t new_rx_data;
uint8_t tx_buffer[MAX_NUM_TX_BYTES];
uint8_t rx_buffer[MAX_NUM_RX_BYTES];

void setup(void) {
  Serial.begin(57600);
  Wire.begin();
}

void loop(void) {
  // If new data is available
  if (new_rx_data) {
    new_rx_data = false;

    // Process the data in the background
    PrintRxData();
  }

  BAR_RequestMeasurement();
  BAR_GetData();

  // This is a bit of a hack to get this function to execute.
  // After attempting to register this function as a callback with
  // the Wire.onReceive() method the function wouldn't execute.
  BAR_OnDataReceived(0);

  // Wait a tit, then do it again
  delay(500);
}

void RequestMeasurement(void) {
  // MR: 0xD8 0x30 0x0A
  // Internal (to IC) register address
  tx_buffer[0] = 0x30;
  // Request-measurement command
  tx_buffer[1] = 0x0A;
  Wire.beginTransmission(BAR_7BIT_ADDR);
  Wire.write(tx_buffer, 2);
  Wire.endTransmission(true);
}

void GetData(void) {
  // GD: 0xD8 0x06 0xD9 response from slave
  // Internal (to IC) register address
  tx_buffer[0] = 0x06;
  Wire.beginTransmission(BAR_7BIT_ADDR);
  Wire.write(tx_buffer, 1);
  Wire.endTransmission(false);
  Wire.requestFrom(BAR_7BIT_ADDR, 5, true);
}

void OnDataReceived(int num_bytes) {
  uint8_t i = 0;
  while (Wire.available() && i < MAX_NUM_RX_BYTES) {
    rx_buffer[i++] = Wire.read();
  }

  // Indicate to the background that there is new rx data
  new_rx_data = true;
}

void PrintRxData(void) {
  Serial.print("Pressure [kPa]: ");
  Serial.print(ToKpa(rx_buffer));
  Serial.print("\r\n");

  Serial.print("Temperature [C]: ");
  Serial.print(ToCelsius(&rx_buffer[FIRST_TEMP_BYTE_INDEX]));
  Serial.print("\r\n");
}

// Returns the pressure in kPa given raw binary data
float ToKpa(uint8_t* raw_data) {
  // example: raw_data[3] = {0x63, 0x6C, 0xBB}; => 101.81kPa
  // return ((float)((((uint32_t)raw_data[0]) * 65536) |
  //                  (((uint32_t)raw_data[1]) * 256)  |
  //                  (((uint32_t)raw_data[2]) * 1))) / 64.0 / 1000.0;
  return ((float)((
                  (((uint32_t)raw_data[0]) << 16) |
                  (((uint32_t)raw_data[1]) << 8)  |
                  (((uint32_t)raw_data[2]) << 0)
                  ) >> 6)) / 1000.0;
}

// Returns the temperature in Celsius given raw binary data
float ToCelsius(uint8_t* raw_data) {
  // example: raw_data[2] = {0x18, 0xE6}; => 24.90C
  // return ((float)(((uint32_t)raw_data[0]) * 256) + (((uint32_t)raw_data[1]) * 1)) / 256.0;
  return ((float)(
                 (((uint32_t)raw_data[0]) << 8) |
                 (((uint32_t)raw_data[1]) << 0)
                 )) / 256.0;
}

```

# Answer
> 3 votes
First off; when talking about I2C bus, an important point to clarify: did you connect pullup resistors to both **SDA** and **SCL** lines (`A4` and `A5` respectively)? Without those, the I2C bus will not work properly.

Next, I2C protocol is quite low-level and a bit complex; but fortunately, the **Wire** library that comes with Arduino helps a lot and hides some of this complexity.

When using Wire library, there is a first point to keep in mind:

The device address is 7 bits only, the 8th bit is used to define the direction of data (read or write). You don't need to care about this direction bit as Wire deals with it for you.

In your situation, the device address is `0x6C`, ie `1101100` in binary.

The commands you mentioned that you want to send to the device, `0xD8 0x30 0x0A` and `0xD8 0x06 0xD9` already include the device address and the write bit (`0`):

`0xD8` is `1101 1000` ie `1101100` plus the `0` direction bit at the end.

Please note that `0xD8 0x06 0xD9` is made of 2 commands actually:

* `0xD8 0x06` is a write command to tell the device hich register we want to read
* `0xD9` is just the device address followed by the read bit (`1`): this is the way the I2C master tells a slave that the former will now wait for data sent from the latter.

It is important to split this command in 2 because each will use a specific API from Wire library.

Writing to your device with the Wire library will be done this way:

```
// First command: start measurement
Wire.beginTransmission(0x6C);
Wire.write(0x30);
Wire.write(0x0A);
Wire.endTransmission();

// Second command: tell the device what register we want to read
Wire.beginTransmission(0x6C);
Wire.write(0x0A);
Wire.endTransmission();

```

Then you can start reading from your device with a different API:

```
Wire.requestFrom(0x6C, 3);
byte b1 = Wire.read();
byte b2 = Wire.read();
byte b3 = Wire.read();
// Now rebuild value from the 3 bytes just read...

```

Note that `Wire.requestFrom(0x6C, 3);` will send the `0xD9` that is calculated from the device address `0x6C` and the read bit. SO you don't have (and you should not) send `0xD9` yourself, Wire doesit for you.

Please note that I use `Wire.endTransmission()` without the `stop` argument. Not sure if this is mandatory, but it worked fine on my I2C experiments.

# Answer
> 2 votes
In the diagram there is a `S` after sending `0x60`. You first write to the device, letting it you want to read, and then you start reading.

I think you need to do something like

```
void GetData(void) {
  Wire.beginTransmission(7BIT_ADDR);
  Wire.write(0x06);
  Wire.endTransmission(false);//don't terminate connection

  Wire.requestFrom(7BIT_ADDR, 3);//this will send the 0xD9
  pressure = ( (uint32_t) i2cread() << 16) | ( i2cread() << 8 ) | i2cread();//or something

}

```

But I've never used I2C.

---
Tags: i2c
---