text:
Problem with PWM function on RGB LED and IR
I'm having an issue in controlling a RGB LED with Arduino and a remote control. When including the library IRRemote.h (version 2.2.3), the blue channel only works in on/off logic instead of PWM. If I remove the library, the PWM logic of the blue channel works normally and it does accept the whole range (0-255). I'm using an Arduino/Elegoo Uno R3 board. What could be causing the issue?
Below the code:
#include "IRremote.h"

int pinRic = 9; // Signal Pin of IR receiver to Arduino Digital Pin 11
IRrecv ricevitore(pinRic);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'
#define BLUE 3
#define GREEN 5
#define RED 6
#define IR_BPlus  0xFF3AC5  //
#define IR_BMinus 0xFFBA45  //
#define IR_ON     0xFF827D  //
#define IR_OFF    0xFF02FD  //
#define IR_R    0xFF1AE5  //
#define IR_G    0xFF9A65  //
#define IR_B      0xFFA25D  //
#define IR_W    0xFF22DD  //
#define IR_B1   0xFF2AD5  //
#define IR_B2   0xFFAA55  //
#define IR_B3   0xFF926D  //
#define IR_B4   0xFF12ED  //
#define IR_B5   0xFF0AF5  //
#define IR_B6   0xFF8A75  //
#define IR_B7   0xFFB24D  //
#define IR_B8   0xFF32CD  //
#define IR_B9   0xFF38C7  //
#define IR_B10    0xFFB847  //
#define IR_B11    0xFF7887  //
#define IR_B12    0xFFF807  //
#define IR_B13    0xFF18E7  //
#define IR_B14    0xFF9867  //
#define IR_B15    0xFF58A7  //
#define IR_B16    0xFFD827  //
#define IR_UPR    0xFF28D7  //
#define IR_UPG    0xFFA857  //
#define IR_UPB    0xFF6897  //
#define IR_QUICK  0xFFE817  //
#define IR_DOWNR  0xFF08F7  //
#define IR_DOWNG  0xFF8877  //
#define IR_DOWNB  0xFF48B7  //
#define IR_SLOW   0xFFC837  //
#define IR_DIY1   0xFF30CF  //
#define IR_DIY2   0xFFB04F  //
#define IR_DIY3   0xFF708F  //
#define IR_AUTO   0xFFF00F  //
#define IR_DIY4   0xFF10EF  //
#define IR_DIY5   0xFF906F  //
#define IR_DIY6   0xFF50AF  //
#define IR_FLASH  0xFFD02F  //
#define IR_JUMP3  0xFF20DF  //
#define IR_JUMP7  0xFFA05F  //
#define IR_FADE3  0xFF609F  //
#define IR_FADE7  0xFFE01F  //
#define incFact 30
int  brightFact = 0;
int lv[3];

void fade7()
{
#define delayTime 10 // fading time between colors

  lv[0] = 255; // choose a value between 1 and 255 to change the color.
  lv[1] = 0;
  lv[2] = 0;

  for (int i = 0; i < 255; i += 1) // fades out R bring G full when i=255
  {
    lv[0] -= 1;
    lv[1] += 1;

    analogWrite(RED, lv[0]);
    analogWrite(GREEN, lv[1]);
    delay(delayTime);
  }

  lv[0] = 0;
  lv[1] = 255;
  lv[2] = 0;

  for (int i = 0; i < 255; i += 1) // fades out G bring B full when i=255
  {
    lv[1] -= 1;
    lv[2] += 1;

    analogWrite(GREEN, lv[1]);
    analogWrite(BLUE, lv[2]);
    delay(delayTime);
  }

  lv[0] = 0;
  lv[1] = 0;
  lv[2] = 255;

  for (int i = 0; i < 255; i += 1) // fades out B bring R full when i=255
  {
    lv[2] -= 1;
    lv[0] += 1;

    analogWrite(BLUE, lv[2]);
    analogWrite(RED, lv[0]);
    delay(delayTime);
  }
}

void setColor(int r, int g, int b)
{
  Serial.println("About to write:");
  Serial.println(r);
  Serial.println(g);
  Serial.println(b);
  analogWrite(RED, r);
  analogWrite(GREEN, g);
  analogWrite(BLUE, b);
}

void  translateIR() // takes action based on IR code received
{
// describing Remote IR codes
  Serial.println(results.value, HEX);
  switch (results.value)
  {
    //case IR_BPlus: setBright(true);break;
    //case IR_BMinus: setBright(false);break;
    case IR_OFF: setColor(0, 0, 0); break;
    //COLORS
    case IR_R: setColor(255, 0, 0); break;
    case IR_G: setColor(0, 255, 0); break;
    case IR_B: setColor(0, 0, 255); break;
    case IR_W: setColor(255, 255, 255); break;
    case IR_B1: setColor(255, 20, 0); break;
    case IR_B2: setColor(0, 255, 20); break;
    case IR_B3: setColor(20, 0, 255); break;
    case IR_B4: setColor(255, 20, 255); break;
    case IR_B5: setColor(255, 90, 0); break;
    case IR_B6: setColor(0, 255, 90); break;
    case IR_B7: setColor(90, 0, 255); break;
    case IR_B8: setColor(255, 150, 255 ); break;
    case IR_B9: setColor(255, 191, 0); break;
    case IR_B10: setColor(0, 255, 191); break;
    case IR_B11: setColor(191, 0, 255); break;
    case IR_B12: setColor(120, 255, 255); break;
    case IR_B13: setColor(255, 255, 0); break;
    case IR_B14: setColor(0, 255, 255); break;
    case IR_B15: setColor(255, 0, 255); break;
    case IR_B16: setColor(150, 255, 255); break;

    //END COLORS
    case IR_FADE7: fade7();
  }// End Case

  delay(100); // Do not get immediate repeat
} //END translateIR

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  ricevitore.enableIRIn(); // Start the receiver*/

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (ricevitore.decode(&results)) // have we received an IR signal?
  {
    translateIR();
    ricevitore.resume(); // receive the next value*/
  }
} /*--(end main loop )-- */

By default, the IRremote library uses Timer 2 on an ATmega328P. (Library documentation) This timer is also used for PWM on pins 3 and 11.
This means that you will have to use a different PWM pin for your blue LED (e.g. 9 or 10, controlled by Timer 1).
Alternatively, you could edit the IRremote library to use Timer 1.


text:
Uploading Lua code to Arduino
I have Arduino UNO board. Can I upload programs written in Lua?
I wrote a code for simple home automation using relays to control lights and tried to upload it to my Arduino board, I get error code of "Error compiling for board Arduino/Genuino Uno"? What does this mean?
This is the code I used:
var("Switch", "ME.BI21")
var("Relay", "ME.BO21")
var("RelayState", "ME.BO41")

RelayState = 1

Relay = Switch

if (Relay == 1 then){
  print("The Relay is ON")
}
else{
  print("The Relay is OFF")
}
end

The Uno can’t run Lua code. The ESP8266 modules like the Wemos D1 or NodeMCU can, with the right firmware.

source: Stack Exchange

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

sort: votes


text:
ILI9163C screen not working properly
I've just tried out my new TFT_ILI9163C display with TFT_ILI9163C library but I'm having an issue with it. The graphics has moved down (the "hello world" should be in the top left) and the leftover space looks like there was no signal. Can be seen in the photo.
What could be wrong?

Have you read the section entitled "BLACK, RED or ..." in your link above?

Arduino\libraries\TFT_ILI9163C_settings\TFT_ILI9163C_settings.h
Change value here... #define __OFFSET 0//*see note 2

I had the same board and problem as you, what fixed is was changing the board setting to black even though it is phyiscally red.
Inside
Arduino\libraries\TFT_ILI9163C\_settings\TFT_ILI9163C_settings.h

Change
//  ---> SELECT HERE <----
#define __144_RED_PCB__//128x128
//#define __144_BLACK_PCB__//128x128
//#define __22_RED_PCB__//240x320

to
//  ---> SELECT HERE <----
//#define __144_RED_PCB__//128x128
#define __144_BLACK_PCB__//128x128
//#define __22_RED_PCB__//240x320

This worked but I'm unable to accept this answer. Is it due to lots of time having been spent since it was written?

Open the file
{sketchbook folder}/libraries/TFT_ILI9163C/_settings/TFT_ILI9163C_settings.h
in a text editor. You can find the location of the sketchbook folder in the Arduino IDE at File > Preferences > Sketchbook location.
Change:
#define __OFFSET      32

to:
#define __OFFSET      0

Save the file.
Upload the sketch to the Arduino board again.

This was what worked for me too. Although there is a white line in the right and bottom borders now and it wasn't there before, This line is not at the top and left borders.

I wrote my own driver for DisplayCore for that very same board a while back and found the exact same problem.
The issue is just the setting for the offset of the GRAM which it looks like there is a setting for in the library you are using.  Get that value right and you will have a proper display.

I see it - but what to do with that? I'm trying to make work the benchmark example. Copied the #define stuffs but no luck so far ...

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

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


text:
ESP8266-07 no work after reboot
I try move my projects from atmega to ESP8266-07 modules. I connect ESP8266-07 to FT232:
(ESP) RX -------- TX (FT232)
(ESP) TX -------- RX (FT232)
(ESP) GND ------- GND (FT232)
(ESP) VCC ------- VCC 3.3V (FT232)
(ESP) EN -------- VCC 3.3V (FT232)
(ESP) GPIO0 ----- GND (FT232)
(ESP) GPIO15 ---- GND (FT232)

I can upload sketch and it's work. BUT...
... WHEN I restart ESP (software reset or hardware reset - unplug power) program no starting. I try change connections after upload like:
Try 1:
(ESP) RX -------- TX (FT232)
(ESP) TX -------- RX (FT232)
(ESP) GND ------- GND (FT232)
(ESP) VCC ------- VCC 3.3V (FT232)
(ESP) EN -------- VCC 3.3V (FT232)

Try 2:
(ESP) RX -------- TX (FT232)
(ESP) TX -------- RX (FT232)
(ESP) GND ------- GND (FT232)
(ESP) VCC ------- VCC 3.3V (FT232)
(ESP) EN -------- VCC 3.3V (FT232)
(ESP) GPIO0 ----- VCC 3.3V (FT232)

Try 3:
(ESP) RX -------- TX (FT232)
(ESP) TX -------- RX (FT232)
(ESP) GND ------- GND (FT232)
(ESP) VCC ------- VCC 3.3V (FT232)
(ESP) GPIO0 ----- VCC 3.3V (FT232)

But everytime sketch does not start after upload. This is not a code problem, because I try start "blink" sketch or other. Everytime ESP work once, after upload.

https://github.com/esp8266/esp8266-wiki/wiki/Boot-Process

sounds like you're leaving it in programming mode, which the first reboot after a flash ignores...

Thank you gre_gor. You were right about correct pins. If you want start ESP on "normal mode" you must plug pins like:
(ESP) GND ------- GND
(ESP) GPIO15 ---- GND
(ESP) VCC ------- VCC 3.3V
(ESP) EN -------- VCC 3.3V
(ESP) GPIO0 ----- VCC 3.3V
(ESP) GPIO2 ----- VCC 3.3V

But if we must use GPIO0, GPIO2 and GPIO15 how we have 9 GPIO, 2 UART and 1 ADC?

For me the same issue happened once ,i tries flashing the AT commands firmware (can download from espressif website)and then burned my test firmware to it ...worked.Try it..!


text:
Can't upload to arduino from clion
I'm trying to upload a script to my arduino uno (mega and nano doesn't work either). It works unless I #include <Adafruit_SSD1306.h>
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <SimpleDHT.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET  4

Adafruit_SSD1306 display(OLED_RESET);

// initializing foo here. const static unsigned char foo_bits[] PROGMEM = {0x00, 0x00 ///

void draw(void) {
    display.drawXBitmap( 0, 0,foo_bits, foo_width, foo_height, 1);
    display.display();
}

void setup(void) {
    display.begin();
    display.clearDisplay();
}

void loop(void) {
    draw();
}

The error I'm getting is
libuno_Adafruit_SSD1306.a(Adafruit_SSD1306.cpp.obj): In function `Adafruit_SSD1306::ssd1306_command(unsigned char)':
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `TwoWire::beginTransmission(int)'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `TwoWire::write(unsigned char)'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `TwoWire::write(unsigned char)'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `TwoWire::endTransmission()'
libuno_Adafruit_SSD1306.a(Adafruit_SSD1306.cpp.obj): In function `Adafruit_SSD1306::begin(unsigned char, unsigned char, bool)':
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `SPIClass::begin()'
libuno_Adafruit_SSD1306.a(Adafruit_SSD1306.cpp.obj): In function `SPIClass::beginTransaction(SPISettings)':
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `SPIClass::interruptMode'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `SPIClass::interruptMode'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `SPIClass::interruptSave'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `SPIClass::interruptMask'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `SPIClass::interruptSave'
libuno_Adafruit_SSD1306.a(Adafruit_SSD1306.cpp.obj): In function `Adafruit_SSD1306::begin(unsigned char, unsigned char, bool)':
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:416: undefined reference to `TwoWire::begin()'
libuno_Adafruit_SSD1306.a(Adafruit_SSD1306.cpp.obj): In function `Adafruit_SSD1306::display()':
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:472: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:472: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:472: undefined reference to `TwoWire::beginTransmission(int)'
libuno_Adafruit_SSD1306.a(Adafruit_SSD1306.cpp.obj): In function `TwoWire::write(int)':
/opt/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.h:78: undefined reference to `Wire'
/opt/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.h:78: undefined reference to `Wire'
/opt/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.h:78: undefined reference to `TwoWire::write(unsigned char)'
libuno_Adafruit_SSD1306.a(Adafruit_SSD1306.cpp.obj): In function `Adafruit_SSD1306::display()':
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:475: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:475: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:475: undefined reference to `TwoWire::write(unsigned char)'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:479: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:479: undefined reference to `Wire'
/opt/arduino/arduino-1.8.5/libraries/Adafruit_SSD1306/Adafruit_SSD1306.cpp:479: undefined reference to `TwoWire::endTransmission()'
collect2: error: ld returned 1 exit status

My cMake file is
cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)
set(PROJECT_NAME touch)
project(${PROJECT_NAME})
include_directories(/opt/arduino/arduino-1.8.5/libraries/)
set(${CMAKE_PROJECT_NAME}_SKETCH touch.ino)

set(${CMAKE_PROJECT_NAME}_BOARD uno)
set(${CMAKE_PROJECT_NAME}_PORT /dev/ttyACM0)
generate_arduino_firmware(${CMAKE_PROJECT_NAME})

If I remove all of the Adafruit_SSD1306 uploading works. The exact same program works from Arduino IDE. What could be the cause and how can I fix this?

The foo variables are all declared (see the commented line in the sketch, just wanted to keep the code short and foo_bytes is quite long). The sketch works from Arduino IDE and the libraries are updated. @LookAlterno

@LookAlterno But yeah - I don't see any kind of connection between sketch and error too, what makes this very hard to fix for me...

Patience? For what? @LookAlterno


text:
Sharing serial Rx to read a push button on ESP8266-01
I'd like to know if it's possible, and if so how to use the serial Rx pin in a shared way to read a push button?
I've seen people using it in sort of a dedicated way but my idea is to use it dynamically. Which means it would stay as a standard Rx pin, with a push button sharing it. So the question is, what would happen if the push button was pressed? Would it be possible to detect it from the Rx stream?

Just to make sure: Are you have a X-Y problem maybe? (https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). If your basic problem is "I don't have enough I/O pins on my ESP8266 to add a push-button", then the actual answer would be "add more I/O pins by adding a GPIO port expander over I2C or SPI", not "whack it onto the UART RX line and see if I can detect it"

Just get a WeMos D1 mini or similar. You get access to all 11 GPIO pins (except the SDIO pins of course, those are reserved for the flash memory) and a USB interface for easy programming. They're like $3.50 from China, so there's really no reason to use the ESP-01 in the first place.

I have experimented with my NodeMCU (ESP8266-12F, but the core chip is the same ESP8266EX).
First, the theory: UART is a asynchronous serial protocol. It has a configuration which consits of the baud rate (bits per second), parity bit (enabled or not) and number of stop bits (between 1-2). A common configuration is "9600N1", meaning 9600 bits per second, no parity bit, 1 stop bit.
If you want to trasmit the bitstring 0101 0101 with no parity, 1 stop bit, the RX line voltage will be:

RX line idles in high state (for us: 3.3V). Transmission is started by the start bit, which means that the line is pulled LOW. Then, the bits are transmitted LSB to MSB, followed by parity (if enable) and the stop bits.
I wrote the sketch
#include <Arduino.h>

void setup() {
    //use 300 Baud, lol
    Serial.begin(300);
}

void loop() {
    if(Serial.available()) {
        char readChar = (char) Serial.read();
        Serial.println("Read char: " + String(readChar) + " hex " + String((int)readChar, HEX));
    }
}

When transmitting a normal "A" (binary: 0100 0001) over serial, it looks like this in a logic analyzer:

When I connected a pulled-up button the RX line and press, the signal goes as

As one can see, the analyzer sees the pushing down of the button as a start bit, but the timing is way of. The line is pulled back to high much later. The time slot for the stop bit (which must be 1) was missed, so the logic analyzer displays "FRAMING ERROR". But the UART circuit inside the ESP8266 doesn't seem to care. It reads this as the transmission of a byte of the value "0x00".
Serial output: Read char:  hex 0
So, in response to the question "what would happen the push button was pressed?" we can say: At this speed of 300 baud (lowest possible setting), the UART received a bogus transmission but still reads it as an incomming 0x00 byte. However, depending on the bouncing of the signal due to the button presses, other received byte values might well be possible. You could be able to de-bounce the button to make the signal more stable, timing wise.
Anyway, you should not make a push button act as a crude UART transmitter if it isn't the absolute last possible solution. Depending on your application, you might be able to use the solution from this question and switch the function of the TXD0 and RXD0 to GPIO (more info). If you know exactly when to expect a button push, switch the pins to GPIO mode before and poll the status of the button (or install an interrupt).
However, as a bottom line: If you have no idea when the button will be pushed, then you will be fundamentally unable to distinguish the cause of the RX line falling low at the time the transition happens. It could be the transmission of some actual data (maybe also the zero-byte), but it could have also been the button.
A I²C GPIO port expander like the MCP23017 (link) would make much more sense, especially if you already have an I2C bus. There are also SPI devices available for this.


text:
What values are the Atmel MCUs EEPROMs preloaded with?
I have checked with two datasheets: one for some ATMegas and one for some ATTinys MCUs and could not find what the EEPROM.get() call would read back if the EEPROM was empty (or contained default factory values). I have written a program in order to find out and it looks like on Arduino Uno the EEPROM bytes are all FF by default.
Is this the case with every Arduino board or just some of them ? Or perhaps we can not assume that all the MCUs of a certain type (such as ATMega328) will have this factory preloaded value of FF for the EEPROM bytes ?
edit
Following the fuses - thanks @Chris Stratton - I was able to find this in the datasheet:

Skip writing the data value 0xFF, that is the contents of the entire
  EEPROM (unless the EESAVE Fuse is programmed) and Flash after a Chip
  Erase.

Seems like we could get the factory pre-loaded value by not programming the EESAVE fuse, which is what the Arduino Uno does by default, and just reading them.

uno.bootloader.low_fuses=0xFF
  uno.bootloader.high_fuses=0xDE
  uno.bootloader.extendedfuses=0xFD

However, having a way to set them to a known value is fine too for my needs, so I shall just write that fuse and havea  guaranteed 0xFF all over the EEPROM.

You'll have to check the specific ATmega fuse settings, but I believe that by default the Arduino programming process erases the EEPROM, so an Arduino-based test may not show you what the contents were before you uploaded the test program.

When you erase an EEPROM it sets the cells to 0xFF. When you write a byte to a cell any 0 bits are set to 0 and the 1 bits are left alone.
0xFF is the normal erased state for most EEPROMs.

They're all set to 0xFF by default.

On what authority do you rest this claim?

Having read unset EEPROM on several of the chips when new.  I know it is true at least for the 328, 1284, and 2560.  Having heard the same from many others who have seen the same.  Why are you seeing something different?

Read it how?  Some methods would likely have pre-erased before you could do so.  But even with one that couldn't, there's a big difference between observations of typical values of unspecified aspects, vs those which are actually specified by the manufacturer.

Ok sure.  Do you know what they are preloaded with?  I've heard the 0xFF from enough people in enough places to believe it beyond my own observations.  Do we have any reason to believe otherwise?  Do you have any documentation saying that it isn't?   What makes you think my method isn't sound?  avrdude doesn't erase the eeprom the way I normally use it.  I know this because I can load a sketch that writes in configuration values and the load another new sketch that uses them and they're still there.  And my code actually tests for 0xFF to determine if the configuration values have been written


text:
The Wire library and an ATTiny88 MCU
This is the MCU: http://www.microchip.com/wwwproducts/en/ATtiny88 - it advertises a hardware I2C interface, but I am struggling with it. It is mounted on my own board (which worked fine if I dropped an ATMega instead).
edited - prev screencapture were from an ungrounded logic analyzer
First tried the Femtocow ATTiny - it has complained about no Wire library at the #include Wire.h line. So i went into C:\Program Files\Arduino\hardware\arduino\avr\libraries, grabbed the Wire folder and copied it into C:\Program Files\Arduino\libraries. Compiled fine, loaded the binary with avrdude, got a few first TWI communication fine, then it started trashing.
Second attempt was with the cores from Drazzy ATTinycore which came with its own Wire library. Compiled fine, loaded the binary and got the same behaviour.
This is how the messed up I2C line looks in both cases. Starts fine, then appears to go wonky, after a few of these wonky bursts the lines go silent. Also, in spite of having changed the frequency to both 100 and 400 kHz i have this weird 1.953 kHz clock...
#define F_TWI             400000L
//#define F_TWI             100000L

....

  Wire.begin(); // Initiate the Wire library
  Wire.setClock(F_TWI);

I am using Arduino 1.8.2. Anything gives ?

Circuit or wiring? And pullup resistors?

It is a PCB, equipped with two 3k3 pullups

These implementations are only partially in hardware - while software doesn't twiddle the bits, it has to poke the hardware for each edge.  The invalid SDA transitions may well be caused by an analog issue - try smaller (stronger) pullups, make sure no peripheral is loading the bus, ideally look with a scope not a logic analyzer.

@ChrisStratton I am afraid i am not so advanced to posses an oscilloscope :) What values did you have in mind ? Maybe some 470 Ohm ? The rail is 3.3 V

Just tried the 470 Ohms, same outcome. I don't suppose this could be a bad PCB since there is the exact same behaviour on each attempt. Maybe I ought to replace the MCU...

It's very unlikely to be bad silicon

My issue has ultimately come from some memory differences between the ATTiny88 and the ATMega88 - the latter has twice as much SRAM - 1 kB. There normally have not been any warnings on this running out of RAM issue except for once - can't recall how but Arduino IDE did warn.
However, until I got to the bottom of it there have been some digging that had to be done. Like getting used to the programmer either working as expected, or erroring and failing, or erroring and not failing. Then there are the, sometimes changing, folders into which Arduino IDE outputs its files. Also there are non-working board configurations causing the used Wire libraries to issue read and write requests followed by just a NAK. Oh, and not to forget about the messed up signals - turns out they weren't messed up, just the logic analyzer was.


text:
How to wire and use a B10K linear LED potentiometer?
I've bought some nice looking LED potentiometers from Ebay. They look like this.
I'm very new to low level electronics/hardware and I don't know how to wire it. It has 4+2 pins.
Also, how to use it in the Arduino?

Can't tell.  You need to use a DMM to discover which pins are which. Then https://www.arduino.cc/en/Tutorial/AnalogInput

The Taiwan Alpha spec sheet page 2 for this type of pot shows a little information about the pinout.  Refer to the second “P.C.B. MOUNTING HOLE DETAIL” diagram, which apparently shows the top side PCB layout.  The LED's anode is at lower right, marked B; its cathode is lower left, marked E.  It doesn't say what L (the pin next to E) is.  The three numbered pins most probably are: 1 and 3, ends of the resistive element.  2, wiper.
If that is correct, you could attach pin 1 to 5V, pin 3 to ground, and pin 2 to an analog input.  Before hooking it up like that, however, take ohmmeter readings from pin 1 to pin 2 as you move the slider from one end to the other and see if readings change proportionately to position.
Note, the phrase “Center Dent” on the ebay page probably should instead be “Center Detent” or  “Center Click”.


text:
Problems with serial communication from Arduino to ESP8266
I've been trying to get an Arduino and ESP8266 to communicate with each other over serial. The ESP8266 uses the Serial class for communications, while the Arduino uses SoftwareSerial.
The problem is that when I try to send data from the Arduino to the ESP8266,  only the first character of the string sent gets received by the ESP8266. For example, if I send a string "leather", the ESP8266 only receives an 'l'. Both devices are operating at 38400 baud, although I have tried 9600 baud with similar results (apparently SoftwareSerial is more reliable at lower baud rates).
Here is the relevant code that's running on both devices:
Arduino code:
#include <stdlib.h>
#include <SoftwareSerial.h>

#define COMMAND_TILT                'c'
#define SOFTWARE_SERIAL_BAUD_RATE   38400
#define ESP_RX                      8
#define ESP_TX                      9

SoftwareSerial esp(ESP_RX, ESP_TX);

void setup()
{
    ...
    esp.begin(SOFTWARE_SERIAL_BAUD_RATE);
    ...
}

void loop()
{
   if (esp.available() > 0) {
        String data;
        while (esp.available() > 0) {
            data += (char) esp.read();
        }

        char command = data.charAt(0);
        data.remove(0, 1);
        int value = data.toInt();
        char buf[STR_BUF_LEN];

        switch (command) {
             case COMMAND_TILT:
                 ...
                 sprintf(buf, "%c%d", COMMAND_TILT, value);
                 esp.write(buf);
                 break;
             ...
        }
    }

    delay(100);
}

...

ESP8266 code:
#define SERIAL_BAUD_RATE 38400

void setup()
{
    ...
    Serial.begin(SERIAL_BAUD_RATE);
    ...
}

void loop()
{
    ...

    if (Serial.available() > 0) {
        String data;
        while (Serial.available() > 0) {
            data += (char) Serial.read();
        }

        char command = data.charAt(0);
        data.remove(0, 1);

        // problem: now, data.c_str() is blank when it should contain an integer in string format

        ...

        delay(100);
    }
}

...

If it helps to know, I'm running an MQTT client on the ESP8266 and controlling some steppers and relays on the Arduino.

use SoftwareSerial at 9600 baud. not more

@Juraj if you read the bottom of my questions it says I tried 9600 baud. Unfortunately no difference.

why do you thing that data will be available without a gap?

Strangely I am able to send data from the ESP to the Arduino in two separate write() calls and still get it in one piece on the Arduino side. But even if I send the data in one buffer the other way around, the ESP only gets the first character. For any gaps in data, shouldn't the Serial.available() calls take care of things? Or do you mean something else entirely?

Serial.available() returns the count of bytes in RX buffer. but at 9600 baud the bytes are coming very slow

you can use the blocking functions readString or readBytes, but it would be better to know the terminator char. https://www.arduino.cc/reference/en/language/functions/communication/serial/

The cause of the issue was that the ESP was reading chars too quickly, meaning that it would give up before the next char could be sent from the Arduino. To fix the issue I simply added a 10 ms delay between each Serial.read() call on the ESP.

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


text:
ESP-8266 stopped working due to possibly faulty perfboard layout
I have been following this tutorial to set up my ESP8266. I have also recreated on a perfboard the circuit provided in the tutorial, and I intend to use this perfboard circuit in my project.
The problem arises when I plug my ESP into the perfboard and try to talk to it through the serial monitor. When using a baud rate of 115200, the ESP responds to commands but in a garbled format. Also, the blue LED stays on after powerup for increasingly long periods of time. Now the blue LED is always on and the ESP no longer responds to any commands, except when reset and asked for the startup firmware info. I suspect that the ESP is now broken but am not sure how to check.
Also note that the ESP was working fine on a breadboard at 9600 baud, prior to the blue LED incident. Now it won't work with the breadboard either.
All commands were sent with newline and carriage return.
Is the ESP8266 broken? Could there be something wrong with my perfboard circuit? The circuit is rather dense and contains wiring for several other components in addition to the ESP-8266.

most ESP8266's default baud rate is the non standard 74880 (which is 115200 * 26 / 40)

@JaromandaX when serial monitor is set to 74880 baud the "boot message" shows up when resetting the board. However I'm unable to get a response from any commands sent to the board, at any baud rate.

It turns out the real culprit was the AT+IPR=9600 command bricking the board. The board was "fixed" by obtaining the firmware and flashing it to the board using esptool.py. Download the repo's source code, navigate to the directory bin/at/, and see the file README.md to see which addresses to flash the different parts to.


text:
Send Newline / Carriage return with python
With the Serial Monitor I have the Newline option:

How can I send the same using python?
I tried:

30\r\n
30\r
30\n

import serial

ser = serial.Serial('COM3', 115200)

while True:
    numIn = input("enter delay value: ")
    ser.write(numIn.encode('ascii'))

You tried them and they didnt work? ser.write((numIn + '\r').encode())? How are you checking this?

Thanks, this (numIn + '\r\n') works. Typing \r\n does not for some reason.


text:
Badly formatted characters using JDY-30 bluetooth module
I have a JDY-30 bluetooth module and have it wired like this (except using an Arduino Uno):
It is working, but I need to use it with a 115200 baud rate instead of the default one of 9600.
I also got that working.
Here is the code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial (2, 3); // RX, TX

// state | RXD | TXD | GND | VCC | EN

void setup () {
  mySerial.begin(115200);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
}

void loop() {

  while (mySerial.available()) {
    delay(10);
    Serial.write(mySerial.read());
    delay(10);
  }

  while (Serial.available()) {
    mySerial.write(Serial.read());
  }

}

But when I type things I often get badly formatted characters.
Some examples:

16:32:33.212 -> +VERSION=Firmware V3.0.6,Bluetooth V4.0 L⸮
16:32:38.990 -> +VERSION=Firmware V3.0.6,Bluetooth V4.0 LE

more:

16:33:27.144 -> +NAME=CC61-A
16:33:30.054 -> +NAME=CC41-A

If I also use 115200 baud rate for the Arduino, then it gets really worse.
Is there a solution for this?
See more about the JDY-30 here:
http://myosuploads3.banggood.com/products/20181203/20181203214419JDY-30-SPP-Bluetooth-Module.pdf

It is impossible to reliably receive using SoftwareSerial at 115200 baud. The UNO is just too slow for that.

Also the 3.3V logic of the bluetooth unit is right on the HIGH threshold of the 5V logic of the Arduino. There is little margin for error, which makes it very prone to noise.

@Majenko what about writing, is that reliable? I don't care so much for the reading.

Writing is fine, yes. The Arduino is in control of the flow in that situation, so speed is less critical.

As @Majenko pointed out:

It is impossible to reliably receive using SoftwareSerial at 115200
  baud. The UNO is just too slow for that.

I got results that where a lot better by first making a string when reading and then once we have a string send that. Instead of sending what we read all the time.
For example, when I tried AT+VERSION now it took me 16 attempts to get a wrong one, and only one character out of 42 was wrong that time.
#include <SoftwareSerial.h>

SoftwareSerial mySerial (2, 3); // RX, TX

// state | RXD | TXD | GND | VCC | EN

void setup () {
  mySerial.begin(115200);
  Serial.begin(115200);
  Serial.println("Enter AT commands:");
}

void loop() {

  String input_string = "";

  while (mySerial.available()) {
    input_string += (char)mySerial.read();
  }

  if (input_string != "") {
    Serial.write(input_string.c_str());
  }

  while (Serial.available()) {
    mySerial.write(Serial.read());
  }

}


text:
Read Arduino code generated by Simulink
I am trying to do a Hardware-in-the-loop (HIL) system with Arduino and Simulink but the driver of my motor (Pololu VNH5019) works at 20kHz and simulink PWM block only supports 490Hz.
I would like to read and modify the code before it is sent to the Arduino to modify this and add other libraries.
It would be that possible?
If it is not possible, there is any other visual environment (with blocs, like simulink or Xcos) to generate Arduino Code?

Simulink just supplies code for all the things you could be up to, triggered by a serial command of yours. This is very slow and I think it's obvious, that you would want a fast and slim realization of everything possible, if you attempt to do HIL.
If there is a special part you think is only easy for you with blocks, just ask right away, but it is really easy to do everything you can wish for in a few simple lines.
Also this is better for you, because you really know, what's going on.
I could provide some detail code, since I'm doing HIL myself atm, but you would need to specify a bit, what you are up to.
To really answer your question: I don't know of any other visual programming tool for arduino and as stated above, my best knowledge is, that simulink uses pretty messy things. And loads them onto the board right away, right?

Thanks a lot, the thing is that I am developig fast HIL protyping systems.

Thanks a lot, the thing is that I am developing  HIL rapid protyping systems. For do that I am using Scilab/Xcos that provide me a serial monitor of my system in real time, about 8ms, with that i can monitor and create models of my plants to introduce controllers. Simulink is only for ensure that you can do all the project in a easy way, without programming anything. Once that you have your models and your prototype ready you start to write the code and polish it. If you didn't undertood me let me know and I will show you the projects that I am currently doing.

Simulink most definitely supports higher PWM frequencies than 490Hz. I know because I have used it to generate PWMs in the 20kHz range on microcontroller boards. I suggest you post more details or screenshots of your work. Have someone help you determine where you are going wrong.


text:
How to read bytearray from arduino pin in arduino sketch
I'm using the DYP-ME007TX sensor with arduino uno.
The output from this sensor comes in packets of 4-bytes:
Data[0]= 0xFF: Packet Header
Data[1]= 0x0-0xFF: Data Most Significant Byte (MSB)
Data[2]= 0x0-0xFF: Data Least Significant Byte (LSB)
Data[3]= 0x0-0xFF: Data Checksum: = (0XFF + MSB + LSB) & 0xFF

Data is in MILLIMETERS
16 bit value in mm = Data[1] << 8 | Data[2]
How can exctract this packet in arduino sketch and extract millimeter number?

This is a serial data stream. Connect the device's OUT to your Arduino's RX, then read the documentation on the Serial library.

I want to use two and more this kind of sensors, so I think I just can't use Arduino's TX. I used SoftwareSerial library: http://www.arduino.cc/en/Tutorial/TwoPortReceive

I found the answer from forum.arduino.cc
There is a sketch
#include <SoftwareSerial.h>

// TX_PIN is not used by the sensor, since that the it only transmits!
#define PING_RX_PIN 6
#define PING_TX_PIN 7

SoftwareSerial mySerial(PING_RX_PIN, PING_TX_PIN);

long inches = 0, mili = 0;
byte mybuffer[4] = {0};
byte bitpos = 0;

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

  mySerial.begin(9600);
}

void loop() {
  bitpos = 0;
  while (mySerial.available()) {
    // the first byte is ALWAYS 0xFF and I'm not using the checksum (last byte)
    // if your print the mySerial.read() data as HEX until it is not available, you will get several measures for the distance (FF-XX-XX-XX-FF-YY-YY-YY-FF-...). I think that is some kind of internal buffer, so I'm only considering the first 4 bytes in the sequence (which I hope that are the most recent! :D )
    if (bitpos < 4) {
      mybuffer[bitpos++] = mySerial.read();
    } else break;
  }
  mySerial.flush(); // discard older values in the next read

  mili = mybuffer[1]<<8 | mybuffer[2]; // 0x-- : 0xb3b2 : 0xb1b0 : 0x--
  Serial.print("PING: ");
  Serial.print(mili/10);
  Serial.println("sm");
  delay(500);
}


text:
problem on implementation of the ultrasonic circuitry
I used an Arduino Uno on my project to produce a frequency greater than 35000Hz and the output of digital pin was connected to the ultrasonic transmitter circuitry:

However, it's not working on the transmitting side. Here's the Arduino code:
void setup()
{
    Serial.begin(9600);
}

void loop()
{
    pinMode(13,OUTPUT);
    pinMode(12,OUTPUT);
    int pirSenses = analogRead(A1);
    int pirOuts=11;
    pinMode(pirOuts,INPUT); /*PIR sensor 1*/
    int pirSense = analogRead(A0);
    int pirOut = 10;
    pinMode(pirOut,INPUT); /*PIR sensor 2*/
    Serial.println(pirSense);Serial.println(pirSenses);

    if (pirOut || pirOuts == HIGH)
    { /*tone produces ultrasonic frequency*/
        delay(8000);
        tone(13, 50132); delay(100); noTone(13); delay(10);
        tone(13,54621);  delay(50);  noTone(13); delay(50);
        tone(13,35689);  delay(60);  noTone(13);
    }
    else if (pirOut||pirOuts==LOW)
    {
        tone(13, 50132); delay(100); noTone(13); delay(10);
        tone(13,54621);  delay(50);  noTone(13); delay(50);
        tone(13,35689);  delay(60);  noTone(13);
    }
    else
    {}
}

And the transmitter (model "MCPCT-G5100-4139") specification:

Please help me with this problem. Thanks!

How do you know it's not working. First try it with an audible frequency.

You have at most a tiny burst of attempt after more than 8 seconds of other operations and delay.  First make it transmit continuously, and either use a scope or check at audio frequency as Gerben suggested.

The circuit diagram shows pin 3 but your code uses pin 13 - have you wired it correctly? The code in general makes little to no sense - check it's working with the following: void setup() { pinMode(13, OUTPUT); tone(13, 10000); } void loop() {}.

Your ultrasonic Transducer driver circuit isn't doing a very good job. At most you are getting only a few milliwatts output to the transducer. Your circuit is applying 12 volts through a 2.2K resistor to the transducer, and your Q1 transistor is merely shorting out the Transducer.
From viewing the data sheet on your transducer, it looks like a tiny loud speaker and not a Piezo device. But that is OK.
Try the following push pull driver circuit.  I have tried to keep it simple, but you would need to come up with a PNP transistor (in addition to your existing NPN transistor).
The V2 square wave is your 5 volt output from Arduino.
Also, notice that I have shown the driver circuit using 5 volts, not 12 volts. Using this circuit, if you use 12 volts supply, the output doesn't get any more powerful, and just causes more heating in the transistors.
EDIT 1  :  IMPORTANT :  Don't leave your output pin in the HIGH state.  This turns on transistor Q1 and causes sustained current in the Transducer.  To alleviate this, insert a 47uf capacitor in series with the transducer.
EDIT 2 :  Changed schematic to include output capacitor.

What kind of capacitor should I use for this? Electrolytic or polarize capacitor?

You can use electrolytic. Connect the positive to the transistors emitter.

what is the function of the 47uF capacitor? do this capacitor function as a high pass filter? thanks

To block DC from your transducer.


text:
Cannot upload sketch to Atmega328p TQFP soldered on PCB
After creating a working prototype with DIP ATMega328 chip/ Arduino UNO I recently got PCBs assembled with SMD components and ATMega328P TQFP soldered onto them, but now I'm having a hard time trying to upload the Arduino program.
This is the schematic of the PCB with ATMega328P TQFP with ISP headers for programming:

I'm using USBasp programmer with upgraded firmware to upload the code. The chip gets detected and also I can upload sketches to it but the problem is the code runs slow, which I found out is due to the default 8MHz internal clock.(the blink program makes LED blink every 16 seconds instead of 1 second,i.e. with delay(1000))
Now to switch to the external 16MHz clock which I want to use I found out here that I have to change the fuse values from the default

lfuse: 0x62   hfuse: 0xD9   efuse: 0x3F

to

lfuse: 0xFF   hfuse: 0xDE   efuse: 0x05

I tried it two times and both the times it screwed up the ATMega328P chip
C:\Users\p>avrdude -p m328p -c usbasp -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efu
se:w:0x05:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x1e950f
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xDE"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDE:
avrdude: load data hfuse data from input file 0xDE:
avrdude: input file 0xDE contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0x05"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x05:
avrdude: load data efuse data from input file 0x05:
avrdude: input file 0x05 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

C:\Users\p>avrdude -p m328p -c usbasp

avrdude: error: programm enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

Both of the PCBs are not responding to the USBasp programmer and now I have only got one PCB left. I desperately want to get the final one working.
This is my first time using the SMD ATMega328P chips and any help would be appreciated.

You should connect AVcc to a supply voltage. According to the datasheet AVcc has a minimum requirement of Vcc - 0.5 V. Also put a 0.1 µF decoupling capacitor between AVcc and Gnd.

It looks like the capacitors on your crystal are considerably bigger than they should be.
You are switching the clock to the external crystal, and because you have such massive capacitors on it it's failing to oscillate.  Without that oscillation the chip can't run, and so it can't respond to the programming.
The crystal capacitors should be roughly 2x the "load capacitance" of the crystal you are using.

CX1 = CX2 = 2(CL - CSTRAY)

Is there a value for capacitance you can suggest?

Use the formula I stated and insert the load capacitance of your crystal.  You can most likely ignore the stray capacitance as it should be tiny. Without knowing what crystal you have I can't suggest a value.  It will be in the low 10s of picofarads though.

Got it, thanks,will let you know if it works

The arduino board uses 22pF.

@Gerben Which one? Most I have seen use ceramic oscillators.  Or are you on about the USB interface chip (32U4 or whatever it is on your version)?

I just looked at the schematic of the UNO SMD. They used 22pF on the ATMega8u2's crystal. But I don't know anything about crystals.

22pF is quite common since 11pF crystals are quite common.

Majenko is quite right, the value of 0.1 µF is far too high. I assume you have spare Arduinos lying around. You can force a clock signal onto XTAL1 by using a signal from my Bootloader Programmer. That would at least let you change the fuses. However your longer term solution is to replace the capacitors. 18 pF to 22 pF would be reasonable values to try.

Thanks everyone for the tips, I will change the caps and let you know the result!

As expected it worked with 22pF caps! Thank you every one


text:
Arduino pro mini (clone) @1Mhz target does not answer
Recently I have been experimenting with battery powered sensor (mySensors).
I created node with 3.3V Arduino Pro Mini (ATMega328P @ 8Mhz with nordic radio chip and BME280 sensor) and successfully programed it many times using either USBAsp programmer or serial (to USB) programmer.
I wanted to lower power consumption and so I disconnected power led and burned fuses as follows:
lfuse 62
hfuse DA
efuse 7
It worked successfully and I recompiled the sketch and upload it with USBasp.
I got an error that data cant be verified. It was late in the night so I jumped to Internet and googled it. In one forum I found, post (which I am unable to find again) that stated the he was able to upload sketch when he switched programmer to 5V. (Power was connected to Vcc)
I did that and it worked fine.
Than I tried to make change to sketch and upload it again (on 3,3V) and again got verification error so I unplugged programmer and switched back to 5V.
When I did that, the device stopped answering.
I regularly used this command to check that device responds and see fuses
avrdude.exe -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -cusbasp -Pusb

What i did

Checked wiring.
Tried program fuses on blank new arduino - worked (programmer is
fine)
Measured voltage ok
Measured current (its around 4mA, I see it as the board is not
sleeping and is actively doing something)
I noticed that when I issue command mentioned above the on board led
quickly lights up and then goes off again.
I tried to power it from raw, from Vcc and from Vcc on serial hader (picture).
I measured power on Vcc when connected to Raw pin and it reads 3.3V
so power regulator should be ok.
I used -B10 switch to averdude with no luck

My question is

Is it possible that I burned the ATMega chip?
Is it possible that I see target not answering because of USBAsp is unable to lower programming frequency? (warning: cannot set sck period. please check for usbasp firmware update.)

Please suggest if there is anything I can try before throwing it out.
Thank you.

EDIT 2017-01-07
I was able to brick another board.
I think that the programmer is the cause.
I tried to upload bootloader with fuses from arduino and it failed with verification error.
I was able to burn bootloader from command line after seting fuses and restarting the board.
When I tried to upload the program it I got
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x00 != 0x0c
avrdude: verification error; content mismatch

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: lfuse changed! Was 62, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: hfuse changed! Was da, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: efuse changed! Was 7, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: Fuses OK (H:07, E:DA, L:62)

I answered yes because in in earlier attempts it just froze.
Now the board is in same condition as the first one.
Is it possible to revive it?
Thanks.

Here is link to post that suggests that I may burned the arduino.Method #6: Apply >3.3V to the 3.3V Connector Pin rugged-circuits.com/10-ways-to-destroy-an-arduino. Strange thing is that it worked two maybe three times ok :-)

TL;DR if the AVR is running at 1Mhz you have to slow down the sleep of the USBasp. Use avrdude  -B10 .... to slow it down.

Ok, I need to solder jumper on USBAsp programmer. I will try in the evening and let you know.

That is another option. My solution is to just add -B10. Which seems easier than soldering to me.

I thought that USBAsp software must be upgraded to support this options, but it accepted -B10 and used 93750 Hz but result was still target doesn't answer.

You could try the jumper on the USBASP.

Ok I was able to brick another board using USBAsp programmer. I also solder the jumper with no effect. I updated the post, but dont know what to do. I dont want to brick any more boards :-). Should I look for another programmer?

What was the command you used to set the fuses? You can also lower the speed in software. I've had similar problems every now and then. Sometimes the -B10 didn't work. Sometimes only the jumper worked. Sometimes nothing worked, and then all of a sudden It did work. I'm still not sure what was going on.

@gaben I used avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cusbasp -Pusb -e -Ulock:w:0x3F:m -Uefuse:w:0x07:m -Uhfuse:w:0xDA:m -Ulfuse:w:0x62:m. Do you think its fault of USBAsp? I was combining -P200, jjumper and it sometimes work sometime didnt and twice it bricked my board. Really dont know what is the problem.

Those are more sensible fuse setting then in the other post. Not sure what the -P flag does.

I am closing this thread.
The board is probably not destroyed, more likely are fused corrupted.
There are ways of reviving ATMega328 chip and program fuses back its called high voltage programming. You need to probably unsolder the chip or modify your board (post from tontrack).
Also if you are wondering what to do or not to your Arduino board here is quite interesting page (you wil find it in comment).
I did not found a way how it could have happen but it did.
Anyway Iam done with UsbAsp programmer and ordered AVR pocket programmer. Until it arrives I stop any more attempts.
Hope this helps somebody.

How to destroy your Arduino https://www.rugged-circuits.com/10-ways-to-destroy-an-arduino/


text:
How can I make this code read a page every 10 seconds?
I got problems with the code and I have used most of today, trying to find a solution and it's starting to drive my crazy. I hope one of you guys will be able to help me out.
I need the code to check a specific page every 10 seconds, single character.
This is what I have now, working code:
Where should I start?
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 104 };
char server[] = "billigefittings.dk";

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println(Ethernet.localIP());
  Serial.println();

  Serial.println("connecting ...");

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /lan.php");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if(client.available() > 0) {

    char c = client.read();

    Serial.print("page value:");
    Serial.println(c);

    if(c == '1') {
        digitalWrite(8, HIGH);
        Serial.println("8 HIGH ...");
        delay(5000);
        digitalWrite(8, LOW);
        Serial.println("8 LOW ...");
    }else{
        Serial.println("page value does not match '1' !");
    }

    // The code above should run even 10 seconds

  }

  if(!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;);
  }

}

Update: Edit the loop like the example below does not work either, it stops after the first loop (8 LOW):
void loop()
{
  if(client.available() > 0) {

    char c = client.read();

    Serial.print("page value:");
    Serial.println(c);

    if(c == '1') {
        digitalWrite(8, HIGH);
        Serial.println("8 HIGH ...");
        delay(5000);
        digitalWrite(8, LOW);
        Serial.println("8 LOW ...");
    }else{
        Serial.println("page value does not match '1' !");
    }

    delay(5000);

    // The code above should run even 10 seconds

  }

}

What aspect of it is causing you difficulty? Where to start is moving most of it into the loop(), and pausing for 10s after you've done it.

I tried that, but it does not work. Nothing happens after the first loop, even when I remove the client.stop() part.

You need to connect to the server (client.connect...) and disconnect (client.stop();) each time round.  More generally, try to understand the problem: it isn't true that "nothing happens" - something happens, just not what you want. If you could understand what in fact happens, you'd be closer to understanding why.  You can put trace (serial.prinln()) in, find out where it's going wrong.

As discussed in the comments, you need to connect to the client each time, not just once.
Here's my modified version of your code, which I hope will work -- I'm not set up to test it.
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 104 };
char server[] = "billigefittings.dk";

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println(Ethernet.localIP());
  Serial.println();
}

void loop()
{
  // Connect to the server
  Serial.println("connecting ...");

  EthernetClient client;
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /lan.php");
    client.println();
  } else {
    Serial.println("connection failed");
  }

  // Wait a moment for data to arrive
  // Note: This is NOT a reliable way of doing it!
  delay(1000);

  if(client.available() > 0) {
    char c = client.read();

    Serial.print("page value:");
    Serial.println(c);

    if(c == '1') {
        digitalWrite(8, HIGH);
        Serial.println("8 HIGH ...");
        delay(5000);
        digitalWrite(8, LOW);
        Serial.println("8 LOW ...");
    }else{
        Serial.println("page value does not match '1' !");
    }
  }

  // Disconnect the client
  if(client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // Wait another 9s, which will give us a delay of roughly 10s
  delay(9000);
}

That worked perfectly, will keep in mind that you need to connect upon each try - you saved my day! thank's a lot.

Glad to hear it was helpful!

Got a small question related to your answer. It seems you got quite a lot of knowledge about coding this stuff. Do I need to flush cache, or something, in the code above? It's supposed to run months without stop.

No, I can't see anything there which needs maintenance. The only thing that feels dodgy is that when we connect we wait 1s for data, and if there isn't any, we abandon ship.  That'll probably work most of the time, but what if just occasionally the server is under high load, or your network is laggy or whatever? It'll appear to have failed.  Browsers have much longer timeouts than this.  How to deal with depends on what you're trying to achieve.

Hmm... we have 3 machines each with an arduino. Each arduino check a file to see if a value, matching the machine, is active. If the value is active, then the arduino will power a motor for a short period of time. Each of the machines does this separately, checking a file every 10 seconds.

What do you want to happen if the network is (temporarily?) slow? Would you rather it wait (how long?) or is "slow" equivalent to "not working" for the think you're trying to achieve?

Thats a very good questions. Maybe add a 30 seconds timer, do a GET request to a php page with some info, so I can store some details about the delay in a database for tracking. Is it possible to add a timeout to Arduino and do a GET request to a php page? (e.g. domain.com/machine.php?status=err_delay&machine_id=3)... I need to think this over, have a feeling this will be quite important. Thanks for bringing it up :)


text:
How can I open simultaneously 2 client socket connections with GSM shield?
How can I open simultaneously two socket connections with a GSM shield?
It seems that when I try to open the second connection, it is not opened, and additionally the first connection is closed.
Code:
#include <GSM.h>

#define PINNUMBER      ""
#define GPRS_APN       "sm2ms.movilforum.es"
#define GPRS_LOGIN     ""
#define GPRS_PASSWORD  ""

#define SERVER "www.abv.bg"    // some server
#define PORT   80              // some port

static GSM gsm;
static GPRS gprs;
static GSMClient clientControl;    // first connection
static GSMClient clientData;       // second connection

void setup()
{
    // initialize serial communications
    Serial.begin(9600);

    Serial.println("GSM not initialized");

    while (true)
    {
        if (gsm.begin(PINNUMBER) == GSM_READY)
        {
            Serial.println("GSM initialized");

            while (true)
            {
                GSM3_NetworkStatus_t eErrorCode;

                delay(1000);

                eErrorCode = gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD);
                if (eErrorCode == GPRS_READY)
                {
                    Serial.println("GPRS initialized");

                    return;
                }
                Serial.print("Not connected to GPRS, error code = ");
                Serial.println(eErrorCode, 1);
            }
        }

        Serial.println("Not connected to GSM");
        delay(1000);
    }
}

void loop()
{
    delay(1000);

    Serial.println((clientControl.connect(SERVER, PORT))
                   ? ("Connected") : ("Couldn't connect"));

    delay(1000);

    Serial.println((clientData.connect(SERVER, PORT))
                   ? ("Second connection succeeded")
                   : ("Second connection failed"));

    Serial.println("Do something here");

    // close the stuff here!!!
    for (;;);
}

The serial dumps:
GSM not initialized
GSM initialized
GPRS initialized
Connected
Second connection failed
Do something here

With other clients I don't have problem supporting two simultaneous connections. Here the first connection succeeds, the second fails.
Regards,
Boyan

Could you post the code you are using to create the connections?

Additionally, it seems to not matter which exactly the server is. The same happens also with other active servers/ports.

It seems like you cannot open a new one because it is already open, you either need to make a new instance or close the old first.

First, clientControl and clientData are already two different instances. Secondly, I cannot close the control connection. I need them both open simultaneously. If I close the control connection, everything will end. If I don't open data connection, I cannot send data. Therefore I need them both.

Could you give us a copy paste of the serial log ?

Serial log added.


text:
build fixed size strings from floats
This is likely a duplicate, but I couldn't find the original question. This is really basic, but just can't figure it out.
I'm trying to combine a few char arrays together. This is what I've tried so far.
float a = 12.3456;
float b = 5.4321;
bool c = true;

char a_string[4];
dtostrf(a, 4, 1, a_string);

char b_string[4];
dtostrf(b, 4, 1, b_string);

char c_string[2] = {'0', '\0'};
if (c) {
  c_string[0] = '1';
}

char output[12] = "-----------";

output[0] = a_string[0];
output[1] = a_string[1];
output[2] = a_string[2];
output[3] = a_string[3];

output[4] = ' ';

output[5] = b_string[0];
output[6] = b_string[1];
output[7] = b_string[2];
output[8] = b_string[3];

output[9] = ' ';

output[10] = c_string[0];

Serial.println(output);

Results in an empty string in seems.
If I remove the second dtostrf(), and change b_string[0] ... to a_string[0] Then I get 12.3 12.3 1. Doesn't seem to like having dtostrf() called more than once, but it seems like the function I want, since it allows me to set a fixed strint size. The output I'd be looking for is 12.3  5.4 1
another approach
String a_string = String(a, 1);
String b_string = String(b, 1);
String c_string = String(c);

String output;
String space = " ";

output.concat(a_string);
output.concat(space);
output.concat(b_string);
output.concat(space);
output.concat(c_string);

Serial.println(output);

This outputs 12.3 5.4 1. Is there a way to make the String fixed width? I'm looking for
12.3  5.4 1 instead of
12.3 5.4 1
What's the proper way of doing this?
EDIT

After trying to use the @Majenko's answer I sometimes get garbage values printed. Any ideas why?
float a = analogRead(A1) / 1023.;
float b = analogRead(A2) / 1023.;
bool c = analogRead(A3) / 1023;

char* output = createString(a, b, c);
Serial.println(output);

char* createString (float _a, float _b, bool _c)
{
    char a_string[5];
    dtostrf(_a, 4, 1, a_string);

    char b_string[5];
    dtostrf(_b, 4, 1, b_string);

    char out[12];
    snprintf(out, 12, "%4s %4s %d", a_string, b_string, c ? 1 : 0);
    return out;
}

and the output:
 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.�tS
�
 0.6  `S
�
 0.6  1.0
}
 0.6  1.0 0
 0.7  1.0 0
 0.6  1.0 0
 0.6  1.0 0

using
  Serial.print(a_string);
  Serial.print(" ");
  Serial.print(b_string);
  Serial.print(" ");
  Serial.println(c);

doesn't produce the errors

Other than figuring out how long each string is or using *printf()?

The simple way would be to format the string with sprintf - however sprintf on the Arduino lacks floating point support (although it is possible to enable it).
So if you convert your floating point numbers into strings first (remember to provide room for the NULL terminating character!) you can then use sprintf to format those converted numbers into what you want:
float a = 12.3456;
float b = 5.4321;
bool c = true;

char a_string[5];
dtostrf(a, 4, 1, a_string);

char b_string[5];
dtostrf(b, 4, 1, b_string);

char out[12];

snprintf(out, 12, "%4s %4s %d", a_string, b_string, c ? 1 : 0);

%4s is replaced by a string which is padded to at least 4 characters wide. The padding is to the left of the string. If you want the padding to the right you can use %-4s instead.

Addendum:
In your new posted code you are making a fundamental error:
char out[12];
snprintf(out, 12, "%4s %4s %d", a_string, b_string, c ? 1 : 0);
return out;

out is a local variable to the function. Its memory is allocated on the stack. You fill that with data and then return the address of that location on the stack. As soon as you leave the function that memory allocation is lost. Yes, the data is still there, but the moment you call another function that memory gets overwritten with the call frame of the new function you have called - thus corrupting your data.
You have two main options:

Make out global
Make out static

The effect of the two options is pretty much the same, except that in the second option the scope of out is restricted to the function which means you can use the name out elsewhere without it conflicting. In both options though the memory allocated to out is in the BSS not the stack and thus won't get overwritten.

Thanks, that works great. When I try to use analogRead values for it though I sometimes get garbage. I updated by question. Any ideas?

See my addendum.


text:
How to read main code inside main code in Arduino?
How can I read the hex code of the main programme stored inside flash memory inside my running Arduino programme?
So far I am able to read the Flash at any given address by using PROGMEM
unsigned int displayInt;
int k;    // counter variable

void setup() {
  Serial.begin(9600);
  while (!Serial);  // wait for serial port to connect. Needed for native USB

  for(k = 0; k < 5; k++) {
    displayInt = pgm_read_word_near(k);
    Serial.println(displayInt);
  }
}

void loop() {
}

The output is
37900
13716
53
3072
37900

But this not hex code.
I am implementing the OTA (over the air) feature. I will get the new version of a code from GPRS. It will be huge code so I will write it to flash by using the custom bootloader mentioned in this thread. I am able to write to the flash memory. Now I would like to read the data from flash. To begin with I would like to read the main programme inside my main programme.

Interesting. If you want hex you have to tell it to print in hex. If I change your display line to:
Serial.println(displayInt, HEX);

Then I get:
940C
3594
35
C00
940C

Compare this to what the decompiled file looks like:
   0:   0c 94 35 00     jmp 0x6a    ; 0x6a <__ctors_end>
   4:   0c 94 5d 00     jmp 0xba    ; 0xba <__bad_interrupt>
   8:   0c 94 5d 00     jmp 0xba    ; 0xba <__bad_interrupt>

If you take the endianness into account (you are reading words, not bytes) then it is the same.

If you change it to read bytes it looks better:
void setup() {
  Serial.begin(115200);
  while (!Serial);  // wait for serial port to connect. Needed for native USB

  for(int k = 0; k < 12; k++) {
    byte c = pgm_read_byte(k);
    char buf [3];
    sprintf (buf, "%02X", c);
    Serial.println(buf);
  }
}

void loop() {
}

I increased the baud rate to 115200. I'm always puzzled when people use 9600 baud. Do you hanker for the olden days, when 9600 baud modems were the fastest you could get?
That gives this result:
0C
94
35
00
0C
94
5D
00
0C
94
5D
00

As you can see, it is exactly correct.

Thanks. I am a frontend web developer trying to learn all of it(firmware development) at once. I don't know C very well. Thanks


text:
rc522 RFID reader will only accept first tag after power up
I have an interesting problem using the Mifare rc522 device similar to http://www.ebay.com/itm/201415107836
I have this device connected to an arduino uno and drawing power from the 5V supply.
It reads cards and tags well.
Provided the card waved by it has previously been waved by it as the first card after power up.
It will recognise ALL the cards and tags I have with no problems but ONLY if each card has been at some time the FIRST card since the device was powered up.  Reset button does not help.  Once each card or tag has been used as the first after power up it will work every time thereafter.
I am using a very simple sketch which simply reads the RFID via serial link and then displays the data on an LCD.
Can anyone help explain this odd behaviour.
Is it something to do with the tags perhaps?
http://www.ebay.com/itm/201611365871 (bought from same seller who is, BTW very quick and cheap to mail parts)
I have tried running off a 12v supply (to the duino) and USB with same effect.  I have added a capacitor (47uf) across the power to the RFID - same issue.
/*
 Based on  LiquidCrystal Library - Hello World

 * LCD 4  RS pin to digital pin 12   Pin
 * LCD 6  Enable pin to digital pin 11
 * LCD 11 D4 pin to digital pin 5
 * LCD 12 D5 pin to digital pin 4
 * LCD 13 D6 pin to digital pin 3
 * LCD 14 D7 pin to digital pin 2
 * LCD  5 R/W pin to ground
 * LCD  1 VSS pin to ground
 * LCD  2 VCC pin to 5V

 */

// include the library code:
#include <LiquidCrystal.h>

char incomingByte = 0;
int cursorpos=0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int detonate=10;
int shownumber=0;
void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(24, 2);
  // Print a message to the LCD.
  lcd.print("Initialised");
  Serial.begin(115200);
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):

  lcd.autoscroll();
   if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = char(Serial.read());

                // say what you got:

                lcd.print (incomingByte, HEX);

        }

}

further edit:
I have now been able to get the thing to communicate using software serial - it seems to work out the baud rate quite well so despite the datasheet you are not limited to 115200 baud.  Still the same problem though as far as I can see it will now work with any 3 cards - any new card bumps one off the list of acceptables.  AAAARRRGGGGHHH
As requested, code change below - I basically lifted this directly off the arduino forum with changes only to make it work with an uno using software serial.  It does work, after a fashion but still the same problem with recognising only a few of the cards I have.
//emulate mega with software serial
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);

unsigned char command, devnull;
unsigned int returnLength;

void setup() {

Serial.begin(9600);
mySerial.listen();
  Serial.println("Waiting for Card\n");
mySerial.begin(9600);

  mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual

}

void loop() {
   if (mySerial.available())
    {
      Serial.print("\n\rCARD SERIAL: ");
      for (unsigned int i=0; i<4 ;i=i){
        //Serial.print("2");
        if (mySerial.available()) {
            //Serial.print("\n\ri is: ");Serial.print(i);Serial.print(" ");
            Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
            i++;
          }
        }

       Serial.println("\n\rRead Card Make...");
       mySerial.write(0xAB);mySerial.write(0x02);mySerial.write(0x01);

       Get_Reply();

       mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
    }

}void Get_Reply() {
       while (!mySerial.available());
       devnull = mySerial.read();
       while (!mySerial.available());
       returnLength = mySerial.read() - 1;

       for (unsigned int i=0;i< returnLength;i=i){
         //Serial.print("2");
         if (mySerial.available()) {
            //Serial.print("\n\ri is: ");Serial.print(i);Serial.print(" ");
            Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
            i++;
          }
        }
}

Please post the sketch. It might have an issue even if simple.

You could try to run some example sketches, to see if they have the same problem.

Thanks.  Added code as requested.  It's a head scratcher as there is no memory usage intended.

Can you try to send the in coming bytes to your PC via USB and possibly take out the LCD code? Or directly connect to the rfid-board using an USB-UART cable? It may be that the code is working just fine, but the cursor leaves your LCD screen or that the LCD gets stuck in some kind of loop.

It will recognise ALL the cards and tags I have with no problems but ONLY if each card has been at some time the FIRST card since the device was powered up. - sounds like a problem with the reader. Maybe you need to acknowledge that you have read the card, or something?

Thanks nick - was thinking along the same lines.  It reports a code for every tag every time but only if that tag has at some point been the first tag presented after power up.  I have thought it may be writing to the tags but there is very little info on this particular unit.  Should have bought a better one but have been enjoying the challenge.

I cannot use USB to get the info from an uno as the card reader uses the serial and requires 115200 baud which exceeds softwareserial capability.  I may try a mega, but that is overkill for all the projects I have in mind so I don't have one of those right now.

Update the code in your question.

My guess is that you have to do this in two steps, i.e. 1) read from mySerial to a buffer, 2) write to Serial.


text:
Any resources you know with regards to remotely reading data from arduino?
I am trying to implement arduino101 and my application needs to read data from the Arduino without a USB connection to my laptop. I appreciate you if you know any beginner-level tutorial for this.
Please let me know if you can't understand my question.

Just letting you know: I can't understand your question.

You can use the Bluetooth on the board, a Bluetooth dongle for your laptop if the laptop does not have bluetooth or you can buy a wifi shield.
The 101 has Bluetooth LE on the board.
You will find there is a Bluetooth -> Serial USB software, so the application on the laptop can still work the same way as when using the usb.
Here are the Bluetooth examples for the 101 on arduino.cc
https://www.arduino.cc/en/Reference/CurieBLE
and the user guide for the 101
https://www.arduino.cc/en/Guide/Arduino101


text:
Arduino Mega 2560 not recognized/overloaded
I pulled my Arduino set out of storage yesterday and was very upset to find that it is not working for some reason.  Before I explain the problem, let me explain the situation.
Hardware (all DFRobot):
Arduino Mega 2560
Arduino Mega 2560 4x-platform breakout board
GPIO Expansion Shield V1.0
I/O Expansion Shield V7.1
8 Channel 5V Relay Board
4 LED/Resistor set up
1 digital speaker
1 digital humidity/temperature tester
7 analog chemical air chemical testers
The whole project:

LED Portion:

Relay Portion:

Sensor Portion:

Pin Connections:

In this 4th photo, the two analog pin sets in use right in front are the ones I remove in order to gain control again.  if those are plugged in then it doesnt work.  It has nothing to do with those pins specifically, If I remove any two it works again, those ones are just easiest to remove to get it to work:

Explanation of project:
This is basically a test station, where I can hook up what ever I want and see how it works and then move onto another peripheral piece of hardware and make them interact.  I went with the 4x-platform breakout board as to maximize I/O space.  Once a project is done, I Velcro band them together as to not get them confused and move on.
Explanation of problem:
When I plugged the Arduino into my PC the first time, the lights came on the Arduino and then after about 15 seconds it powered down and the lights went off.  My PC did recognize it while it was powered up and the port option under tools in the Arduino IDE was available and I could select the port.  After the power down and problems I realized something must be up.
I considered the fact that maybe the Velcro was constricting the wires and causing them to short circuit through the rubber insulation, but couldn't find any info on that online.
After this I decided to cut the PC out of the equation and try just plugging it into the wall, 1st, via USB to 5V1A wall charger, it stayed on for a few seconds and then turned off, 2nd with a 5V2A wall charger, same scenario, 3rd via the barrel jack with the same wall chargers, with no success.
I undid all of the wire bundles to rule out a short circuit, which it did.  I then found out after much trial an error that if I removed any 2 of any analog or digital wires, the lights would stay on and it would work.
Now, with two cables removed so it did not lose power, I plugged it into my PC and am now able to program it again and see it in the port in the IDE, but as soon as I plug in another 2 analog or digital peripheral devices it will lose all power and stop working.
I also tried plugging my DFRobot Beetle micro-controller in with the same USB cable and it worked perfectly.  I also tried resetting the micro-controller, to no avail.
Conclusions so far:
A short between rubber insulation at 5v is extremely unlikely
one would think that if a mega board was designed to have so many I/O pins you could actually connect to all of them with out any problem.
Since this happened on both the PC and wall charger scenarios, and the problem seems to be associated when disconnecting any 2 sensors, the problem is most likely at the micro-controller level.
Questions:
are all the peripheral devices draining the board so much that the USB port on the PC or wall chargers cant handle it?
How do I provide enough power to the board if this is the problem?
Or is this simply faulty board?
If it is a faulty board, what causes this and how do you avoid it?
Just to clarify, looming the wires together into bundles is OK right?
Finally, any help would be really appreciated, this is the first time this has happened and it sucks.

Pics would be nice here.  Try using something like Gimp to resize the images you have so they are smaller.  You can also use a free image storage site and post links to them.

I was able to do it by print screening, hope that helps.

Thank you for the pics.  Thank helps, and yet it doesn't...  Soooo many wires!  :-)

Is that bad practice?  I honestly don't know, the plan was to fill all the pins eventually.

Actually, I was just poking a little fun at you.  Sorry if that didn't come across that way.  AFAIK, it's not bad practice, it just makes it hard to trace things down.  Having a lot of wires can lead to EMF across the wires, but twisting them or otherwise shielding them helps.  I built a CNC machine using an Arduino Mega and I have Waaaaay more wires than you do, so you're not alone.

ah haha ok, well thats good to know.

First off, that is one heck of a rig.  I'm impressed to the point of "I gotta get me one of those."
Bundling your wires shouldn't have the kind of impact you are seeing, unless there are bare wires touching.  You might get induction interference, but not a total shut down.
From what I can see here, it looks like there's so much stuff connected to the Arduino that it's probably starving it for power.  You should look into using power rails for Gnd and +5v.
You will also need to check if you are supplying it with enough amps, too.  Your computer's USB port only supplies 0.5A, unless it happens to be USB3, then it's 0.9A.  Even your 5V1A PSU might not be enough.  Consider finding a 2-5 amp wall wart to do some more testing with.  There are usually spec sheets with components, so you'll need to add all the power draw for all the components, including the Arduino, and make sure you have more than enough to meet that calculated power draw.  Exceeding it by at least 10-20% is usually considered good practice, even for a test rig.
Consider powering your rig's new power rails with the extra PSU even when the Arduino is plugged into your computer.  As long as you make sure you aren't trying to take power from the computer and the PSU at the same time with the same component, you should be fine.  (Don't cross the streams.)
There could be a short or feedback loop somewhere in your sensors that's causing the extra drain.  There are so many wires here that it'd be easy to hook up something backwards.  Along with the number of wires, the bundling doesn't let SE-us help you track that down.
You might want to look at the direction your pins are facing.  It was an odd situation for me, but having two of the metal clips facing each other was enough for a short.  In your "Relay Portion:" pic, they are all facing the same way, which is good.  See if there are places where that's not the case and fix it.  Like I said, it was an odd situation, but it's a phantom problem you can avoid.

Oh ya I love the DFRobot stuff, its really cool, I saw that Multi-platform shield and immediatly went for it.
So when you say use a power rail do you mean buy a separate wall PSU and run the power to a separate breadboard, then run all power from this breadboard.  Or do you mean wire the separate PSU directly into the shields via the screw terminals so that all the 5v/GND pins on the shield themselves are run off the external PSU?

You'll have to forgive me, as I'm a complete novice when it comes to actual power calculations.  So you're saying calculate out how many volts & amps each piece of hardware consumes and then find a power supply which will output what I need.  The volts wouldn't be part of that thought right?  Just for example, 22 devices at 5v each would need a full 110, that cant be right can it?  I just need to make sure that the PSU has enough AMPS to push all the power through, correct?

A power rail is pretty much anything that allows you to have 1 PSU power multiple things at once, without having to go through other components first.   The screw terminals might do the same thing.  https://images-na.ssl-images-amazon.com/images/I/41t0EVwnGoL.SX355.jpg

For power calculations, as long as they are all the same voltages, you can just add the amps together.  So, 5x components that use 5v @ 0.5A, you'll need 5v @ 2.5A to power it.  If you have another 2 components that are 12V @ 1A, then you'll need another PSU to supply 12V @ 2A.

Alright, the local electronics store (the only one) only had a 5V3A power supply.  I will try hooking it up with a multi-meter and see how many amps it draws tonight and try adding them up as well to see if it matches.  I'll try a breadboard first and then try the terminals after some more research.
The PSU he gave me has a barrel jack so just out of curiosity, is there anything explicitly wrong with using the external PSU in the barrel jack while using the USB for programming?  Or is the Micro-controller not smart enough to prioritize the better power source?

I use the barrel jack PSU and USB at the same time all the time.  It's designed to do just that, so you should be good to go there.  However, the Arduino is only capable of putting out 200mA from the power outputs and 40mA from the I/O pins. You'll still need to go to the screw terminals of the breakout board or a power rail to reach the components themselves.
https://electronics.stackexchange.com/questions/67092/how-much-current-can-i-draw-from-the-arduinos-pins

Alright, well I have my homework cut out for me, I'll get back to you on this.  If each pin can only output 40mA it seems odd that any of the devices would be made to pull more and require a power rail.  Lots to consider, thanks!

Let us continue this discussion in chat.


text:
Multiple if statements - stuck
I have a robot that uses two motors to skid steer. The robot gets input from three ultrasonic sensors (left, middle, and right) and a passive infrared sensor. If the robot detects a person in front of it, then it follows.
The sensors seem to work as they are intended. The infrared sensor sees a person and the ultrasonic sensors see that the person is between 65cm and 150cm and it follows. If the left ultrasonic sensor has the person in range, it turns left, and if the right ultrasonic sensor has the person in range, it turns right.
The problem is that the robot gets stuck turning left or turning right depending on which sensor it checks first in the code. It's like it's stuck in a while loop even though I'm not using a while loop.
I have adapted NewPing and library. The code in question is at the bottom in the last function. The rest is part of NewPing to read the ultrasonic sensors.
If anybody has any suggestions, it would be greatly appreciated.
#include <NewPing.h>

#define SONAR_NUM     3 // Number of sensors.
#define MAX_DISTANCE 170 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 35 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).

unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

NewPing sonar[SONAR_NUM] = {     // Sensor object array.
  NewPing(11, 4, MAX_DISTANCE), //Left -- Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(8, 3, MAX_DISTANCE),  //Center
  NewPing(7, 9, MAX_DISTANCE),  //Right
};

int ledR = 13;
int ledG = 2;
int ledB = A0;
int motorPinL = 5;
int motorPinR = 6;
int ePIR = 10;
boolean epirVal;

void setup() {
  Serial.begin(115200);
  pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
  pinMode (ledR, OUTPUT);
  pinMode (ledG, OUTPUT);
  pinMode (ledB, OUTPUT);
  pinMode (motorPinL, OUTPUT);
  pinMode (motorPinR, OUTPUT);
  pinMode (ePIR, INPUT);
}

void loop() {
  for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
      if (i == 0 && currentSensor == SONAR_NUM - 1)
        oneSensorCycle();                             // Sensor ping cycle complete, do something with the results.
      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
      currentSensor = i;                          // Sensor being accessed.
      cm[currentSensor] = 155;                      // Make distance 155 in case there's no ping echo for this sensor. changed from zero
      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
    }
  }
  // Other code that *DOESN'T* analyze ping results can go here.
}

void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}

void allStop () {
  analogWrite (motorPinL, 0);
  analogWrite (motorPinR, 0);
  digitalWrite (ledG, LOW);    //LED corresponding to right ultrasonic sensor
  digitalWrite (ledR, LOW);    //LED corresponding to left ultrasonic sensor
  digitalWrite (ledB, LOW);    //LED corresponding to center ultrasonic sensor
}

What exactly do you want it to do? Currently your top priority is to stop if any sensor is outside the range bracket or if epirVal is true. If epirVal is false and a sensor is in range you turn. If epirVal is false and no sensor is within range you keep doing whatever you were doing before.

@Andrew I want the robot to go straight if the middle sensor detects the person between 65cm and 150cm and the PIR sensor sees the person (when it sees a person epirVal == false because it's active low. If the right sensor sees the person in the same range and the epirVal is low, the robot turns right. If the left sensor sees the person in the same range and the epirVal is low, then it turns left. I had too many else if's in the last code. I have rewritten my code and the applicable part is the very last function. There is something very wrong with my logic. looking for help.

@Andrew  and btw it doesn't do anything with this current code. It just sits there.

Do not vandalise your post. This may result in a question ban. see question bans

Your logic is flawed. Translating your loop in pseudocode gives
something like this:
if (PIR does not detect OR ANY sonar is out of range) {  // cond. 1
    stop
} else if (PIR does detect AND right sonar is in range) {  // cond. 2
    turn right
} else if (PIR does detect AND left sonar is in range) {  // cond. 3
    turn left
} else if (PIR does detect AND center sonar is in range) {  // cond. 4
    go straight
}

Notice that, if condition 1 is false, then that means that the PIR does
detect AND ALL of the sonars are in range. Which implies that condition
2 is necessarily true. Which implies that the following elses have no
effect. Your code can then be optimized (and the compiler probably did
optimize it) into
if (ANY sonar is out of range OR PIR does not detect) {  // cond. 1
    stop
} else {  // cond. 2 is true if cond 1. is false
    turn right
}

You should rethink your problem asking yourself the following questions:

under what conditions should the robot turn right?
under what conditions should the robot turn left?
under what conditions should the robot go straight?
under what conditions should the robot stop?

Make sure that in any circumstance EXACTLY one of the above conditions
holds true. In other words, the conditions should be mutually exclusive
and cover every possibility. One you have the answers, the coding should
be straightforward.

Edit: Your updated code still contains logic flaws. For example, if
the PIR senses the person and BOTH the left and right sonars are in
range, then you are asking the robot to BOTH turn left and turn right.
Unless it's a quantum robot evolving in an Everett's multiverse, it
won't be able to comply. To the risk of repeating myself, you must
decide on one and only one action for every possible situation.
If you are struggling with that concept, I suggest you start by filling
the truth table below. On each of the 16 lines of the table you should
fill the last column with one (and only one) action among: allStop,
turnRight, turnLeft and straight. Yes, I know it's tedious to
consider all the possible situations one by one, but you must do that
before starting to write the code. Otherwise you end up with completely
broken logic.
+--------+----------+----------+----------+-----------+
| PIR    | sonar 0  | sonar 1  | sonar 2  |  robot    |
| senses | in range | in range | in range |  action   |
+--------+----------+----------+----------+-----------+
|  no    |   no     |   no     |   no     |           |
|  no    |   no     |   no     |   yes    |           |
|  no    |   no     |   yes    |   no     |           |
|  no    |   no     |   yes    |   yes    |           |
|  no    |   yes    |   no     |   no     |           |
|  no    |   yes    |   no     |   yes    |           |
|  no    |   yes    |   yes    |   no     |           |
|  no    |   yes    |   yes    |   yes    |           |
|  yes   |   no     |   no     |   no     |           |
|  yes   |   no     |   no     |   yes    |           |
|  yes   |   no     |   yes    |   no     |           |
|  yes   |   no     |   yes    |   yes    |           |
|  yes   |   yes    |   no     |   no     |           |
|  yes   |   yes    |   no     |   yes    |           |
|  yes   |   yes    |   yes    |   no     |           |
|  yes   |   yes    |   yes    |   yes    |           |
+--------+----------+----------+----------+-----------+

The pseudo-code above is what I want the robot to do. I just can't think how to make it mutually exclusive. I have been looking at your answer and thinking about this most of the day, and I don't know what the next step is. I know you say to rethink the problem and ask myself the questions, but I thought I already had it coded to do just exactly what your questions are. I'm not seeing the logic. Any hints to give me another step in the right direction?

You said, "Notice that, if condition 1 is false, then that means that the PIR does detect AND ALL of the sonars are in range. Which implies that condition 2 is necessarily true. Which implies that the following elses have no effect."  I feel like I'm missing something on the fundamental use of if...else if. Can you help?

@DanielShields: See the De Morgan's laws: NOT(NOT(PIR detects) OR NOT(sonar 0 in range) OR NOT(sonar 1 in range) OR NOT(sonar 2 in range)) = (PIR detects AND sonar 0 in range AND sonar 1 in range AND sonar 2 in range).

I'm not a philosopher or a professional programmer. Can you be a little more specific?

@ Edgar Bonet changed my code above. I now know that you can't have more than one else if statement so those were changed. I tried to think of every scenario and make the code mutually exclusive and cover every possibility. Per your suggestion. Now it does nothing except for the middle and left led flash really quickly.

@DanielShields: You don't need special qualifications to understand De Morgan's laws. They basically say that the negating “It's sunny AND cold.” yields “It's NOT sunny OR it's NOT cold.”. Since you seem to be struggling with logic, I updated my answer with a table for you to fill. Once you are done, you may be able to solve your problem all by yourself. If not, then add the filled table at the end of your question: we will then at least know what your program is intended to do.


text:
Where can I find the code for Arduino's "attachInterrupt"?
Where can I find the code for Arduino's attachInterrupt function?
A search on the Arduino's Github repo yielded nothing.
I suspect it might be a wrapper for some avr-libc function but nothing in the avr-libc docs stands out to me...

download a text editor like Notepad++  ..... you can then use it to search for text in folders (directories) ..... search for the text "attachInterrupt" in the arduino install directory .... it will find all files that contain that word   ..... get it here https://notepad-plus-plus.org/

It's in the core in WInterrupts.c
On my install it's at:
arduino-1.8.5/hardware/arduino/avr/cores/arduino/WInterrupts.c

Thank you! Never knew I could find these files in the install!

How could you compile them if they weren't there?

Online: https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/WInterrupts.c


text:
Modbus RTU controller monitoring with arduino and RS485 module
I'm a medium user in Arduino. I baught a pHmeter controller with RS485 output (MODBUS RTU protocol).
I want to get pH value read by the controller over RS485 module and Arduino.
According the controller's manufacturer, we should operate as bellow:
Sent by computer : 00 03 00 00 00 01 85 DB
Return from controller : 00 03 02 02 AE 05 58.

#include SoftwareSerial.h

#define SSerialRX        10  //Serial Receive pin
#define SSerialTX        11  //Serial Transmit pin
#define SSerialTxControl 3   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW
#define Pin13LED         13

SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
byte byteSend;

void setup()
{
  // Start the built-in serial port, probably to Serial Monitor
  Serial.begin(9600);
  Serial.println("SerialRemote");  // Can be ignored

  pinMode(Pin13LED, OUTPUT);
  pinMode(SSerialTxControl, OUTPUT);

  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver

  RS485Serial.begin(9600);
  delay(2000);
  digitalWrite(SSerialTxControl, RS485Transmit);
   RS485Serial.write((byte)0x00);
   RS485Serial.write((byte)0x03);
   RS485Serial.write((byte)0x00);
   RS485Serial.write((byte)0x00);
   RS485Serial.write((byte)0x00);
   RS485Serial.write((byte)0x01);
   RS485Serial.write((byte)0x85);
   RS485Serial.write((byte)0xDB);
   Serial.println(" ");

   digitalWrite(Pin13LED, LOW);
   delay(10);
   digitalWrite(SSerialTxControl, RS485Receive);

}
void loop()
{

  if (RS485Serial.available())
  {
    byteSend = RS485Serial.read();   // Read the byte
    Serial.print(byteSend, HEX);
    Serial.print(" ");
  }
}

I tried this following sketch who does not work.
I would like to know if it is the good way to send request to the controller?

add to question a wiring schema and complete sketch

Post update with wiring and complete sketch

If you ask if there is a better way to send the request, then yes there is. but it will not make it work. byte request[] = {0, 0x03, 0, 0, 0, 0x01, 0x85, 0xDB};  RS485Serial.write(request, sizeof(request));

Good, it's working well.

To send series of bytes over Serial or any other Stream (Print) implementation use the "write buffer" method size_t write(const uint8_t *buffer, size_t size)
For the case in question:
byte request[] = {0, 0x03, 0, 0, 0, 0x01, 0x85, 0xDB};
RS485Serial.write(request, sizeof(request));

If someone is curios about the Modbus RTU request bytes. They are:

station address
function - 0x03 Read Multiple Holding Registers
register address - 2 bytes
number of registers to read - 2 bytes
checksum - 2 bytes

The response:

station address return
function or error code
data length
data - length bytes
checksum - 2 bytes