text:
How can I fix stuttering motors that are connected to ESC's [Arduino Uno]?
Been making a few posts about my drone and i am getting closer and closer to my goal to make it work.
Right now I have a problem with stuttering with all four of my motors (sometimes the motors does not even start but they beep instead). This is the motor and esc I use: https://hobbyking.com/en_us/mt1806-brushless-combo-include-esc-5030cw-ccw.html
I put together a very quick schematic on how i have everything connected:

So motor connected to the ESC and the ESC grounds go to arduino Gnd, the signal pins from the ESC goes to different pwm pins and the rest of the esc goes to the power distribution where i also insert my 3s lipo battery. From my power distribution i connect two cables to my arduino uno gnd and vin pin.
When I use this very simple code:
ESC9.write (100);
ESC6.write (100);
ESC5.write (100);
ESC3.write (100);
delay (2000);

ESC9.write (0);
ESC6.write (0);
ESC5.write (0);
ESC3.write (0);
delay (2000);

The motors start like they should but they stutter (some motors move more than others) and as you can see in my code i tell them to stop after 2 seconds to see if i can control them and indeed they stop nicely.
This is a 3 second video on how it looks once I enter my lipo battery:
https://vid.me/XpWg
Is this a case of bad soldering somewhere perhaps or do I need to calibrate my ESC/motor? Codewise I am just using a simple Servo and then I just use the code I posted above. Do I need to add anything else maybe? Since all 4 motors are stuttering/buzzing it is most likely not a problem with the motor/esc i suppose!
My arduino uno is a chinese copy, could that have anything to do with it?
Also I made this post earlier with a little less information but more info about my soldering: All four of my ESC motors stutters when I run it on my Arduino, how can this be fixed?
Appreciate every help and tips!

This seem to be the same problem. You should have just edited the previous question.

Ah ok i am pretty new so i thought i should create a new post with more info.

Please edit the original post with this new information/images.

It isn't clear from your diagram or the video what wire thicknesses you've used or precisely how currents are being routed, or how big your battery is.
Let BPG denote the ground terminal on the battery pack, and BP+ the battery's positive terminal.
There should be heavy wire from BPG to the ground pin of each ESC.  There should be a signal wire (that is, heavy or light, makes little difference as long as motor currents have their own heavy wires to follow) from BPG to an Arduino Gnd pin.
There should be heavy wire from BP+ to the positive voltage pin of each ESC.  There should be a signal wire from BP+ to Arduino Vin.
There should be signal wires from Arduino PWM outputs to ESC PWM inputs.  There should be heavy wires from ESCs to motors.
Also, in your code try changing 100 on up to 200 or 250 (or near whatever the ESC maximum setting is) to see if problem persists at higher levels of PWM drive.  Also if your battery pack is small, add some more packs of the same voltage in parallel, or try a heavier-duty pack.
Edit 1: Check whether each of the motors can work ok by itself.  That is, either comment out three at a time, or use if-statements that check button or jumper settings.  If all the motors work ok singly, try them in pairs or triples.  There are six different combinations of motor pairs, so rather than trying all six of those you might first try the four different sets of three motors at a time, and if that reveals a combination of three motors that fails, try the pair combinations among those three to see if there is some interaction between two motors.  If problems occur when testing with fewer than four motors, try swapping motors on to different ESCs, to find out if the problem is due to a motor, an ESC, or the battery.  (You can also swap motors on ESCs and test all four at once, but testing with fewer motors going should provide a more systematic problem solving method.)

I have used regular arduino jumper cable on everything except with the ESC and motor. with the ESC i soldered a bullet on the red and black wire (that are a little bit thicker than an arduino cable and then i connect those to the power distribution board. On the distribution board there are two slots where i can put two arduino jumper cables and there i put one that goes to the GND and the other to the VIN.

The motors that are connected to the ESC are also 3 thicker wires that i have put together (did not need to solder anything here, just put them together). I tried changing to 100, 200, 250 but it stutters the same with the same frequency. My battery is a 3s lipo with 1500 mah 65C.

This is the motor + esc i use: https://hobbyking.com/en_us/mt1806-brushless-combo-include-esc-5030cw-ccw.html and the battery i use: https://hobbyking.com/en_us/graphene-1500mah-3s-65c-w-xt60.html

Have you tried with two motors only, or three?   See edit 1 for more comments on testing

Will try it now!

A weird thing that is happening now (and also has happend before) is that the drone beeps once i insert my lipo battery

Is that a sign of something?

Some drones beep once when they pair up with transmitter, and continued beeping is a low-voltage signal on some drones; aside from that I don't know.

yeah when it works it beeps twice but now i have the issue that it keeps beeping. like it is some sort of error.

Double check if by mistake there might be a short in the wiring.  What battery voltage do you measure just before, and just after, turning it on?

I do not have an oscillator unfortantly :( which makes it very hard to solve this


text:
Simulate motor encoder quadrature signals using an Arduino UNO
I'm supposed to write a raspberry pi and arduino code to read the RPM of a motor with an encoder attached to it. However, I'm having weird numbers and I'm unsure about the specs on the motor and the encoder. So I thought it would be smart to use a second arduino to simulate the motor with encoder.
The simulator would need to produce a 2 signals representing the two signals from the encoder. I want to be able to set the frequency and phase shift of these signals in software to imitate changes in speed and direction of the motor rotation. Forward would have one signal 90 degrees ahead, and then reverse having that same signal to be 90 degrees behind. So phase difference of plus or minus 90 degrees.
I'd like to eventually have the simulator be able to simulate motor actions like oscillating between forward and reverse 5 seconds each, or forward for 5 seconds and then stop completely.
I found this code by bigjosh which is more or less what I want to do. However, that code doesn't allow for a shift of -90 deg by default. I know there's a comment there to change it, but I'm not knowledgeable enough to understand what's going on exactly. I'd like someone to help me with that.

what is your question? ... this site is a Q&A site, not a forum, and not a brainstorming site

Wow, that turned out to be way harder than I expected. It is very hard to do cleanly on the AVR timer. But I was able to come up with this working function, which I think is what you are looking for...
// freq_hz is frequency in hertz from 122 to 4,000,000
// shift_deg is phase shift between output A and output B in degrees (values outside -180 to +180 are normalized)

// Note that at frequencies above 44KHz you will loose precision on phase shift. At 4Mhz, everything is rounded to just 0 or +/-90 degrees.
// Note that all timing happens in 1/16Mhz increments, so frequencies that do not land on integer multipules of that will be aproximiate.
// Use startWaveforms() directly for more precise control.

void startQuadrature( unsigned long freq_hz , int shift_deg  );

It can glitch at start-up, shutdown, and changes in speed and direction... but so can a motor encoder so I guess that is ok. It would be possible to create a glitch-free version but more work.
Github repo here...
https://github.com/bigjosh/Quadrature
So, to simulate a motor going forward with 50KHz pulse rate, you would use something like...
startQuadrature( 50000 , +90);
...and the same pulse rate going backwards would be...
startQuadrature( 50000 , -90);
Do note that if you connect an Arduino UNO output pin to a Raspberry Pi input pin that it will likely damage the Pi. This is because the UNO outputs 5 volts for a "1" signal, but the Pi can only tolerate a maximum 3.3V on any pin. You can google "5V 3.3V level shifting" for solutions to this problem.

Wow! Thank you so much! I can't believe you actually went all out like that! Much appreciated honestly.
I have a couple of questions:

Are you using a program to simulate the arduino and oscilloscope or are you using real hardware and taking snapshots?
I'm actually getting a lot of glitches that is making this extremely unstable. To the point that it's not working out for me at all. I'm not sure if this is error on my side (receiving arduino) or the hardware cannot do much better.

Thanks again!
For voltage level shifting, I was gonna use resistors until I buy a proper module

@krusion, if you found it useful you should vote it up.

bigjosh - Nice work!  I just dl'd the repo and tried it on a spare Uno here - works like a charm, once I got all my stupidities cleared up ;-)

@user3765883, that indicates it makes sense to "accept" it as the answer.

source: Stack Exchange

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

sort: votes


text:
Why is my Adafruit motor shield not spinning my motors?
I'm using the Adafruit Motor Shield v2.3. I'm powering the Arduino with a USB cable and I'm powering the motor shield with a 9 volt battery.
I removed the vin pin, and I'm using this tutorial/code to make the DC motor spin.
I've tried 3 different kinds of DC motors, but none of them will do anything. The Arduino works for normal sketches, like lighting up LEDs, but I can't get the motors to work.
Any ideas?
Edit: I'm using Adafruit's "Motor Test" code from the Motor Shield v2 library, as shown below. The motor is on port 1.
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>

AF_DCMotor motor(4);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");

  // turn on motor
  motor.setSpeed(200);

  motor.run(RELEASE);
}

void loop() {
  uint8_t i;

  Serial.print("tick");

  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);
    delay(10);
 }

  for (i=255; i!=0; i--) {
    motor.setSpeed(i);
    delay(10);
 }

  Serial.print("tock");

  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);
    delay(10);
 }

  for (i=255; i!=0; i--) {
    motor.setSpeed(i);
    delay(10);
 }

  Serial.print("tech");
  motor.run(RELEASE);
  delay(1000);
}

You said "this tutorial/code" but there is nothing. Did you forget to add a link?

@JakeC - Thanks, I had copied it from my reddit post. It's fixed now.

What motors are you using? Are they rated to run at 9 volts? How good is the connection to the motor? It looks like from the picture that the pins are shorting on the casing. Do you have a multi-meter? Have you checked the voltage of the battery?

ACtually, ignore the above, according to Adafruit, you cannot use a 9V battery. See: https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/faq#faq-14

As pointed out here countless times before, a 9v "transistor" battery is the wrong choice for most motor projects, as it has minimal current capability.  Don't use it!

a micro servo SG90 was connected with the motor shield too.

A couple of things I see...
1.) Your motor leads may be shorting out of the housing of the motor. make sure they are not.
2.) You may have the motor on the wrong port for the given code:
On line 7 of the code it reads: AF_DCMotor motor(4);
So try switching physically your motor to port 4.
3.) Also, this board has an I2C address and I dont see that addressed anywhere in the code. You can check to see what the I2C address is with this code. It will also show you that the motor control board is indeed responding.
// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

Thanks for the code! I had soldered my pins on a bit crooked, so it was difficult to push them all the way in. When I ran your test, it couldn't find any I2C devices, and according to some Google results, that problem can be caused by various pin connectivity issues. I detached the motor shield from the Arduino, straightened out the pins, reinserted the motor shield as firmly as I could, and then everything started working!

@Pikamander2  :) Glad I could help!

Per the comments above, and the documentation from Adafruit, a 9V battery is insufficient for use with motors as they do not provide enough current.

Well, I've tried it with 2 AA batteries as well, but no luck. Here's what it currently looks like: http://i.imgur.com/IyTPnfx.jpg

2 AA is only ~3V, nowhere near enough. Per the Adafruit guide, the Green LED needs to be lit brightly and from the pic it doesn't appear to be as bright. You would need to use at least 4 AA batteries to meet the 5V threshold and no more than 8 to stay under the 12 V maximum.

Here it is with a Tenergy 9.6V 2000mAh battery (fully charged). It's lit up a lot brighter, but the motor still does nothing. http://i.imgur.com/Uursw2z.jpg

At this point I would update your original question with the new details, and my previous comments would apply there. Check the connections to the motor (they still don't very good). Maybe use a multi-meter to check the output of the board.

Also, I've added the code to the original post. It's just the standard Adafruit motor example code, with no modifications

My multimeter is giving me 0 from all of the motor ports, so the motor shield isn't putting out any power. Any idea why?

I see that this is still not working even with a proper battery. My next best guess is you need to update your library:

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>

Judging by 2009 and AFMotor.h you have a copy of an old version of the library. I recommend getting the latest version and following the official tutorial.

The issue turned out to be that my bent pins weren't pushed all the way in to the Arduino, so Accentrix's answer was the most helpful. Still, thanks for the link, I hadn't noticed that I was using an old library.

This was my problem. For the old version of the adafruit motor shield board, the header is named "AFMotor.h". Mine is the Adafruit motor shield v2 and the correct header file is named "Adafruit_MotorShield.h". If you make this mistake then the problem is exactly as described, everything looks like it should work but nothing happens.

license: 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:
LoRa stops working after several hours. Arduino reset button ineffective
I am designing a master-slave LoRa link between two Arduino Pro Minis. The goal is to control a car heater a few hundred meters from my home. The master sends a command to the slave as needed. The slave acknowledges the command.
If no ACK is received in 5 sec the command is resent. In addition to this the master queries the slave every minute to verify the link.
This library is used to control the DRF1278F
I presume that a receive callback or a call to LoRa.parsePacket() returns either nothing or a complete packet, so I do not ever have to handle partial packets.
Chinese Arduino Pro Mini 3.3V 8MHz boards are used.
I am using a module DRF1278F module which contains an RFIC SX1278
Connections
Arduino --> LoRa module
----------------------------------
  SS 10 --> NSEL 10k pullup to Vcc
 SCK 13 --> SCK
MISO 12 --> SDO 100k pulldown to GND
MOSI 11 --> SDI
 INT  3 --> IO0
 RST  6 --> RST

The device is built on a piece of PCB acting as a ground plane, all GND connections are done to this plane.
It is constructed with short direct wiring.

Problem.
After several hours of operation either the master or the slave sort of hangs up. No radio operations any more. There is activity on the SPI but very different to normal operation. I have tested for weeks and not yet survived for one night.
Pushing the reset button does not restore operations. Removing 3.3V power always restore normal operation, even a very brief short circuit of 3.3V.
There is no need to rest in power down, so probably not an overheat issue.
It can be either the master or the slave end that hangs up. Power cycling only the hung up unit will restore communications. My simple protocol will then resyncronize itself and continue running.
The arduino watch dog timer is activated, however it does not trigger when the hangup occurs as the arduino program loop still runs.
Things tested.
The 3.3 V supply has less than 50mV p-p ripple as checked with an oscilloscope set to infinite persistence for 8 hours, while a hangup occurred.
The interface can be run either polled or interrupt driven, no difference.
No String objects are used.
Using different Vcc like 3.0V and 3.6V makes no difference.
Extra Vcc decoupling made no improvement.
Lowering SPI speed from 8MHz to 4MHz made no difference.
Removed Arduino LED on pin 13.
My problem symptoms are similar to this old question
What can I do to resolve this issue?
Slave code:
/*
Relay controller, remote end of link
*/
#include <SPI.h>
#include <LoRa.h>
#include <avr/wdt.h>

//#define TTT

#define csPin 10
#define resetPin 6
#define irqPin 3         // must be a hardware interrupt pin
#define myLED 8
#define GNDRET 7
#define powerPin 9

unsigned long LEDtime;
const unsigned long LEDonTime = 500;

char outgoing[40];
byte msgCount = 0;
unsigned long lastLoopTime = 0;
unsigned long heaterStarted = 0l;
const unsigned long heaterTime = 60 * 60 * 1000L; // One hour in ms
unsigned interval = 2000;
int temp = 2310;
byte localAddress = 0x11, destination = 0xAA;
unsigned long ttt;

volatile char incoming[40];
volatile int recipient;
volatile byte sender, incomingMsgId,
incomingLength, gotMsg, ovrn;

void setup()
{
    Serial.begin(9600);
    while (!Serial);
    pinMode(myLED, OUTPUT);
    digitalWrite(myLED, LOW);
    pinMode(GNDRET, OUTPUT);
    digitalWrite(GNDRET, LOW);
    pinMode(powerPin, OUTPUT);
    digitalWrite(powerPin, LOW);

    Serial.println("LoRa Switch 0.1");

    LoRa.setPins(csPin, resetPin, irqPin);
/*
    LoRa.setTxPower(10);
    LoRa.setSpreadingFactor(12);
    LoRa.setCodingRate4(8);
    LoRa.setSPIFrequency(4E6);
    LoRa.enableCrc();
*/
    wdt_enable(WDTO_1S);

    if (!LoRa.begin(433E6))
    {
        Serial.println("LoRa init failed. Check your connections.");
        {
            // blinking in panic
            LEDtime = millis();
            while (millis() - LEDtime < 75)
            {
                digitalWrite(myLED, HIGH);
            }
            while (millis() - LEDtime < 150)
            {
                digitalWrite(myLED, LOW);
            }
        }
    }

    LoRa.onReceive(onReceive);  // Assign callback
    LoRa.receive();
    Serial.println("LoRa init succeeded.");
}

void loop()
{
    if (millis() - lastLoopTime > 1000)
    {
        // Once per second loop
        lastLoopTime = millis();
    }

//  onReceive(LoRa.parsePacket()); // Polling

    if (gotMsg)  // Flag from CallBack routine
    {
        digitalWrite(myLED, HIGH);
        LEDtime = millis();

#ifdef TTT
        Serial.print("Received from: 0x");
        Serial.println(sender, HEX);
        Serial.print("Sent to: 0x");
        Serial.println(recipient, HEX);
        Serial.print("Message ID: ");
        Serial.println(incomingMsgId);
        Serial.print("Message length: ");
        Serial.println(incomingLength);
        Serial.print("Message: <<");
        for (int i = 0; incoming[i] != 0; i++)
            Serial.write(incoming[i]);
        Serial.println(">>");
        Serial.print("RSSI: ");
        Serial.println(LoRa.packetRssi());
        Serial.print("Snr: ");
        Serial.println(LoRa.packetSnr());
        Serial.println();
#endif
        // Command processing
        if (incomingLength == 4)
        {
            // Start heater, it will either timeout or be stopped by a message
            if ((byte)incoming[0] == 0x55 && (byte)incoming[1] == 0xAA)
            {
                Serial.println("Set on");
                digitalWrite(powerPin, HIGH);
                heaterStarted = millis();
            }

            if ((byte)incoming[0] == 0xCC && (byte)incoming[1] == 0x99) // Stop heater
            {
                Serial.println("Set off");
                digitalWrite(powerPin, LOW);
                heaterStarted = 0L;
            }
            // Build ack answer

            if (heaterStarted > 0L)
            {
                // Compute session time in minutes
                ttt = millis() - heaterStarted;
                ttt /= (1000L * 60L); // minutes since start
            }
            else
                ttt = 0L;
            outgoing[0] = (heaterStarted > 0L) ? 'T' : 'F'; // Heater state
            snprintf(outgoing + 1, 30, "%3lu", ttt);

            incoming[0] = 0; // We are done, clear flags
            gotMsg = 0;

            sendAck(outgoing);
        }
        LoRa.receive();

    }

    if (LEDtime) // LED timeout
    {
        if (millis() - LEDtime > LEDonTime)
        {
            digitalWrite(myLED, LOW);
            LEDtime = 0;
        }
    }

    if (heaterStarted) // Heater timeout
    {
        if (millis() - heaterStarted > heaterTime)
        {
            digitalWrite(powerPin, LOW);
            heaterStarted = 0L;
        }
    }
    wdt_reset();
    // END of loop
}

void sendMessage(char *outgoing)
{
    LoRa.beginPacket();                   // start packet
    LoRa.write(destination);              // add destination address
    LoRa.write(localAddress);             // add sender address
    LoRa.write(msgCount++);                 // add message ID
    LoRa.write(bsize(outgoing));        // add payload length
    LoRa.print(outgoing);                 // add payload
    LoRa.endPacket();                     // finish packet and send it
}

void sendAck(char *outgoing)
{
    Serial.println("Send ACK");
    LoRa.beginPacket();
    LoRa.write(destination);
    LoRa.write(localAddress);
    LoRa.write(incomingMsgId);            // report ID
    LoRa.write(bsize(outgoing));        // add payload length
    LoRa.print(outgoing);                 // add payload
    LoRa.endPacket();
}

byte bsize(char *ooo)
{
    byte i = 0;
    while (ooo[i++]);
    return i - 1;
}

byte bsize(volatile char *oo)
{
    return bsize((volatile char *)oo);
}

byte insptr;
void onReceive(int packetSize) // has to be a non blocking function
{
    if (packetSize == 0) return;     // if there's no packet, return
    if (gotMsg) ovrn = true; // gotMsg should be reset by consumer by now

    // read packet header bytes:
    recipient = LoRa.read();         // recipient address
    sender = LoRa.read();            // sender address
    incomingMsgId = LoRa.read();     // incoming msg ID
    incomingLength = LoRa.read();    // incoming msg length

    insptr = 0;

    while (LoRa.available())
    {
        if (insptr < 38)
            incoming[insptr++] = (char)LoRa.read();
        else
            LoRa.read();  // Flush
    }
    incoming[insptr] = 0;  // End of C string
    gotMsg = true;

}

/*
void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
void setFrequency(long frequency);
void setSpreadingFactor(int sf);
void setSignalBandwidth(long sbw);
void setCodingRate4(int denominator);
void setPreambleLength(long length);
void setSyncWord(int sw);
void enableCrc();
void disableCrc();
*/

Master code:
/*
Relay controller, Controller and GUI base
*/
#include <SPI.h>
#include <LoRa.h>
#include <avr/wdt.h>

#define TTT

#define csPin  10
#define resetPin 6
#define irqPin 3         // must be a hardware interrupt pin
#define ackLED 9
#define LEDGND 8
#define remoteLED 7

unsigned long LEDtime;
const unsigned long LEDonTime = 500;

char outgoing[40];
byte msgSequ = 0, mincnt, ack_TO;
unsigned long lastLoopTime = 0;
unsigned interval = 2000;
byte localAddress = 0xAA, destination = 0x11;
unsigned long ttt;

volatile char incoming[40];
volatile int recipient;
volatile byte sender, incomingMsgId, incomingLength, isACKed, gotMsg, ovrn;

char cc;

void setup()
{
    Serial.begin(9600);
    while (!Serial);
    pinMode(ackLED, OUTPUT);
    digitalWrite(ackLED, LOW);
    pinMode(remoteLED, OUTPUT);
    digitalWrite(remoteLED, LOW);
    pinMode(LEDGND, OUTPUT);
    digitalWrite(LEDGND, LOW);
    isACKed = 1;
    Serial.println("LoRa Master 0.1");

    LoRa.setPins(csPin, resetPin, irqPin);
/* no specials
    LoRa.setTxPower(10);
    LoRa.setSPIFrequency(4E6);
    LoRa.setSpreadingFactor(12);
    LoRa.setCodingRate4(8);
    LoRa.enableCrc();
*/
    wdt_enable(WDTO_1S);

    if (!LoRa.begin(433E6))
    {
        Serial.println("LoRa init failed. Check your connections.");
        {
            // blinking in panic
            LEDtime = millis();
            while (millis() - LEDtime < 75)
            {
                digitalWrite(ackLED, HIGH);
            }
            while (millis() - LEDtime < 150)
            {
                digitalWrite(ackLED, LOW);
            }
        }
    }

    LoRa.onReceive(onReceive);  // Assign callback
    LoRa.receive();
    Serial.println("LoRa init succeeded.");
}

void loop()
{
    digitalWrite(ackLED, isACKed == 0);

    if (millis() - lastLoopTime > 1000)
    {
        // Once per second loop
        lastLoopTime = millis();

        if (isACKed == 0)
        {
            if (ack_TO++ > 5)
            {
                sendMessage(outgoing); // Resend
                LoRa.receive();
                ack_TO = 0;
                Serial.println("Resend...");
            }
        }

        if (mincnt++ > 60)
        {
            // Once per minute loop
            mincnt = 0;
            if (isACKed)  // Free to ask
            {
                // Heartbeat
                cmdAsk();
                isACKed = 0;
            }
        }
    }

    if ((cc = Serial.read()) > 0)  // Test version, cmd
    {
        if (cc == '1')
        {
            cmdOn();
            isACKed = 0;
        }
        else if (cc == '0')
        {
            cmdOff();
            isACKed = 0;
        }
        else if (cc == 'Q')
        {
            cmdAsk();
            isACKed = 0;
        }
    }
//  onReceive(LoRa.parsePacket()); // Polling

    if (gotMsg)  // Flag from onReceive routine
    {
#ifdef TTT
        Serial.print("Received from: 0x");
        Serial.println(sender, HEX);
        Serial.print("Sent to: 0x");
        Serial.println(recipient, HEX);
        Serial.print("Message ID: ");
        Serial.println(incomingMsgId);
        Serial.print("Message length: ");
        Serial.println(incomingLength);
        Serial.print("Message: <<");
        for (int i = 0; incoming[i] != 0; i++)
            Serial.write(incoming[i]);
        Serial.println(">>");
        Serial.print("RSSI: ");
        Serial.println(LoRa.packetRssi());
        Serial.print("Snr: ");
        Serial.println(LoRa.packetSnr());
        Serial.println();
#endif
        // Command processing
        if (incomingLength == 4)
            if (incomingMsgId == msgSequ - 1) // Ack is on last sent
            {
                if (incoming[0] == 'T') digitalWrite(remoteLED, HIGH);
                if (incoming[0] == 'F') digitalWrite(remoteLED, LOW);
                isACKed = 1;
            }
        incoming[0] = 0; // Message is processed, clear flags
        gotMsg = 0;
    }

    if (LEDtime) // LED timeout
    {
        if (millis() - LEDtime > LEDonTime)
        {
            LEDtime = 0;
        }
    }
    wdt_reset();
}   // END of loop

void cmdOn()
{
    outgoing[0] = 0x55; // Heater  on
    outgoing[1] = 0xAA;
    outgoing[2] = 'X';
    outgoing[3] = 'Y';
    sendMessage(outgoing);
    LoRa.receive();
}

void cmdOff()
{
    outgoing[0] = 0xCC; // Heater  off
    outgoing[1] = 0x99;
    outgoing[2] = 'A';
    outgoing[3] = 'B';
    sendMessage(outgoing);
    LoRa.receive();
}

void cmdAsk()
{
    outgoing[0] = 0x0F;
    outgoing[1] = 0xF0;
    outgoing[2] = '7';
    outgoing[3] = '7';
    sendMessage(outgoing);
    LoRa.receive();
}

void sendMessage(char *outgoing)
{
    LoRa.beginPacket();                   // start packet
    LoRa.write(destination);              // add destination address
    LoRa.write(localAddress);             // add sender address
    LoRa.write(msgSequ++);                 // add message ID
    LoRa.write(bsize(outgoing));        // add payload length
    LoRa.print(outgoing);                 // add payload
    LoRa.endPacket();                     // finish packet and send it
}

byte bsize(char *ooo)
{
    byte i = 0;
    while (ooo[i++]);
    return i - 1;
}

byte bsize(volatile char *oo)
{
    return bsize((volatile char *)oo);
}

unsigned char insptr;
void onReceive(int packetSize) // is a non blocking function
{
    if (packetSize == 0) return;     // if there's no packet, return
    if (gotMsg) ovrn = true; // gotMsg should be reset by consumer by now

    // read packet header bytes:
    recipient = LoRa.read();         // recipient address
    sender = LoRa.read();            // sender address
    incomingMsgId = LoRa.read();     // incoming msg ID
    incomingLength = LoRa.read();    // incoming msg length

    insptr = 0;

    while (LoRa.available())
    {
        if (insptr < 38)
            incoming[insptr++] = (char)LoRa.read();
        else
            LoRa.read();  // Flush
    }
    incoming[insptr] = 0;
    gotMsg = true;
}

/*
void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
void setFrequency(long frequency);
void setSpreadingFactor(int sf);
void setSignalBandwidth(long sbw);
void setCodingRate4(int denominator);
void setPreambleLength(long length);
void setSyncWord(int sw);
void enableCrc();
void disableCrc();

RSSI always a value between -30 ( very close) and - 120
SNR 0 is noise floor… max = 10

*/

If pressing Reset on the Arduino doesn't help it seems likely to me that the Lora part is the problem. Pressing Reset wouldn't reset that (necessarily).

does it always hang up after the same amount of time?

Removing 3.3V power always restore normal operation - to which end? Sending or receiving?

between two Arduino Pro Micros ... Chinese Arduino Pro Mini 3.3V 8MHz boards are used - which is it? Mini or Micro?

maybe it has something to do with a sequence counter of some kind reaching an overflow condition

@Nick Gammon How to edit  the code segments like you did?

@jsotola The time to hangup seems random and quite long. Also which side, master or slave, that hangs up seems unpredictable.

The DRF1278F has a reset pin. Just connect that pin to one of the Arduino pins. Then in the setup set the pin to OUTPUT and LOW, wait a ms, then turn it back into an INPUT. That way the DRF1278F also resets, when the arduino resets. E.g. through a WDT event, which you're already using.

@Gerben LoRa.begin() pulses NRST, however it does not seem to work when hung up. WDT is not triggered by the hangup.

How to use markdown

i would have the lora turn off for 50 seconds, then on for 10, in a loop. saves power 80%, ensures "fresh boot", with only a min of lag max to start the heater. might also consider ESPNOW instead of LORA.

I feel I want to report the probable solution to this problem.
I hope an answer to my own question is appropriate.
After much testing I found an interaction between the boot loader and the watchdog. This post describes it well: Watchdog timer blog post
So, replacing the boot loader seems to remove the hangup, so far ...
Why the watchdog triggers in the first place remains to be found out but presently it does little or no harm.
A side note, the reset button seems to reset the ProMini if pushed reasonably soon after the hangup. If pushed hours later it has no effect.

Has been running continiously for over a year now wihout any hangup.

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


text:
Update Dynamically Tkinter Widget Scale from Arduino Ports using python and firmata
I'm having trouble trying to get Arduino digital ports values and set these values into a Python Tkinter Widget Scale.
I'm using Python and Arduino with Firmata.  I'm able to access my arduino board with python code.  For example in a label widget I'm getting and setting Arduino analog port value in real-time to a label as in following code without any problems:
import Tkinter
import pyfirmata

def onStartButtonPress():
    while True:
        if flag.get():
            analogReadLabel.config(text=str(a0.read()))
            analogReadLabel.update_idletasks()
            top.update()
        else:
            break
    board.exit()
    top.destroy()

def onExitButtonPress():
    flag.set(False)

port = 'COM7'
board = pyfirmata.Arduino(port)

it = pyfirmata.util.Iterator(board)
it.start()

a0 = board.get_pin('a:0:i')

top = Tkinter.Tk()
top.title("Reading Analog pins")

descriptionLabel = Tkinter.Label(top, text="Potentiometer input:- ")
descriptionLabel.grid(column=1, row=1)

analogReadLabel = Tkinter.Label(top, text="Press Start..")
analogReadLabel.grid(column=2, row=1)

flag = Tkinter.BooleanVar(top)
flag.set(True)

startButton = Tkinter.Button(top, text="Start", command=onStartButtonPress)
startButton.grid(column=1, row=2)

exitButton = Tkinter.Button(top, text="Exit", command=onExitButtonPress)
exitButton.grid(column=2, row=2)

top.mainloop()

Up to this point it's okay and the GUI shows me something like:

But what I'm trying to do and not getting is:

Here is the code:
import Tkinter
import pyfirmata
import serial;

def onStartButtonPress():
    while True:
        if flag.get():
            analogReadLabel.config(text=str(d8.read()))
            analogReadLabel1.config(text=str(d9.read()))
            analogReadLabel2.config(text=str(d10.read()))
            analogReadLabel.update_idletasks()

        pos1 = d8.read()
        if pos1 == True:
            pos1 = int(pos1)
            pos1 = 0
            brightnessScale.set(pos1)

        pos2 = d9.read()
        if pos2 == True:
            pos2 = int(pos2)
            pos2 = 100
            brightnessScale.set(pos2)

       ''' and so on '''

        brightnessScale.update_idletasks()
        top.update()
    else:
        break
board.exit()
top.destroy()

def onExitButtonPress():
    flag.set(False)

port = 'COM7'
board = pyfirmata.Arduino(port)

it = pyfirmata.util.Iterator(board)
it.start()

a0 = board.get_pin('a:0:i')

d4 = board.get_pin('d:4:i')
d5 = board.get_pin('d:5:i')
d6 = board.get_pin('d:6:i')
d7 = board.get_pin('d:7:i')
d8 = board.get_pin('d:8:i')
d9 = board.get_pin('d:9:i')
d10 = board.get_pin('d:10:i')

top = Tkinter.Tk()
top.geometry("800x600")
top.title("Reading Analog pins")

descriptionLabel = Tkinter.Label(top, text="Potentiometer input:- ")
descriptionLabel.grid(column=1, row=1)

analogReadLabel = Tkinter.Label(top, text="Level 1")
analogReadLabel.grid(column=2, row=1)

analogReadLabel1 = Tkinter.Label(top, text="Level 2")
analogReadLabel1.grid(column=3, row=1)

analogReadLabel2 = Tkinter.Label(top, text="Level 3")
analogReadLabel2.grid(column=4, row=1)

brightnessScale = Tkinter.Scale(top, from_ = 500,
                            to = 0,
                            length = 500,
                            width = "30",
                            tickinterval = 50,

                            bg = "lightskyblue",
                            highlightcolor = "darkblue",
                            highlightbackground = "royalblue",
                            troughcolor = "darkblue",

                            state = Tkinter.DISABLED,
                            sliderlength = 50,
                            relief = "sunken",
                            label = "Volume do Reservatorio em %",
                            orient = Tkinter.VERTICAL)
brightnessScale.grid(column=1, row=5)
Tkinter.Label(top,text="Volume da Caixa em (%)").grid(column=1, row=6)

flag = Tkinter.BooleanVar(top)
flag.set(True)

startButton = Tkinter.Button(top, text="Start", command=onStartButtonPress)
startButton.grid(column=1, row=2)

exitButton = Tkinter.Button(top, text="Exit", command=onExitButtonPress)
exitButton.grid(column=2, row=2)

top.mainloop()

To summarize: I have reed switches in each digital port declared in the code.  These reed switches are normally open state, when I put a magnetic field near them it turn to close and I get a change in that value like from False to True.  What I'm trying to do is update the Tkinter Scale Widget in real time as the labels but I'm not getting it.
Is there any trick in python code that can solve my problem ? Because I did a lot of research on the internet and I could not get done, as you can see in image 2 when the state of the second digital pin changes, a label changes to True, and in the scale code this corresponds to the value 100, but it's still on the 0 mark.
I'm not comfortable also with the usage of command, and variable parameters of scale widget.
In short, I want to update in real time python Tkinter scale widget according to values from digital ports from arduino using firmata.
I'm using Python 2.7
PS: for completeness:
This is my arduino code (Sketch) without firmata, which is working as expected.
int level;
int position;

void setup() {

pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);

Serial.begin(9600); // ativa a porta serial

void loop() {
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);

position = digitalRead(8);
if ( position == HIGH) {level=0;}

position = digitalRead(9);
if ( position == HIGH) {Level=100;}

position = digitalRead(10);
if ( position == HIGH) {level=200;}

position = digitalRead(11);
if ( position == HIGH) {level=300;}

position = digitalRead(12);
if ( position == HIGH) {level=400;}

Serial.println(level);
delay(500);

}

What I could do also here
is get these values via serial in python and use them to update the scale in this way but I don't know if in this method it's gonna work also!
And what I thought in Python:
But I still have much to learn in algorithms and Data Structures.
Just the Pseudo Code:
def setScaleValue():
while True:
    if flag.get():
         pos1 = d4.read()
        if pos1 == True: #or 1
        #Here is the problem i don't know for sure what comes in my digital port
        #If is a True bool or a 1 as HIGH value from arduino
        #And probably i don't know if it's possible to change the values of a scale in this way !!!
        #or if i'm mistaken the Cast stuff in Python
            pos1 = int(pos1)
            pos1 = 0
            brightnessScale.set(pos1)

        pos2 = d8.read()
        if pos2 == True:
            pos2 = int(pos2)
            pos2 = 100
            brightnessScale.set(pos2)

        brightnessScale.update_idletasks()
        top.update()
    else:
        break
board.exit()
top.destroy()

return

d4 = board.get_pin('d:4:i')
d5 = board.get_pin('d:5:i')
d6 = board.get_pin('d:6:i')
d7 = board.get_pin('d:7:i')
d8 = board.get_pin('d:8:i')

brightnessScale = Tkinter.Scale(top, from_ = 500,
                            to = 0,
                            length = 500,
                            width = "30",
                            tickinterval = 50,

                            bg = "lightskyblue",
                            highlightcolor = "darkblue",
                            highlightbackground = "royalblue",
                            troughcolor = "darkblue",

                            state = Tkinter.DISABLED,
                            sliderlength = 50,
                            relief = "sunken",
                            label = "Volume do Reservatorio em %",
                            orient = Tkinter.VERTICAL)
brightnessScale.grid(column=1, row=5)
Tkinter.Label(top,text="Volume da Caixa em (%)").grid(column=1, row=6)

your third file is malformed, def setScaleValue(): isn't defined properly, you need an indent level change after a function definition.

When your code runs, can you be able to click on stop button?

in your code:
pos2 = d8.read()
print("pos2 is {} type {}".format(pos2, type(pos2)))  # This way, you'll know the var type you're getting on the console
    if posX == True:
        posX = int(posX)          # You then cast to an integer
        posX = 100                # You discard pos2 value by setting it to 100
        brightnessScale.set(posX) # You set the scale always to value 100

By adding the print line, you can ensure the variable value and type.
Then, you may have to adapt your if statement accordingly.
Beware what you're doing then with those 2 lines reaffecting posX, this is probably not what you want to do before updating the scale.


text:
Arduino only addresses 3 LED at a time
I am running the following sketch on an Arduino Uno using Arduino 1.6.8.
Strip is a WS2811 12V.
#include <Adafruit_NeoPixel.h>
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();
}

void loop (){
   strip.setPixelColor(0, 255, 0, 255);
   strip.show();
}

The problem is that the LED’s light in (Green) groups of three and what I want is individual control.
strip.setPixelColor(0, 255, 0, 255); Illuminates Pixels 0,1,2
strip.setPixelColor(1, 255, 0, 255); Illuminates Pixels 3,4,5
strip.setPixelColor(2, 255, 0, 255); Illuminates Pixels 6,7,8

And so forth.
Although this code uses NeoPixel I get exactly the same issue if I use the equivalent in FastLed.
Any pointers to what I am doing wrong would be appreciated.

LED strips with WS2811 and 12V are the ones with one driver and 3 RGB LEDs on it. These are interconnected so you just can't control less than whole group of three.
If you need individual control, you have to get 5V variant with WS2812.


text:
Odd symbols in ESP8266 responses to AT commands
I used the code below to control an ESP8266.  I am getting some unknown symbols in the responses.
#include <SoftwareSerial.h>
const byte rxPin=2;
const byte txPin=3;
SoftwareSerial ESP8266( rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200);
  delay(1000);
  // put your setup code here, to run once:

}

void loop() {
  Serial.println("sending an AT command");
  ESP8266.println("AT");

  delay(100);
  while(ESP8266.available())
  {
    String inData = ESP8266.readStringUntil('\n');
    Serial.println("Got Response:" + inData);
    delay(1000);
      ESP8266.println("AT+RST");
    }
  // put your main code here, to run repeatedly:

}

The unknown symbols are shown in the screen shot.

What might the problem be?

I have included software serial library

Did you try changing the baud rate on software serial?

Unfortunately your image has been shrunk so much that I can't make out what it says.

I tried using 57600 baud rate

Even changed the serial monitor setting below to carriage return also

I nutted over this for quite a while. If you look up the reference for SoftwareSerial - https://www.arduino.cc/en/Reference/SoftwareSerial - and look at the limitations, you'll find that it won't work above 57k baud rate and pins 2 and 3 wont support change interrupts, whatever they are.  Sometimes I think some of these projects are untested.  I think I'll use the hardware ports on two arduinos and use SoftwareSerial on the right pins and baud rate to get the two arduinos to communicate, or use Software serial to talk to the pc through a MAX232.  I don't think you'll get a 115200 baud esp to talk SoftwareSerial


text:
Does ATmega328 on Uno need to be burned?
I'm new to the Arduino world so please bear with me. I'm not sure whether the ATmega328 bootloader needs to be burned. What I'm reading is all that needs to be done is plug the board into the computer by USB cable. Then burning the 328 is also mentioned. I appreciate any help.

As mentioned, an Arduino style board usually comes with a bootloader in the chip.  You can also buy loose chips already programmed with a bootloader at a small price premium.  And you can use a working Arduino or similar board as an ISP programmer to burn the bootloader into a chip that doesn't have one, or has a different one that you want, or to directly program a sketch alone without a bootloader.

You've mentioned Arduino in your first sentence, but then refer to it as ATMega328 and the board. Is it an Arduino board or is it an ATMega Development board? Two similar but different things. I used several versions of ATMega boards since before Arduino was conceived. Those were the days :). For those you would need to burn your own, but anything with Arduino on it would already have it edit: why is it that right after I post the comment, I notice you specifically mention UNO in the title  It would be highly unlikely a UNO board (even a compatible one) would not have it already

You only ever need to burn a bootloader if:

You are building your own "breadboard" Arduino
You have somehow erased the bootloader that is on your Arduino
You have replaced the original chip on the Arduino

The chip that came already inserted into the Arduino board already has the bootloader installed into it.

It depends. If you bought the arduino from most places, it will be already be burned. However, some less reputable sources might not burn it. If the LED on pin 13 blinks when you power on the arduino, that means the bootloader is installed.

It would be incredibly rare for an Arduino (even compatible Arduino) board not to have a bootloader installed. I've bought a couple early on that were compatible boards without realising it (I know better now), but they always worked "out of the box". Good point about the LED blinking, I would have tested just by plugging it in and trying to send a sketch to it, so good point right there. And welcome to SE Arduino! :)

I bought a pack of 15 arduino clones for a class, and roughly half of them had bootloaders. If they are from Arduino.cc they will likely come with the bootloader, but some clones don't.

If you bought an Arduino Uno the bootloader comes pre-programmed.
"The ATmega328 on the Uno comes preprogrammed with a bootloader that allows you to upload new code to it without the use of an external hardware programmer. It communicates using the original STK500 protocol (reference, C header files)." - from the oficial page.
Might want to take a look at this discussion if you're confused.


text:
Arduino Not Working as Intended when using barrel jack
I am using an Arduino to control some mechanical components in a project I have. It controls a motor, two servos, a valve, and a compressor. When plugged into the computer, everything works fine and perfectly. However, when I power it through the barrel jack using our power supply, some weird things happen. First of all, our servos, which are powered through the Arduino, stop working. All the other components work except for them. Secondly, at the end of the code we have a 5 second delay. Using the computer it works fine. When powered with our supply the delay doesn't seem to happen at all. Any ideas?

You say the servos  are powered through the Arduino.   How are the  motor/valve/compressor powered?  What voltage do you read on the +5V line in the two different ways of powering the Arduino?  How's the +5V line look on a scope ?  Re the 5 second delay, if you have an LCD you can attach, display millis() before and after the delay() call

The motor, compressor, and valve are powered with our 12v battery, which is what the arduino runs on when not plugged in. I am not near my setup right now, so unfortunately I can't take those measurements until later, but I'll check them for sure.

You should not power servos through an Arduino.  Even if they have to use the same supply they should have their own wiring.  They should not use the Arduino's regulator.

i agree with majenko, maybe you know how to fix it but if you do not know here is a site with good information to make you're own  5 volt Regulated source.
http://www.rakeshmondal.info/IC-7805-Voltage-Regulator
sorry for my bad english and good luck. :D

I had a similar problem recently while powering a servo with a Arduino.
It did turn out to be power, our Arduino could only supply about 500ma and with sufficient speed or torque on the servo (a lot of times just the boot sequence) we would it the 500ma at peak, the effect however was baffling at first because when we hit the peak current the Arduino would reboot, this could account for you extra delay at the end.
For us the solution was simple bypass the Arduino when supplying current to the servos, in our case it as a 5v battery, you would probably need to drop the 12v to 6v in your case.


text:
How to split a string into substring Arduino
I'm about identify myself stupid, howcome I couldn' t figure out how to split a string into substring using arduino, even after 10 days of searching. The number is fact... So, As Mr.Arduino.cc says: string.substring() is just can be used as conditional phrase with loops like if. and there is no method such strtok() like in C can help me with this. So guys, I' m bagging you for help, please!
if (ks > 255 * 60)
            {
                    vek.print("Bu yazı, ", 25, 0);
                    vek.printNumI(255*60, 25, 8);
                    vek.print("karakterd-", 25, 16);
                    vek.print("en uzun ol", 25, 24);
                    vek.print("dugundan", 25, 32);
                    vek.print("gosterlemz", 25, 40);
            }

for (byte i = 0; i <= ss ; i ++)
            {
                    for (byte j = 0; j <= 6; j++)
                    {
                            int ilk_kar = j * 10 + i * 60;
                            int son_kar = ilk_kar + 10;

                            String yaz=readString.strtok(ilk_kar,son_kar);

                            vek.print(yaz, 25, j);

                            if (analogRead(A5) == 1023)
                            {
                                    continue;
                            }
                            else
                            {
                                    break;
                            }
                    }
            }
    }
}

Error: sketch_aug22a.ino: In function ‘void loop()’:
sketch_aug22a.ino:83:56: error: ‘class String’ has no member named ‘strtok’
What am I supposed to do?
Thanks, already...

Do you want to split the string on a particular character or position?

You can use strtok(). It's not part of the Arduino core library: it's just a libc function.

And, how am I supposed to find that libc (I guess a library) thing?

Mr.Bonet, pls, I need this answer...

It would help to have the above questions answered. Do you want to split at  a certain spot (eg. 5th character)? Or after certain symbols (eg. a comma)?

How do you find strtok? Google? For example: http://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm

there is no method such strtok() like in C can help me with this - yes, there is. Just use it. No need to include any extra libraries or anything. Why do you think there is "no method"? Did you try it?

I did, I have edited my question. please check that out

strtok() is not a method, it's a plain function that works on C strings (char *), not on String objects. Nick Gammon googled the doc for you, you should take a look at it.

Import the string.h library by adding #include <string.h> on top of your sketch, in order to use the strtok() function.
Checkout the usage example of strtok() here: http://www.cplusplus.com/reference/cstring/strtok/?kw=strtok

in arduino ide?

Yes, of course.


text:
MAX7219 not behaving as expected
I have 2 rows of 12 MAX7219 connected in series with DOUT to DIN (rows are isolated). Now the thing is I am using LedControl Library to work with it. The problem is the last 4 Matrices on both the rows don't work. The sequence in my code is like this where (row, column, matrix) is used to define the row and column of the matrix and I am talking about a single ROW from two ROWs of 12.
Sequence in Code      What Happens
----------------      -----------------
(0, 1, 0)             (0, 1, 0)
(0, 1, 1)             (0, 1, 9)
(0, 1, 2)             (0, 1, 1)
(0, 1, 3)             (0, 1, 10)
(0, 1, 4)             (0, 1, 2)
(0, 1, 5)             (0, 1, 11)
(0, 1, 6)             (0, 1, 3)
.                     .
.                     .
.                     .
(0, 1, 11)            (0, 1, 8)

Now I can understand why does this happens. This code works like this even if the Device Count is 8.
Code:
#include "LedControl.h"
LedControl row1=LedControl(2,4,3,12);
LedControl row2=LedControl(5,7,6,12);

unsigned long delaytime=500;

void setup() {
  int d_row1 =row1.getDeviceCount();
  for(int address=0;address<d_row1;address++) {
    row1.shutdown(address,false);
    row1.setIntensity(address,15);
    row1.clearDisplay(address);
  }

  int d_row2 =row2.getDeviceCount();
  for(int address=0;address<d_row2;address++) {
    row2.shutdown(address,false);
    row2.setIntensity(address,15);
    row2.clearDisplay(address);
  }
}

void loop() {
  int devices=row1.getDeviceCount();
  for (int i = 0; i < devices; i++){
    delay(delaytime);
    row1.setLed(i,0,0,true);
    row2.setLed(i,0,0,true);
    delay(delaytime);
    row1.setLed(i,0,0,false);
    row2.setLed(i,0,0,false);
  }
}

EDIT
I just noticed something, there is no data going to the last 4 matrices. The timings of the blinking of the LEDs on last 4 matrices does not ties correctly (500ms) but it is in fact 250ms (i.e. half time). It means the blinks on last 4 matrices are between pulses of the first 4 matrices.

After fiddling around with various Libraries, I came across this one.
MD_MAX72XX
It has all the functionalities that I needed with a good Simple Wiki to get you started.
Also it is simple enough that even a noob like me could figure it out.
Regards

Have you checked the wiring between matrices and/or swapped modules in case there is a faulty one in the sequence?

yes I did check and it works. When any other module is swapped with that position, same bug.

Looking at your library source, it seems the number of devices is clamped at 8. This isn't a hard limit imposed by the chip but rather practical design. SPI, especially at high speeds, can get unreliable when the bus capacitance, related to the cable lengths, gets so high that signals are skewed beyond recognition. Also the buffer in the library used to hold the row data is 64 bytes in size, intended to hold the data for 8 devices with 8 rows each.
You can edit the library to make it support 12 devices though it will require attention to detail like, increasing the buffer to 96 bytes, getting rid of short-circuits within the methods that make sure that no more than 8 devices can be addressed, for-loops, etc.

That was the case. I am not that good with C and buffer things. So I abandoned this Library for something else. I did try changing the buffers and stuff but I failed, So I thought, instead of trying to customize this Library, I should look for something else as my changes would mean Library is working outside its recommended features. So... yeah...

@echo_salik You can post your solution here (another library?) and accept your answer so that this question is moved off the stack.

Ah yes. Sure. Sorry, forgot. :)


text:
No power from Breadboard Power Supply Module
Components

Breadboard Power Supply Module IM120525004
1 kOhm resistor
Green LED
Arduino Nano
LiPo 7.4V battery

LED Lights Up Fine with USB power from the Arduino

LED Does Not Light Up with power from the Supply Module

What am I doing wrong?

The Lipo battery is brand new and is charged as the terminals showed about 7.6V on my multimeter. This is confirmed by the LED on the supply module itself lighting up fine.
I think I can smell just a little bit of burn whenever the supply module is connected and there is power in the circuit.
The positive jumper wire is connected to the 5V VCC pin on the Arduino, not the VIN pin on the Arduino, not that it matters, because if I remove the Arduino from the breadboard the LED still does not light up

I'm not surprised you can smell burning. You have the power supply connected backwards.
You see that little + and - symbol next to the ON/OFF jumper? That's the polarity of the two runs of pins. You have the + row connected to the - rail of your breadboard (blue) and the - row connected to the (red) positive rail.
Turn the power supply around 180° and connect it to the other end of the breadboard - the rails will be the other way around then.

hahaha, well spotted! it works now :D

Took me a while to notice that... ;)

"It works now", does everything still work? I won't be surprised if something is damaged (as per the burning smell)?

@Paul the components seem to have survived the ordeal as far as the LED and the Nano lighting up go, haven't done any programming test on that Nano yet ..

Too bad, if it was burning maybe it can be another question XD

You are not the first person to have made this mistake. ;)

Been there, done this. (Can't even claim to have only done it once.... dangit!)  But you know what... I check it EVERY time now.  'Tis how we learn!


text:
ATtiny Mapping PPM Inputs to Move Servo Issue
Short Version:
Not able to get a servo to move to mapped input from RC remote control PPM signal.
Detailed Verison:
I am trying to take an input signal from a hobby RC radio (D4RII receiver ppm stream/one wire) signal and map the values 1000-2000 into 0-180 for a value that is useful for a servo. Initially, I had an issue simply reading the values stored within the array from the TinyPpmReader.h library from DigisparkArduinoIntegration on github.
For background, I am using tiny cores. This was the fist issue that was solved:
Accessing Values From Array Within a Library
Second Issue solved:
Mapping PPM Signals to Servo Values
Now, the last part of the battle is to get the servos the actually move. I have successfully (with help)
1.Made the single array values available to be read via serial console (Uno to ATtiny85) like this - Serial.println(TinyPpmReader.width_us(3));
2.Successfully mapped the values within the ppm array to 0-180 and validated the values are correctly mapped and printed to the serial console like this - Serial.println(mappedval0);
Couple of questions. Is it possible that since the ATtiny 85 only has Timer0 and Timer1 available that pwm wont work? ATtiny 85 datasheet here.  If I understand it correctly, the tinyppmreader library does use an interupt driven process.
I chose to go with the SoftwareSerial library since I don't think it is using any timers (Not really sure).  Or, is this just a simple coding issue? What is my mistake? This will compile and the servo does seem to glitch around but not move according to the mapped ppm stream.
Since my search results are now coming up with my previous questions I am hoping this will help others be able to use ppm / servos with the ATiny 85 since it is so small and perfect for many RC related projects.
CODE:
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>
#include <SoftwareServo.h>
//#include <TinyServo.h>

int val0;                    // integer to store value
int mappedval0;
#define PPM_INPUT_PIN  4

SoftwareServo myservo;

const int PPM_max_value = 2000; //put the max value of PPM reading result
const int PPM_min_value = 980; //put the min value of PPM reading result

//const byte SERVOS = 1; // how many servos do you have? up to 5 on ATTiny85 and 8 on ATtiny84/2313
//const byte servoPin[SERVOS] = { 1 }; // what pins are your servos on?
// you have the option to give your servos nice names. 0 refers to the first servo pin above, 1 to the second, etc

//#define RIGHTLEGSERVO 0

void setup()
{
  Serial.begin(38400);//attiny tx - rx uno does not work at 9600 baud. Set to 38400 @ attiny 1mhz and uno serial console to 38400 baud
  TinyPpmReader.attach(PPM_INPUT_PIN); /* Attach TinyPpmReader to PPM_INPUT_PIN pin */
  //setupServos();
    myservo.attach(0);
}

void loop()
{
   val0 =TinyPpmReader.width_us(3);   //get PPM reading result from index 4
   mappedval0= map(val0, PPM_min_value, PPM_max_value, 0, 180);
   myservo.write(mappedval0);
   //moveServo(RIGHTLEGSERVO, mappedval0);
   //Serial.println(mappedval0);
   SoftwareServo::refresh();
   delay(50);

}

I have commented out the tinyservo library parts while testing the SoftwareServo library.

Does your Tiny have a crystal? That would provider beter timing, but i'm not sure if that is the real problem here. It may indeed be re-using some of the hardware peripherals. And why not use an Atmega328P?

Have you tried contrilling a servo withouth all the other parts of the code? Basically running the servo libraries examples and doing some sweeps. And do you know if you're using a 1mhz (using prescaler) internal clock or 8mhz?

As Paul suggested in 2nd comment, see if you can get the servos to sweep back and forth.   ¶ If you get them to work with numbers in range 0 to 180, next try out your numbers 1000 to 2000 as the argument to myservo.write.  Look at the code for servo::write and you will see that parameter values above 544 are treated as microseconds and used without translation.

Yes, I used a 10k pot to test before moving to the ppm stream. jwpat, why would I need to try 1000-2000 if the values should be 0-180 for the servo?

Another little detail about the behavior is that the servo twitches in sync with the delay(50) variable.


text:
Mapping PPM Signals to Servo Values
This question is an extension of this question.
Accessing Values From Array Within a Library
The answer provided by Mark showed me how to read and print a single value from a particular array by using the index number to print to the serial console.
The second part of this question is how to get these values from the array to map to 0-180 for values that are useful to the servo.
The below code is my attempt that is not working. I used the servo sweep example from the Arduino examples which worked fine with a potentiometer but not with the ppm input. What am I doing wrong here? This won't compile. (I am using TinyServo.h library since this is for an attiny85. Works with with the pot mapping just fine.)
#include <TinyServo.h>
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>

int PPM_INPUT_PIN = TinyPpmReader.width_us(3); //<------- Doesn't work

//int potpin0 = 3;    <---------          // This worked
int val0;                     // integer to store value

const byte SERVOS = 1;                   // how many servos do you have? up to 5 on ATTiny85 and 8 on ATtiny84/2313
const byte servoPin[SERVOS] = { 0 }; // what pins are your servos on?
                                       // you have the option to give your servos nice names. 0 refers to the first servo pin above, 1 to the second, etc

#define PANSERVO 0
#define PPM_INPUT_PIN  2    <--------- //define pin for ppm input

void setup()
{
  setupServos();
}

void loop()
{
  val0 = analogRead(PPM_INPUT_PIN);  <---------          //Doesnt work// reads the value of the       potentiometer (value between 0 and 1023)            // reads the value of the 2nd potentiometer (value between 0 and 1023)
  val0= map(val0, 1000, 2000, 0, 180);
    // scale it to use it with the servo (value between 0 and 180)
       // scale it to use it with the servo (value between 0 and 180)

moveServo(PANSERVO, val0);

  delay(5);                           // waits for the servo to get there
}

For some background, the ppm library outputs like this to the serial monitor:
Ch4=1560 us
These values move from ~1000 - 2000 depending on the ppm signal input. (The input is from a RC remote control receiver)
This example below prints only channel 4 (Ch4=1560 us)from  a total of 8 channels. Now, I want to map this to the values of 0-180:
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>

#define PPM_INPUT_PIN  2

void setup()
{
  Serial.begin(38400);//attiny tx - rx uno does not work at 9600 baud. Set to 38400 @ attiny 1mhz and uno serial console to 38400 baud
  TinyPpmReader.attach(PPM_INPUT_PIN); /* Attach TinyPpmReader to PPM_INPUT_PIN pin */
}

void loop()
{

Serial.print(F("Ch"));Serial.print(3);Serial.print(F("="));Serial.print(TinyPpmReader.width_us(3));Serial.println(F(" us"));

 display results */
  delay(500);
}

What am I doing wrong?

int PPM_INPUT_PIN = TinyPpmReader.width_us(3); contain a reading result, when followed by val0 = analogRead(PPM_INPUT_PIN); it's clearly absurd.

Yes, this is where my problem is. I am trying to understand this.

int PPM_INPUT_PIN = TinyPpmReader.width_us(3);

will save the result into variable PPM_INPUT_PIN, while
val0 = analogRead(PPM_INPUT_PIN);

will save an analog reading results from PPM_INPUT_PIN channel into variable val0. This is (one of) your problem.
To map the PPM value, you can do:
#include <TinyServo.h>
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>

int val0,                     // integer to store value
    mappedval0;               // integer to store mapped value;

const byte SERVOS = 1;                   // how many servos do you have? up to 5 on ATTiny85 and 8 on ATtiny84/2313
const byte servoPin[SERVOS] = { 0 }; // what pins are your servos on?
                                       // you have the option to give your servos nice names. 0 refers to the first servo pin above, 1 to the second, etc

#define PANSERVO 0
#define PPM_INPUT_PIN  2    <--------- //define pin for ppm input

const int PPM_max_value = xxxxx; //put the max value of PPM reading result
const int PPM_min_value = yyyyy; //put the min value of PPM reading result

void setup()
{
  setupServos();
}

void loop()
{
  val0 = TinyPpmReader.width_us(4);   //get PPM reading result from index 4
  mappedval0= map(val0, PPM_min_value, PPM_max_value, 0, 180);
    // scale it to use it with the servo (value between 0 and 180)

  moveServo(PANSERVO, mappedval0);
  delay(5);                           // waits for the servo to get there
}

I think I see what I was doing.Thanks. Why is int left out before mappedval0; ? EDIT. I see the comma after val0. Just extending the variable int type to the next line.

This does in fact compile but does not work.

sorry, there's a mistake in my code. It should be moveServo(PANSERVO,mappedval0);. I've edit the answer

Yes, I saw that before compiling and replaced it with the new variable. It does compile but does nothing.

have you tried to see the result of PPM reading? And have you successfully make the servo rotate (without using PPM result as input)?

Yes, I just connected the attiny85 back to the UNO to read the ouput from ppm on pin 2. It is reading the ppm value to the serial console using this line in a serial print sketch:
Serial.print(TinyPpmReader.width_us(3));
Yes, I have tested the servo with a potentiometer to map. That worked fine also.

The PPM stream behaves as expected. It is connected to a radio controlled receiver that is taking a signal from a transmitter. When I move the stick for channel 3, the values move exactly as they should, from ~980 - 2000.

try print the mappedval0. If the result is between 0-180, then the possibility of problem is on moveServo()

Yep, That works. I am able to print the mapped values. For some reason it still doesn't work. I posted another follow-up question here: –
http://arduino.stackexchange.com/questions/33327/attiny-mapping-ppm-inputs-to-move-servo-issue


text:
Serial Getting Garbage Data with real data
I have made an app in VS2015 C#.Net which sends data to Serial port. The data i am sending is:
stat>temp:39,38,;load:17,4,42,;fans>50,50,;

Where as I am receiving:
ððððstat>temp:39,38,;load:17,4,42,;fans>50,50,;

What I have tried:

Set SerialPort Encoding to ASCII in C#
Set SerialPort Encoding to UTF8 in C#
Set SerialPort Encoding to Default in C#

All have no effect.
Some observations:

When I send the data via Serial Monitor of Arduino there is no garbage data.
When I send data via a USB to TTL converter via my App, no garbage. (This part confuses me more)

BAUD RATE IS: 115200.
This is the only thing I have not changed yet and I dont want to change this as the string length will increase over time. this is 43 bytes of data. It can grow to up-to around 64 or 100 bytes and that would take longer to send and even longer to read adding delays in functions that are already working before the serial interrupt.
Regards

The garbage is just that, it is noise sent and stored in the buffer before your application starts. You need to clear buffer, implement a delay or use a defined signal to identify the start of valid data. No amount of fiddling with encoding will change this.

oh... how would i clear the buffer? I can implement the identification thing, but still a clear buffer should be implemented just for, well, clean buffers. hehe @Milliways

@Milliways i should google before asking, but i though it wouldn't be that simple. Serial.flush()

C# Serial.DiscardOutBuffer() after opening the port in C# and before sending data.

The Arduino should read only whole lines (non-newlines until a newline). Discard the line if it doesn't start with "stat>".
This will make your program more robust and less likely to fail with bad input. Fixing the transmitting app instead still leaves your Arduino vulnerable.
Consider the rule of thumb for serial communication: "Be restrictive in what you'll transmit; be lax in what you'll receive." Specify your communication protocol (e.g. "Packets will begin with 'stat>' and end with <newline>", maximum length of a packet, formats of variables and numbers, etc.). Then write your sender to hold as tightly to the spec as possible and write your receiver to accept whatever minor variations in otherwise good packets, that won't cause you to mistakenly accept bad ones. This principle will make your communications systems more robust and easier to get working in the first place.


text:
esp8266 garbage out only when using SoftwareSerial
I'm trying to operate the esp8266. When I connect RX+TX pins to pins 1+2 on the Arduino, everything works fine. but when I'm trying to use software serial all hell breaks loose and the recieved data is garbadeged (It seems like everything is ok but I can't read the output data...
more interesting, the output is not consistent!
example:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
       for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}

And the output:

I've tried changing the SerialMonitor baud rate, the input pins, but results are all the same.
I've recently changed the MCU(uno) to a different and even a different esp module from a different supplier,
I am still getting the same results! I can't be the first one to encounter such phenomena...

softwareserial obviously has troubles working at 115kbps, It helped me to pause between the  espSerial.read();    with a delay of 50 to 100...

Try dropping the SoftwareSerial connection speed to 19200. Ie, esp8266.begin(19200). 115200 it is the absolute max the SoftwareSerial can theoretically handle.
Also if you are not using all the change interrupt pins on your MCU (Uno/Nano?) then use any 2 pins from 10, 11, 12 or 13 rather than 3, 2 // RX, TX.
Not sure about sendCommand function. If you just want to test the connection then it should be as simple as:
SoftwareSerial esp8266(10, 11); // RX, TX

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

    char buffer[50];
    esp8266.write("AT\r\n");
    esp8266.readBytes(buffer, sizeof(buffer));
    Serial.println(buffer);

...
}

Obviously once you need to open web pages and recieve responses then you will need a libary to handle IDP+ data. With a bit of coercion I got Adafruit_ESP8266.h working with SoftwareSerial.

This is a good idea. Try using those interrupt pins

Tried all the above, still getting same garbage...

I suspect you may need to change the baud rate of the ESP-8266. It usually defaults to 115200. I used http://neilkolban.com/tech/wiring-up-esp8266s to get started with a terminal emulator and then flashed the latest AT firmware and changed the baud rate to 19200 using AT+UART_DEF=19200,8,1,0,0. Also the update via cloud seemed to work ok for me once I set the AP ssid & pwd. Note it takes a while when using AT+CIUPDATE.

From my experience, if you want to have a consistent data transfer over the softserial, you must disable (in Arduino) the global interrupts for the time of transmission. To disable global interrupts use cli() command, to enable it again use sei() command.

I tried this and didn't improve. No sending worked anymore then...

A quick thing to try out.
Try changing Serial.begin(115200); to Serial.begin(9600); and leave  esp8266.begin(115200);.
I'm also completely new to Arduino, but I remember seeing the junk values when the serial monitor baud rate is set to a different value than the Arduino's Baud rate.
I was using Arduino Uno and if I set the baud rate to a value other 9600 in the serial window, I was seeing junk values in println function calls.
i.e Set Serial.Begin(9600); and the Serial Montior baud rate also 9600.


text:
OV7670 Camera Module - wrong pins?
I would like to ask you some helpful informations.
Recently I bought an OV7670 Camera Module.
Unfortunately, this item is not compatible with any tutorial I found in dozens and dozens of sites.
It has 18 pins with these signs:
3.3v   GND
SCL    SDA
VS     HS
PCLK   MCLK
D7     D6
D5     D4
D3     D2
D1     D0
RESET  PWDN

I aint noticed these pins on any OV7670 Camera in any site of tutorial, like youtube or arduino.cc or many others at google searching.
The most comon OV7670 Cameras I found in tutorials have SIOC SIOD instead of SCL SDA, HREF instead of HS and XCLK instead of MCLK.
Did I bought a fake or what do you think?
Please, if any of you, knows how to make it conect or have any useful link, I will apreciate to inform me.
Thank you all for your time.

They are actually named in a different manner.
Your camera module has i2c interface.
SIOC is nothing but Serial Input Clock , same as SCL - i2c clock
Similarly , SDA and SIOD are the same - i2c data
HREF and HS are the same too - Hsync signal
MCLK and XCLK are the same too - system clock
Here is a useful link:
https://www.google.co.in/amp/www.instructables.com/id/OV7670-Arduino-Camera-Sensor-Module-Framecapture-T/%3famp_page=true
Cheers !


text:
MySensors GatewaySerial code not compiling
I am trying to compile GatewaySerial code from MySensors library for my Arduino Leonardo and it gives me EEPROM errors.
Gateway code:
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
* The ArduinoGateway prints data received from sensors on the serial link.
* The gateway accepts input on seral which will be sent out on radio network.
*
* The GW code is designed for Arduino Nano 328p / 16MHz
*
* Wire connections (OPTIONAL):
* - Inclusion button should be connected between digital pin 3 and GND
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
*
* LEDs (OPTIONAL):
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
*
*/

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95

// Set LOW transmit power level as default, if you have an amplified NRF-module and
// power your radio separately with a good regulator you can turn up PA level.
#define MY_RF24_PA_LEVEL RF24_PA_LOW

// Enable serial gateway
#define MY_GATEWAY_SERIAL

// Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
#if F_CPU == 8000000L
#define MY_BAUD_RATE 38400
#endif

// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
//#define MY_INCLUSION_BUTTON_FEATURE

// Inverses behavior of inclusion button (if using external pullup)
//#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP

// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN  3

// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300

// Inverses the behavior of leds
//#define MY_WITH_LEDS_BLINKING_INVERSE

// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
//#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED

#include

void setup()
{
    // Setup locally attached sensors
}

void presentation()
{
    // Present locally attached sensors
}

void loop()
{
    // Send locally attached sensor data here
}

Error:

In file included from /home/szymex/Arduino/libraries/MySensors/hal/architecture/AVR/MyHwAVR.cpp:20:0,
                 from /home/szymex/Arduino/libraries/MySensors/MySensors.h:64,
                 from /home/szymex/Arduino/libraries/MySensors/examples/GatewaySerial/GatewaySerial.ino:86:
/home/szymex/Arduino/libraries/MySensors/core/MyTransport.cpp: In function 'bool transportAssignNodeID(uint8_t)':
/home/szymex/Arduino/libraries/MySensors/hal/architecture/AVR/MyHwAVR.h:54:82: error: 'eeprom_update_byte' was not declared in this scope
 #define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t*)(__pos), (__val))
                                                                                ^
/home/szymex/Arduino/libraries/MySensors/core/MyTransport.cpp:503:3: note: in expansion of macro 'hwWriteConfig'
   hwWriteConfig(EEPROM_NODE_ID_ADDRESS, newNodeId);
   ^
/home/szymex/Arduino/libraries/MySensors/core/MyTransport.cpp: In function 'void transportSetRoute(uint8_t, uint8_t)':
/home/szymex/Arduino/libraries/MySensors/hal/architecture/AVR/MyHwAVR.h:54:82: error: 'eeprom_update_byte' was not declared in this scope
 #define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t*)(__pos), (__val))
                                                                                ^
/home/szymex/Arduino/libraries/MySensors/core/MyTransport.cpp:1065:2: note: in expansion of macro 'hwWriteConfig'
  hwWriteConfig(EEPROM_ROUTES_ADDRESS + node, route);
  ^
/home/szymex/Arduino/libraries/MySensors/core/MySensorsCore.cpp: In function 'void _begin()':
/home/szymex/Arduino/libraries/MySensors/hal/architecture/AVR/MyHwAVR.h:54:82: error: 'eeprom_update_byte' was not declared in this scope
 #define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t*)(__pos), (__val))
                                                                                ^
/home/szymex/Arduino/libraries/MySensors/core/MySensorsCore.cpp:140:2: note: in expansion of macro 'hwWriteConfig'
  hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID);
  ^
/home/szymex/Arduino/libraries/MySensors/core/MySensorsCore.cpp: In function 'bool _processInternalMessages()':
/home/szymex/Arduino/libraries/MySensors/hal/architecture/AVR/MyHwAVR.h:56:114: error: 'eeprom_update_block' was not declared in this scope
 #define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((void*)(__buf), (void*)(__pos), (__length))
                                                                                ^
/home/szymex/Arduino/libraries/MySensors/core/MySensorsCore.cpp:415:4: note: in expansion of macro 'hwWriteConfigBlock'
    hwWriteConfigBlock((void*)&_coreConfig.controllerConfig, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS,
    ^
/home/szymex/Arduino/libraries/MySensors/core/MySensorsCore.cpp: In function 'void saveState(uint8_t, uint8_t)':
/home/szymex/Arduino/libraries/MySensors/hal/architecture/AVR/MyHwAVR.h:54:82: error: 'eeprom_update_byte' was not declared in this scope
 #define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t*)(__pos), (__val))
                                                                                ^
/home/szymex/Arduino/libraries/MySensors/core/MySensorsCore.cpp:499:2: note: in expansion of macro 'hwWriteConfig'
  hwWriteConfig(EEPROM_LOCAL_CONFIG_ADDRESS+pos, value);
  ^
exit status 1

What Arduino IDE version are you using? What platform (Windows, Linux, Mac)? Using IDE 1.8.1 on Windows, I added the MySensors library, opened the Gateway Serial example, set the device to Arduino Leonardo, and it compiled just fine.

I am missing something? There is practically no code and #include is missing the filename.

@gre_gor this appears to be just the example code from the MySensors library, unchanged.

The sketch and library are here: https://github.com/mysensors/MySensors. The sketch in that repository does have the full #include statement and it compiles for Leonardo fine for me to with Arduino IDE 1.8.5.

Also asked at: https://github.com/mysensors/MySensors/issues/1007 and https://forum.mysensors.org/topic/8045/problem-with-compiling-gatewayserial. If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information.

It's arduino ide 1.8.4 on linux mint 18.1

Fixed here:
https://github.com/mysensors/MySensors/issues/1007
I needed to update Arduino IDE, reinstall board definitions and MySensors library


text:
Store RAM and PROGMEM strings in one variable
I want to store a number of strings in an object. Currently I have:
class MyClass {
  int numStrings = 0;
  ??? strings[20];

  public:
    void addString(const char str[]);
    void print();
};

void MyClass::addString(const char str[]) {
  strings[numStrings] = str;
  numStrings++;
}

void MyClass::print() {
  for (int i = 0 ; i < numStrings ; i++) {
    Serial.println(strings[i]);
  }
}

Serial.println() works with strings in RAM and in PROGMEM alike.
Is there a type that I can give to my strings variable that allows me to store both types of strings?
MyClass s;

s.addString("This should work");
s.addString(F("This should work, too"));

Is there a type that I can give to my strings variable that allows me to store both types of strings?

No, but you could tag the pointer or add a vector with type information or ultimately use a class hierarchy (BaseString<-SRAMString, PROMEMString).
As a pointer is 16-bit (Arduino Uno) and there is limited amount of SRAM it is possible to add a magic number to pointers to determine the address space.
Obviously the print() member function will have to use the right type and you will also need a new addString for F() strings. Check how F() is defined.
Cheers!

I don't know how to "tag a pointer", but when working with a magic number I would make that a void pointer?

Here is an example of mapping EEPROM, SRAM and PROGMEM to a single address space: https://github.com/mikaelpatel/Arduino-Shell/blob/master/Shell.h#L1058

The simplest scheme is to use the sign bit for PROGMEM, i.e. add 0x8000 to PROGMEM pointers.

I don't get it. So when I get a __FlashStringHelper* I add 0x8000 to mark that it points to PROGMEM. But then I still can't store that in a const char* variable, can I?

Tell the compiler what you want: uint16_t str = 0x8000U + (uint16_t) str_P; strings[numStrings++] = (const char*) str;

That is the answer I was looking for. :) Is there a type...? -> Yes, uint16_t.

Actually the standard type (stdint.h) is uintptr_t. Here are the details: http://en.cppreference.com/w/c/types/integer. Please remember that the standard was not intended for a Harvard architecture as the AVR.


text:
ACS712 to build doorbell sensor - Arduino Hangs up
I have a ACS712 module that I am connecting to my Arduino Uno to read the current spike when my door bells rings (and then trigger some events in my "sketch").
In my country doorbells use the ~115 VAC at ~60Hz. So, I just opened the doorbell and connected the ACS712 module in series.
I do not know how much amperage my doorbell draws, but it is hardly the 30A supposedly supported by the module.
At this point I am not connecting the OUT pin to the Arduino, only VCC and GND to the +5V and GND of the Arduino Uno. (I am also tried connecting the OUT pin to A2 in the Arduino).
What happens is that as soon as I ring the doorbell the Arduino hangs up. Sometimes I even have to physically unplug the Arduino to get it back to life.
It doesn't necessarily happens in the first bell, but it does not survive 3 rings in a row.
The ACS712 chip is supposed to provide 2.1 kVRMS of isolation... it doesn't seem likely that the "kickback" from the bell would be 2100 VAC... so I cannot imagine how/why my Arduino is hanging up, when it is supposed to be completely isolated from the AC (that's the whole point of the Hall Effect current sensor).
I added some capacitors to the VCC/GND pins with no luck.
So... any ideas on 1) how to protect the Arduino from hanging up?, 2) what is making the Arduino hang up?.

Your second link to the reference sheet points to the downloads folder on your PC - we can't see there :)

How are you powering the Arduino? And what is the voltage (measure with a multimeter between VCC and GND) when the doorbell is pressed? If it drops much below 5v, the arduino may decide there is not enough power and shut down, to be reenabled when the power comes back.

Powering Arduino: USB port of laptop to be able to monitor what is going on. 2) VCC voltage: I haven't been able to measure it (due physical layout, and also because the doorbell doesn't last even 1 second), also: why would the voltage change? the module is supposed to isolate the the two circuits. I'll try to measure it (again) anyways.

The module will isolate the doorbell, but the module will also use some power to do the measuring. I have had issues in the past where running a motor, which draws a high current, from a battery, caused the voltage to drop down too low for the Arduino to keep running. Some USB ports have over-current protection on them, resulting in the same effect.

There are two probable solutions to your problem:

The ACS712 is a hall effect based sensor and also door bells have a solenoid attracting a hammer to hit the bell. Try and place the sensor away from the bell, this could avoid any possible magnetic interference. (This is less likely to happen but there is a fair amount of chance)
May be, there is a problem with the code OR the laptops USB. Connect the Arduino to the sensor and the OUT pin to an analog input. Run the following code:

  void setup()
  {
     Serial.begin(9600);
  }
  void loop()
  {
     Serial.println(analogRead(A2));
  }

If this doesn't work, probably there's a problem with the sensor or the connections.
Give me more details about your connections, code and post a picture of your project for more help.


text:
Arduino Yun not showing up in Windows or Linux [software issue?]
I've got my Arduino Yun (less than a year old) connected to my computer via a USB cable. The device seems to be on (that is, the lights are all on). However, the Arduino is not showing up in either the /dev/ttyACMx (linux) or COMx on my Windows boot. Does anyone have any suggestions for why this could be? I've tried to reset the Yun to factory settings by holding the WRT RST button for 30+ seconds, but that still didn't fix anything.
I'm afraid that I'm now looking at a bricked Yun; if this is the case, what could / should I do?
Thanks!
EDIT: I have the 1.6.0 version running. I'm indeed using a microUSB cable to connect to the arduino via USB. If I'm connected to the Arduino-90xxxxxxx wifi network, I can still push sketches to the arduino. However, I'm unable to see the arduino over serial, both in the IDE / terminal. The only port I see in the IDE is 192.168.240.1
EDIT2: I was able to see my Arduino Yun in the IDE again after flashing the blink sketch via wifi and resetting the 32u4. This makes me think that it's a software issue due to the sketch I'm pushing. Is there something that I could be calling which would make the Arduino unable to connect via serial?

Can confirm that connecting to the YUN via WiFi and flashing some simple program like the blink sketch to it will fix the issue. Would suggest moving your EDIT2 to a self answer so it's obvious there is a solution found.


text:
Getting inverse values of acceleration and tilt for the MPU 6050
I'm using the I2C library to connect to a GY-521 board and, when executing the getAcceleration() methods I get gyro values and viceversa..
This is my setup (I'm using a proto shield but that shouldn't change anything as far as I understand):

It follows this schematic:

And this is the code I'm testing:
#include "Wire.h"

#include "MPU6050.h"

MPU6050 accel;

int16_t ax, ay, az;

void setup() {
    Wire.begin();
    Serial.begin(9600);
    Serial.println("Initializing I2C devices...");
    accel.initialize();
    Serial.println("Testing device connections...");
    Serial.println(accel.testConnection() ? "Connected" : "Connection failed");
}

void loop() {
    accel.getAcceleration(&ax, &ay, &az);
    Serial.print("acc x:    ");
    Serial.println(ax);  // This prints the gyro value of the Y axis!
    delay(1000);
}

I don't think it has to do with the wiring since inverting the 4 and 5 analog pins yields zero values.
Is this a problem with the library? Or with my chip?

I think this has to be a problem with the library, or with your method of discerning which set of values is the accel and the gyro I guess. Gyro should be the one totally zerod out when the sensor is sitting still. Where did you download the library from?

Yup I'm sure that's the gyro value (I even have a video if you need it). So I'm guessing it's the library... I may just wrap it up with the correct names

Personally I use accel.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); which yields all values generated by the sensor.
Just to be certain, if you use accelgyro.getAcceleration(&ax, &ay, &az); you get Gyro data and if you use accelgyro.getRotation(&gx, &gy, &gz); you get Accelerometer data?
If you actually get the values the wrong way around, you could just use the variables in the 'wrong' way, I know this is not how it should work.

There are a lot of libraries, I wouldn't use the accelerometer library in wire, download and add the I2Cdev library, you can get it on a variety of different sites like github.com

Would you please develop your answer further? Currently this is not the typical kind of useful answer: no real value, no detail, no reason why "you wouldn't use the accelerometer library..." For me, you could have posted this as a comment to the question.


text:
arduino ethernet shield
I bought a ethernet shield for my Arduino Uno. I plug it my Arduino and PC with ethernet cable. There is all led is working on ethernet shield. But when i try to examples about ethernet which is in Arduino IDE as "DHCPChatServer" example.
I hope to see;
"Trying to get an IP address using DHCP"
"My IP address: 192.168.1.177"
But I just see "Trying to get an IP address using DHCP"
Any problem with my ethernet shield?

Are you running a DHCP server on the PC you connect the Arduino to? If not, it cannot obtain an IP. You may want to use a static IP instead.

I tried static IP but it didn't work.

@user3748265 What static IP address did you try? Only certain ranges are valid for local networks.

I check out ip address with ipconfig and i set up my ethernet with this ip address. IP address is 192.168.2.101 subnet mask:255.255.255.0 gateway:192.168.2.1

When you connect your arduino directly to the PC using the ethernet cable, neither of them have any information about the network.
Most ethernet devices attach to switches, routers, and gateways, and one or more of these devices host network services such as DHCP, DNS, or provide a way to obtain those services.
Without DHCP, for instance, neither your PC nor the Arduino know what IP adress to use, what their netmask is, and whether there's a gateway to other IP addresses.
You have a few options:

Follow the Automatic Private IP Addressing specification, which windows computers default to when no DHCP server is present or available. Set the IP address of the Arduino to 169.254.x.y where x and y are randomly chosen numbers between 0 and 255, and set th netmask to 255.255.0.0.  The windows computer should have done the same if no static IP address was set - use ipconfig on the windows command prompt to find its IP address.  Your computer and arduino should be able to talk to each other.
Set up a router. It doesn't need to connect to the internet, it just needs to connect to both the PC and the Arduino.  It'll implement a DHCP server and make sure, at minimum, that the two devices can talk to each other and the router.
Set static IP addresses on both devices.  Set up the PC with something like 192.168.42.1 with a netmask of 255.255.0.0 and the Arduino with 192.168.42.2 and the same netmask.  Now they should be able to talk to each other.
Connect both to an existing network.  The network should already have a router with DHCP on it, so it'll take care of everything, and as a bonus you may be able to get internet access as well, which could help with testing since you can use the ethernet shield to communicate with google and other known working services, rather than trying to set up a server on the PC.

I changed my Arduino Uno with Arduino Mega and problem is solved.Thank you