text:
How to properly use volatile variables in Arduino?
I was doing a small project with an Arduino Uno. It involved interrupts as I am using encoders to measure how much the differential wheel system moves forward. My robot moves only forward. So I use only a single channel from each encoder. Here are my two interrupt routines:
ISR (INT0_vect){

      encoderRPos = encoderRPos + 1;

}

ISR (INT1_vect){

  encoderLPos = encoderLPos + 1;

}

The variables encoderRPos and encoderLPos are of type volatile int. I understand that the variables which undergoes change in any interrupt routine need to be of type volatile. This is to warn other parts of the code that use these variables that it may change anytime.
But what happened in my code was a bit strange and I could not explain it. Here is how I compute the distance moved by the left wheel:
  #define distancePerCount 0.056196868
  float SR = distancePerCount * (encoderRPos - encoderRPosPrev);
  float SL = distancePerCount * (encoderLPos - encoderLPosPrev);

  encoderRPosPrev = encoderRPos;
  encoderLPosPrev = encoderLPos;

But when I print the following on my serial monitor, I notice an anomaly:

If you look at the third column, (SL) it's value is too high just for some time. This is upsetting all my calculations.
The only clue I can get it, if I take the value of SL that I got (3682), which is always a constant, and calculate back (encodeLPos - encoderLPosPrev), I will get 65519.66, which is close to the max value of unsigned int. Which means (encoderLPos - encoderLPosPrev) is causing an overflow while both the values whose difference is taken is somewhere around 5000 only!
And I managed to solve it. It was by luck. This is how I modified the code:
  static int encoderRPosPrev = 0;
  static int encoderLPosPrev = 0;

  int diffL = (encoderLPos - encoderLPosPrev);
  int diffR = (encoderRPos - encoderRPosPrev);

  float SR = distancePerCount * diffR;
  float SL = distancePerCount * diffL;

  encoderRPosPrev = encoderRPos;
  encoderLPosPrev = encoderLPos;

I can't comprehend what has happened. Is there something about volatile variables that I should have known about?
Update: Here is the entire code if you ever want to take a look. And it's working very well after changing it to what was suggested in the accepted answer.

Your question says what the third column of output is ... what are the other columns?  Please edit question and add column headings

@jwpat7 I intentionally removed them because that will only confuse  the reader. But the question has already been answered well by Majenko.

It is hard to give detailed answers from your snippets. could you explain why it is not happening randomly but at a specific time every time I run the code? Also why does it give the particular value?  - I could probably do that if I saw the whole code. Meanwhile read this: http://www.gammon.com.au/interrupts

@NickGammon Here you go: http://paste.ubuntu.com/14085127/

3683 / .056196868 = 65537 so it looks like it incremented at the wrong moment, yes? You are accessing a variable that might be changed in an interrupt multiple times in that code, so getting a local copy, while interrupts are off, would be much safer.

@NickGammon Yes, that's what I ended up doing.

You need to learn about critical sections.
What is probably happening is that the variables are being changed by the interrupt routines mid-way through the calculations. Your 'fix' reduces the time spent doing the calculation with the volatile variables thus making it less likely that there is a collision.
What you should do is copy the volatile variables to local variables with interrupts disabled for that brief period.
cli();
int l = encoderLpos;
int r = encoderRpos;
sei();

Because the Arduino is an 8 bit CPU it takes multiple assembly instructions to perform mathematical operations on 16 bit values. Floating point is even worse using many many instructions for a simple addition. Division and multiplication use considerably more. An interrupt has plenty of opportunity to fire during that list of instructions. By doing an assignment like that and then using the new local variables in your calculations the instructions needed to deal with the volatile variables is kept to an absolute minimum.  By turning off interrupts during the assignment you guarantee that the variables can't ever be changed while you are using them. This snippet of code is called a critical section.

This might just be the case. Just wondering, could you explain why it is not happening randomly but at a specific time every time I run the code? Also why does it give the particular value?

Here is a great reference to the cli/sei. http://www.nongnu.org/avr-libc/user-manual/optimization.html#optim_code_reorder. With the memory barrier volatile declaration is not really needed in the code above. Here is some fun reading on this subject. https://www.kernel.org/doc/Documentation/volatile-considered-harmful.txt

@MikaelPatel Nice, but not that relevant for MCUs. Volatile is required in this situation to prevent the compiler from optimzing out instances where it thinks it's not being used (value never changes). The cli/sei is there to make the operation atomic WRT the only other thread (interrupts) that execute.

Did you try compiling the code with and without volatile? But with the critical section (cli/sei). What I am trying to discuss is the concept of the memory barrier and how that provides volatile access (and correct ordering) from the compiler with having to declare variables as volatile. Most programmers are taught that any variable accessed in an ISR must be declared volatile but there is so much more to this story.

I don't think the compiler has much concept of what cli() and sei() do and how that would affect things like optimizing out of variables that shouldn't be optimized out.  All sei() and cli() do is manipulate the global interrupt enabled flag in its register. They do nothing for the flow of code.

After all, they just map to an assembly instruction: # define sei()  __asm__ __volatile__ ("sei" ::: "memory")

It is the magical word "memory" that tells the compiler that it is also a memory barrier. https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html

That stops instruction re-ordering. It has nothing to do with the complete removal of suspected dead code.

@MikaelPatel Here's an extreme example (extreme so it forces the kind of optimization I am after demonstrating): http://pastebin.com/u9bfiN4R

@Majenko That was an extreme example. Did you try both volatile and cli/sei? A contra example is Cosa/RTT https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/RTT.cpp, it has no volatile. All accesses are synchronized instead.

/*
Hi all and thanks for sharing.
From my personal experience here is what I found useful
"A DTMF decoder stores the last DTMF code in bytes in its memory
It's STQ pin goes HIGH every time a a new DTMF is detected
This is just part of the code focused on ISR (Interrupt) "
   Tips when using ISR with Arduino nano and IDE 18.19

1: HIGH or LOW only,  RISING of FALLING will not get triggered properly with Nano using external digital interrupt.
2: Watch out when using LOW. As per using HIGH in example you need to use  flags(event bytes) and possible counters.
3: When you type the attachInterrupt don't use brackets for the void of function you are you are calling, or every time the ISR is triggered it will go from begging of code re-initializing/resetting all global variables no matter if you declare them volatile or static!
4: Delay doesn't work only delayMicroseconds()
5: Keep it short, byte size variables and no complex math if possible
6: Arduino nano external digital ISR pins are 2,3
7: Don't run the void you call in your ISR in the loop().
8: Keep in mind all other comments posted from the other programmers.
*/
/////////////////    Example /////////////////////////////

byte CFlag;     // GLOBAL

byte Counter;   // GLOBAL

#define STQ  3  // GLOBAL

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

pinMode(STQ, INPUT);

attachInterrupt(digitalPinToInterrupt(), DragonBalls, HIGH);
//WhenSTQ PIN GOES HIGH it runs a void function called DragonBalls()

}//end setup

void DragonBalls()

{
    Dpin = digitalRead(STQ);
    delayMicroseconds(10000);
    if      (Dpin == HIGH &&  CFlag ==LOW) {
                                                CFlag=HIGH;
                                                Counter++ ;
                                            }//end if

    else if  (Dpin == LOW  &&  CFlag == HIGH) {
                                                CFlag=LOW;
                                                DragonPrint();//Serial.print staff

                                                }//end else if

}// end DragonBalls(void)

void DragonPrint()

{
    Serial.print(CFlag);
    Serial.print(" = CFlag, Counter = ");
    Serial.println(Counter);

}//end void DragonPrint

what question does this answer? I am sure not that one above


text:
Can I use analogRead to read a digital pin?
analogRead(nGPIO_max + lockerVal) were nGPIO_max(maximum digital pins in Arduino Uno is 13) and lockerval is 2. Which pin is it reading?

13 + 2 = 15, so pin 15.  I'll give you a clue: A0 is pin 14.

To answer the question in the title: No, you cannot use analogRead() to read a digital pin. A digital pin cannot behave as analog because it isn't connected to the ADC (Analog to Digital Converter).
If you call something equating to analogRead(15) on an Uno, then it should read pin A1. You can see the pin assignments in the board-specific versions of pins_arduino.h (shipped with the IDE):
static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;

Using those raw numbers directly is generally not a good idea though as it obscures your code's meaning, and will potentially make it non-portable to other boards. It's better to call something like analogRead(A1).
It's worth noting that the Arduino library fudges the pin numbers slightly. Calling analogRead(1) has the same result as calling analogRead(A1). That means that even if you tried to use analogRead() on a digital pin, it might actually end up reading an analog pin instead. Alternatively, it might just return a meaningless result, depending on the pin number you give it.

source: Stack Exchange

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

sort: votes


text:
arduino uno external power supply
I have an arduino uno which is powered by batteries. I have 6 AA-Batteries (1,5V each) connected to Vin and GND.
Thats cool because I don't have any cables and works pretty good.
The reason I need 6 AA batteries is, that I have a SIM900-module connected to my arduino uno. My USB Port (5V and 500mA) and my standard external power supply (9V and 1A) doesn't deliver enough current for the SIM900. But with the batteries the SIM900 gets enough power (current).
But there is the problem, that the batteries get sucked empty pretty fast and i don't want to exchange them every day. :-)
I searched for an power supply which can deliver 3A with 9V and found one. But i'm not sure if the arduino uno can handle that input via the on-board power-jack? The reason I want a 3A power supply is, that some users on the internet say that the sim900 sometimes uses more than the maximum current written in the documentation (which is 2A).
I'm an electronic noob.
So is there a risk if I try to use the 9V-3A power supply?
Does the arduino only pull the power it needs? So when it needs only 900mA, it only takes 900mA even if the power supply can deliver 3A?
As far as I know, it should work, because the batteries deliver as much current as the arduino (ad sim900) needs. So the batteries don't have an ampere limit, right?

I believe the Arduino uno is rated for up to 12V on VIn, sparkfuns website should have the spec. If it is 12V then you are OK.

The Arduino itself has a limit of about 800mA. That is imposed by the voltage regulator that converts the incoming voltage to 5V.
If you need more than 800mA then you need to provide your own regulated 5V power source and feed it in to the 5V pin (not VIN).
Suitable power sources are mobile phone chargers (modern USB ones).  They generally come in multiples of amps.
And to answer your theory question - the current is the maximum that the supply can provide. It's the voltage that is fixed and the current varies depending on the load.

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


text:
2 Channel Relay normal open is not working with NodeMCU but led on board light up
I am pretty new to NodeMCU (ESP8266) and Arduino IDE in general. I followed various documentation / blogs to set up 2 Channel Relay with NodeMCU chip.
Below is sketch code for it.
#include<CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial

#define LEFT_GARAGE 4
#define RIGHT_GARAGE 5

char ssid[] = "XXXXXXXXXXXXXXXXXXXXXXXX";
char password[] = "XXXXXXXXXXXXXXXXXXXXXX";

char username[] = ""XXXXXXXXXXXXXXXXXXXXXX";";
char mqtt_password[] = ""XXXXXXXXXXXXXXXXXXXXXX";";
char client_id[] = ""XXXXXXXXXXXXXXXXXXXXXX";";

void setup() {
  Cayenne.begin(username, mqtt_password, client_id, ssid, password);
  pinMode(LEFT_GARAGE, OUTPUT);
  digitalWrite(LEFT_GARAGE, HIGH);
  pinMode(RIGHT_GARAGE, OUTPUT);
  digitalWrite(RIGHT_GARAGE, HIGH);
}

void loop() {
  Cayenne.loop();
}

// Left Garage Door
CAYENNE_IN(0){
  int currentValue = getValue.asInt();
  digitalWrite(LEFT_GARAGE,!currentValue);
}

//Right Garage Door
CAYENNE_IN(1){
  digitalWrite(RIGHT_GARAGE,!getValue.asInt());
}

On relay board I tried to connect wire in 2 different configuration.
1st Config:
vcc -> 3.3v from NodeMCU
in1 -> D1/GPIO 04 from NodeMCU
in2 -> D2/GPIO 5 from NodeMCU
GND -> GRD from NodeMCU

2nd Config:
vcc -> 5v USB from NodeMCU
in1 -> D1/GPIO 04 from NodeMCU
in2 -> D2/GPIO 5 from NodeMCU
GND -> GRD from NodeMCU

In 1st config, On relay board respective LED's are turning on when Cayenne buttons are pressed but when I check for continuity on multi meter I don't get anything.
In 2nd config, no LED and no continuity.
am I missing something here? Any feedback/comments are highly appreciated.

Your second configuration is right because from picture of relay module it clear that it requires 5V supply.
 relay working principal is:

when the signal port(in1/in2) is at low level, the signal light will light up and the optocoupler (it transforms electrical signals by light and can isolate input and output electrical signals) will conduct, and then the transistor will conduct, the relay coil will be electrified, and the normally open contact of the relay will be closed.
When the signal port(in1/in2) is at high level, the normally closed contact of the relay will be closed. So you can connect and disconnect the load by controlling the level of the control signal port.

As you mentioned that in second configuration there is no LED glow. For find out solution of your problem, you have do one test. Test voltage level of D1/D2. Just make connection on breadboard as mentioned in image.
If voltage level is correct that it might be problem with your relay module.
Also I have attached here relay connection reference for your directness.


text:
Arduino motor and motor driver
I have a little problem. I have a motor driver (L298N). When I engage in electricity, my 2 motors start and after 5 second stop. Then they stop for about 2 seconds, and then start and in a moment (0.5 second) turn off. This make still around (go about 0.5 s, stop for 2 seconds...). And my motor driver is very hot after 1 minute.
Is it possible that it is because of weak voltage? (The motor driver is for 6-35 V, and I have a 6 V battery).

L298n:
enter image description here
There is my code on Arduino:
const int motorPin1  = 9;
const int motorPin2  = 10;
const int motorPin3  = 6;
const int motorPin4  = 5;

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() {
  forw(3000);
  back(3000);
}

int fast = 255;

void forw(int timer) {
  analogWrite(motorPin1, 0);
  analogWrite(motorPin2, fast);
  analogWrite(motorPin3, 0);
  analogWrite(motorPin4, fast);
  delay(timer);
}

void back(int timer) {
  analogWrite(motorPin1, fast);
  analogWrite(motorPin2, 0);
  analogWrite(motorPin3, fast);
  analogWrite(motorPin4, 0);
  delay(timer);
}

Show how you have things wired.  The 2 seconds off sounds like the board is resetting and you're waiting through the bootloader.

Also what is the current draw of the motors?  Do you have a part number or datasheet?  The driver getting hot suggests that you're running too much current through it.  These little drivers cannot route much current.

I add 9V battery and it go good, but after first back() function stop, and after 2 second back() again, but slowly. There is scheme: link

And there is chassis: link

Please do not vandalize your post. Contributions to Stack Exchanges are subject to the SE Terms Of Service. This includes "You agree that all Subscriber Content that You contribute to the Network is perpetually and irrevocably licensed to Stack Exchange under the Creative Commons Attribution Share Alike license.". Since people have taken the trouble to answer your question, deleting or vandalizing the question is impolite.

I ran the code on my arduino(kinda old), when I checked with my multimeter I noticed that the 5th PWM pin didnt osciallate every 3 seconds, could you please try the below code where I changed the 5th pin to 3rd PWM pin, also please change the connections on the l298 board.
const int motorPin1  = 9;
const int motorPin2  = 10;
const int motorPin3  = 6;
const int motorPin4  = 3;

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() {
  forw(3000);
  back(3000);
}

int fast = 255;

void forw(int timer) {
  analogWrite(motorPin1, 0);
  analogWrite(motorPin2, fast);
  analogWrite(motorPin3, 0);
  analogWrite(motorPin4, fast);
  delay(timer);
}

void back(int timer) {
  analogWrite(motorPin1, fast);
  analogWrite(motorPin2, 0);
  analogWrite(motorPin3, fast);
  analogWrite(motorPin4, 0);
  delay(timer);
}

The L298 is a very old, obsolete design based on bipolar transistors, which means it has a lot of internal losses.
The energy consumed in those losses shows up as heat.
It also has some degree of overload or overtemperature protection, so what you are observing is an automatic shutdown.  Or perhaps, your motor is causing the battery voltage to sag and resetting your Arduino at which point the sketch resumes after a bootloader delay.  6v is really too low an input voltage to the Arduino's regulator, but too high for direct input without the regulator.
You need to make sure that the current draw of your motors is reasonable, and you likely want to replace the terrible L298 with a more modern, low less FET driver.  You will need to select one rated for the actual current draw of your motor: you should consider not only free rotation of the motor, but the increased current draw if it is mechanically stalled.


text:
Uploading Arduino bootloader to ATmega32U4 with another Arduino?
I am in a situation where it is useful if I can upload a bootloader into an ATmega32U4 using another Arduino like this, for ex:https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard. I have a different circuit though.
Is there a reason to believe that this can't be adapted to ATmega32U4?
Are there any important differences between the ATmega328P and ATmega32U4, that I have to take into account for this to work?

Which Arduino board are you using as the programmer?

I entend to use arduino uno

The only difference you have to take into account is that if you're using an ATmega32U4 board such as Leonardo the SPI pins are not broken out to the pin headers along the edge of the board as is the case with the Uno shown in the tutorial you linked. Instead you should connect the programmer board to the ICSP header pins on your ATmega32U4 board, where the SPI pins are broken out:

MISO: ICSP-1
MOSI: ICSP-4
SCK: ICSP-3

So this means you can't follow the wiring shown on the tutorial exactly but it should be very easy to adapt that tutorial to your needs.


text:
Clone vs Counterfeit (Arduino)
On this page on Arduino's website, it states

"HUNDREDS OF COMPANIES AROUND THE WORLD ARE USING IT [Arduino Software] TO PROGRAM THEIR
  DEVICES, INCLUDING COMPATIBLES, CLONES, AND EVEN COUNTERFEIT."
  (Emphasis Added)

With open source electronics, what is the difference between a clone, and a counterfeit?

i think when it is COUNTERFEIT, it also uses the same name. like an imitation brand. but CLONE just copies the circuitry under another name.

Why would you migrate this Nick... The distinction between clone and counterfeit is not specifically about the Arduino, the same thing could have been asked about the Raspberry Pi, the RepRap or SparkFun products, for example.

I agree that my question should have been kept in electronics.  It can apply to any device.  If anything move it to open source as that is broad but related.

The question is based on Arduino and fits in Arduino.SE (Nobody would've migrated it towards EE.SE from Arduino.SE). And, EE.SE seems to have an aversion from any question where the word: "Arduino" is used. Which might be a good thing. Since it gives Arduino.SE a reason to live. But it does indeed feel a little odd or "agressive" to some extent.

This a reference to the terminology defined in Massimo's https://blog.arduino.cc/2013/07/10/send-in-the-clones/ essay, right?

This is not gospel, but here is what those terms are generally used to indicate (as I understand it):

compatible: a dev board which is compatible with the Arduino IDE/toolchain. The Arduino UNO uses an ATmega328 MCU, while other platforms may use different MCUs i.e. there are multiple MCUs that are compatible with the Arduino IDE. It may or may not have the same form factor. Keep in mind that this term can also be used for shields, "Arduino-compatible" shields are add-on boards that are meant to mate with an Arduino. The Sparkfun RedBoard is an example.
clone: a dev board which has the same (or very similar) circuitry as an Arduino and the same physical board/layout. They are branded differently, but are, for all intents and purposes, exactly the same as a real Arduino. These boards are permitted under the open-source licensing of the Arduino design. An Freeduino might be an example.
counterfeit: a dev board which is identical to an original Arduino, and is branded and sold as an original Arduino. As I understand it, the open-source licensing does not permit this, however, this does not deter the flood of shops churning out counterfeit Arduinos. A search on eBay or Aliexpress will turn up loads of examples; note the Arduino guide to spotting counterfeits, in general, the silkscreen is blue and the quality of assembly is not quite as good.

The difference between "compatible" and "clone" is a bit blurry, but it's not really important. The main difference between counterfeit and non-counterfeit is that counterfeit Arduinos are boards that are not sold by Arduino but are branded as such.

With open source electronics, what is the difference between a clone, and a counterfeit?

Counterfeit: the vendor says/implies that the Arduino board is produced by Arduino/Genuino, an "original", but it is not. The screen-print is the same, but looking closer at the components and PCB there are some differences. You think you can turn to Arduino/Genuino for product support but you cannot.
Clone: the vendor states that the board is a "compatible copy", uses all the open-source bill-of-material, schematics, etc, (or slightly changed for cheaper components) when produced, and it is obviously not produced by Arduino/Genuino. You know that you cannot turn to Arduino/Genuino for product support.
The punishment for selling and buying (!!) counterfeit fashion in Italy is very severe.
Counterfeiting is a trademark violation issue.
Cheers!

I'm not sure how the buying counterfeit fashion in Italy is related, but that's an interesting point. It might be usefull to note that originals or clones of known brands are often of a higher quality. But that counterfeit might be useable for hobby projects (but often not in a final product).

@Paul the fact counterfeits might be usable in an hobby project doesn't change the fact using, buying or selling counterfeits breaks the law. For hobby projects you should use cheap clones: never use counterfeits, just by buying them you are supporting thieves.

@Roberto it's completely legal to copy the Arduino hardware. But not to copy the brand(name) I believe.

@Paul that's correct and it's exactly what distinguishes a clone from a counterfeit. What I'm saying it's ok to buy cheap clones (which is something I often do), but I strongly advice against counterfeits, no matter if it's for hobby projects or not.

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


text:
Pass a member function pointer to a method of a foreign class (EDB Lib)
I'm currently working on my own arduino library and I'm becoming exasperated with the following problem: I want to store data with the extended database library (https://code.google.com/p/arduino-edb/) on a sd card. I tried to follow and adapt the instructions on this page and I gave my custom library a property "File dbFile" as well as a property "EDB db". Additionally I have to pass two function pointers to the constructor of the EDB library. So my custom library got two more properties: a writer and a reader function. My class looks roughly like that:
class myLib
{
   public:
      myLib();
      ~myLib();
      void configWriter( unsigned long address, byte data );
      byte configReader( unsigned long address );
      File dbFile;
      EDB configDB;
}

...so far so good. But here comes the pain in the ... When I'm trying to instantiate a new EDB object in the constructor of my class by passing two pointers to the member functions I'm constantly getting an error. Here is how I call the constructor of the EDB library:
configDB = new EDB( &myLib::configWriter, &myLib::configReader );

I get the following error:

no matching function for call to 'EDB::EDB()'
[...] note: candidates are:
note: EDB::EDB(void ()(long unsigned int, uint8_t), uint8_t ()(long
  unsigned int))
       EDB(EDB_Write_Handler *, EDB_Read_Handler *);

The prototype of the EDB constructor looks like this:

EDB(EDB_Write_Handler *, EDB_Read_Handler *);

EDB_Write_Handler and EDB_Read_Handler are defined like so:

typedef void EDB_Write_Handler(unsigned long, const uint8_t);
  typedef uint8_t EDB_Read_Handler(unsigned long);

So I assume that my constructor call doesn't work because the functions that I'm passing are from a foreign class: (myLib::) and not just ()
I have no idea how to solve that problem. Does someone of you have any idea?
Thanks,
Andy
EDIT:
Here is a Minimal, Complete, and Verifiable example:
myLib.h:
#ifndef myLib_h
#define myLib_h

#include "Arduino.h"
#include <SPI.h>
#include <SD.h>
#include <EDB.h>

#define SD_CS 4
#define SD_SS 10

class myLib
{
  public:
    myLib();
    ~myLib();
    void begin();
    void configWriter( unsigned long address, byte data );
    byte configReader( unsigned long address );
    File dbFile;
    EDB * configDB;

};

#endif

myLib.cpp:
#include "myLib.h"

myLib::myLib( void )
{}

myLib::~myLib()
{}

void myLib::begin()
{
  // Init SD
  pinMode(SS, OUTPUT);
  SD.begin(SD_CS);

  // Load Config
  configDB = new EDB( &myLib::configWriter, &myLib::configReader );
  dbFile = SD.open("config.db", FILE_WRITE);
}

void myLib::configWriter( unsigned long address, byte data )
{
  dbFile.seek(address);
  dbFile.write(data);
  dbFile.flush();
}

byte myLib::configReader( unsigned long address )
{
  dbFile.seek(address);
  return dbFile.read();
}

Arduino sketch:
#include <SPI.h>
#include <SD.h>
#include <EDB.h>
#include "myLib.h"

myLib* a;

void setup()
{
  a = new myLib();
  a->begin();
}

void loop()
{
}

Have you tried passing it methods of an instance instead of the class?

new EDB( &this->configWriter, &this->configReader ); like so? already tried it. same problem...

The problem here is a common one with C++.  It basically boils down to how C++ handles member functions.
You define a member function as, say,
class myLib {
    void myFunc(int val);
};

When you call the function it's actually not defined as that - it's instead had its definition change to:
void myFunc(myLib *this, int val);

The addition of the myLib *this is an implicit parameter, and it's how C++ keeps track of its object instances when calling different functions.
So a function which expects a parameter of void (*func)(int) won't accept your method because it's actually void (*func)(myLib *, int).  Hence the error you are seeing.
There is no easy, clean, way around it that I have found as yet, I am afraid.  The closest you can do is to move the reader and writer functions outside of your class and store a global pointer to the actual class, something like:
static myLib *globalLib;
void globalConfigWriter( unsigned long address, byte data ) {
    globalLib->congigWriter(address, data);
}
byte globalConfigReader( unsigned long address ) {
    return globalLib->configReader(address);
}

Then in the constructor for your lib you can do:
myLib::myLib() {
    globalLib = this;
}

You then register the global reader and writer functions with the EDB constructor instead of the class member functions.
It does have the rather major down-side that there can only be one instance of your class since there is only one global pointer and only one pair of reader / writer functions.  There are ways of supporting a finite number of instances, but it basically involves having a reader/writer pair for each instance and allocating one to an instance when it's constructed and de-allocating it when its destructed.  Keeping track of them and knowing which object is associated with which function pair is tricky at best...

Thanks, Majenko for your easy explanation! Now I can see where the problem is. Being able to create only one instance of the class isn't a problem in my case. I'll give your solution a try and let you know how it went.

Can you post a  Minimal, Complete, and Verifiable example? We don't care what the functions do, just make up an example that demonstrates the message.

Having said that, this looks wrong:
class myLib
{
   public:
      myLib();
      ~myLib();
      void configWriter( unsigned long address, byte data );
      byte configReader( unsigned long address );
      File dbFile;
      EDB configDB;
}

Here is how I call the constructor of the EDB library:

 configDB = new EDB( &myLib::configWriter, &myLib::configReader );

OK so myLib is a class, not an instance of a class.

The prototype of the EDB constructor looks like this:

    EDB(EDB_Write_Handler *, EDB_Read_Handler *);

So you want an instance of EDB_Write_Handler.

Let's say that EDB needed a dog and a cat. You don't pass "dog" and "cat" you pass "Fido" and "Fluffy". They are instances of the classes.

You have this:
configDB = new EDB( &myLib::configWriter, &myLib::configReader );

The constructor for EDB expects two functions:
EDB(EDB_Write_Handler *, EDB_Read_Handler *);

These are declared like this:
typedef void EDB_Write_Handler(unsigned long, const uint8_t);
typedef uint8_t EDB_Read_Handler(unsigned long);

These are static functions, that is, they cannot be class functions. Why not? Because a class function has an implicit pointer this which points to this instance of the class.
So, you cannot pass a non-static class-function to the EDB constructor.
Now you can make the functions configWriter and configReader static, but then they can't access class variables (eg. dbFile) because they belong to an instance of the function.
I've tried fiddling around with your code, but without a clear understanding of your intentions, I can't get it to compile. Do you mean to derive your class from EDB?
Why do you even want a class myLib? Are you planning to have multiple instances of it? If so, why? If not, why make a class?

Thanks for your reply Nick! I'm quite familiar with the difference between a class and an instance (aka object) of a class but I'm a little unsure when it comes to the syntax of c++. Thanks for your suggestion! I've added a minimal, complete, and verifiable example.

See amended answer.

This is not at all an Arduino problem. It is a C++ problem.


text:
Interface Processing with Arduino to operate a servo by MouseX
I want to make a servo change its angle using my mouse. When I move mouse horizontally the servo should change its angle correspondingly.
This is the sketch I wrote, unfortunately the servo doesn't move one bit. HELP.
Processing Code:
import processing.serial.*;
Serial port;
void setup() {
  size(256, 150);
  println("Available serial ports:");
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());
  port = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
  // draw a gradient from black to white
  for (int i = 0; i < 256; i++) {
    stroke(i);
    line(i, 0, i, height);
  }
  // write the current X-position of the mouse to the serial port as
  // a single byte
  port.write(mouseX);
  println(mouseX);
}

Arduino Code:
#include <Servo.h>
Servo myservo;
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the servo:
  myservo.attach(10);
}
void loop() {
  byte pos;
  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    pos = Serial.read();
    // set the angle of the servo:
    myservo.write(map(pos, 0, 255, 0, 180));
  }
}

Welcome to Arduino:SE. What exactly is your problem here? What do you expect the code to do? What does it actually do? What have you tried to diagnose the problem? Please help us to help you.

Hi @sempaiscuba, thanks for replying. I'm trying to operate a servo using Arduino and Processing. what I wanted it to do was, i'd move my mouse horizontally on a canvas and the servo would change the angle accordingly and simultaneously.
The problem is the Servo isn't moving at all, the circuitry is fine.

Arduino side looks fine. This is most likely a Processing problem, not an Arduino problem.

@Majenko I Didn't see that coming, I thought Processing was fine. Wait, is it because, mouseX is more of an int than a Byte?

This, println(Byte.valueOf(Integer.toString(mouseX))); brings out an error: Value out of range. Value: 128, Radix 10.

Edit your question to explain what you're actually asking.

@per1234 done..

What version of Processing are you using? I just tested this with v3.3.6 and it works ok. (I didn't hook up a motor, just displayed the values and they were 0-255).

When you try and solve a problem you want to focus on just one part at a time.  If I have understood what you are doing correctly then you are trying to:

Get a computer to talk to an Arduino over serial
Get an Arduino to position a servo
Get an Arduino to decode information sent by the computer
Get the computer to code the information
Get the computer to draw graphics.

You can try and ice a cake, feed a baby, talk on you mobile and drive a truck all at the same time, it doesn't mean its a good idea.  When you crash what was the cause?  You haven't got a clue, you were too busy trying to do all that not analyse what is happening at the same time.
So, what I'm trying to say is break it down.  Normally with motors the problem is related to power, people assume that the Arduino can provide enough power for a servo, that's not always the case.
I would:

Write a program that sets the servo to 10 hard coded positions.
Write a program that sets the servo to the position manually entered on the command line.
Write a program that draws the gradient, interprets the user entry and writes the command to be sent to the Arduino to the command line.
Write a program that runs on the Arduino and echoes what it receives over the serial line to some "other output mechanism"  (Connecting the computer via SoftwareSerial might be a good idea).

And once they are all working as you expect connect them all together and it will all magically work :)
(Sorry if I'm teaching you to suck eggs, if you have already done all this ignore me)


text:
Writing a new function: configMotor(speed, direction)
How can I create a function that can control a DC motor's speed and direction?
configMotor(int speed, direction){
   pwmVal = speed;

   //need help with code for picking direction
}

//move FORWARD
void moveForward(){
  analogWrite(pwn, pwmVal);
  delay(sDelay);
  digitalWrite(ina, HIGH);
  digitalWrite(inb, LOW);
}

//move BACKWARD
void moveBackward(){
  analogWrite(pwn, pwmVal);
  delay(sDelay);
  digitalWrite(ina, LOW);
  digitalWrite(inb, HIGH);
}

I don't know what to write in the code for configMotor function so that it can choose going forward or backward.

All you need to do is pass a parameter to config that says forward or backwards (was direction).
This parameter then sets the values of that the pins INA/B will be set to, because they are opposite.
Does that make sense?  If not add a comment with you question and I'll try and clarify.
int inaDirection = LOW;
int inbDirection = LOW;

void configMotor( int speed, bool forwards = true)
{
   pwmVal = speed;
   inaDirection = forwards?HIGH:LOW;   // ? and : are the same as an if statement, just more compact.
   inbDirection = forwards?LOW:HIGH;
}

// move no need for forward and reverse anymore
void move()
{
    analogWrite(pwn, pwmVal);
    delay(sDelay);
    digitalWrite(ina, inaDirection);
    digitalWrite(inb, inbDirection);
}

why is bool forwards set to equal to true in the parameter declaration?

bool forwards = true means by default the function should go forwards.  You can call configMotor(40); or configMotor(40, true);they both mean the same thing, where asconfigMotor(40, false);` means go backwards.  I added the default value to make it clearer to you that true meant forwards, I guess it didn't work :)


text:
Portal gun sound effects and lights
I'm building a portal gun from the game Portal and I'm struggling with the wiring for the lights and sound. I've the lights working using the first image from Instructables and adding more LEDs shouldn't be a problem. I'm trying to add the SD card and speaker so when you flick the switch, as well as the lights changing, the firing sound is played. Image 2. everything is wired quite nicely the only change is I'm using pin 10 not 4 on the memory card.

This is my code and it all compiles fine and seems to make sense to me but I'm new to programming.
The lights work but none of the sounds play. I've formatted the SD card and also made sure the .wav files are the right format: mono 8 bit 16000 Hz. I can't work out what's wrong and why I can't get it to play the sounds.
I also have an Adafruit amp just in case it isn't loud enough but not a clue how to wire it in.
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>                       // need to include the SD library
#define SD_ChipSelectPin 10            // using digital pin 10 on arduino uno 328, can use other pins
#include <SPI.h>

void setup()
{
  // put your setup code here, to run once:
  TMRpcm tmrpcm;
  tmrpcm.speakerPin = 9;          //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc

  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin))
  {
    Serial.println("SD fail");
    return;
  }
  tmrpcm.setVolume(6);
  tmrpcm.play("1.wav");
  tmrpcm.play("2.wav");

  //set the switch input, pin 8, as an
  pinMode(8, INPUT);

  //set both the LED pins, pin 5 and 6 as OUTPUTs
  pinMode (5, OUTPUT);
  pinMode (6, OUTPUT);
}

void loop()
{
  TMRpcm tmrpcm;
  int switchValue = digitalRead(8);
  if (switchValue == 1)
  {
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    tmrpcm.setVolume(6);
    tmrpcm.play("4.wav");
  }
  else
  {
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
    tmrpcm.setVolume(6);
    tmrpcm.play("5.wav");
  }
}

Well, that first image really sums up Instructables nicely... shudder

At a guess I would say your main problem is you are defining your TMRpcm objects within the setup and loop functions, which means that as soon as that function exits the TMRpcm objects will be disposed of. I.e., it won't work. It may start playing a sound in setup(), but it will stop (and maybe even crash completely) before you even have a chance to hear it.
Your TMRpcm object must be declared globally for you to have any hope of making it work.
TMRpcm tmrpcm;

void setup() {
    // ....
    tmrpcm.speakerPin=9;
    tmrpcm.setVolume(6);
    tmrpcm.play("1.wav");
}

etc.
Another thing to note is that TMRpcm plays the sounds asynchronously. That is, it doesn't wait while it plays the sound, so if you play one sound and then another sound the second sound will start before the first one has even begun playing, so you'll never hear the first one.  Instead, if you want to play sounds sequentially, you should for the first sample to finish using something like:
while (tmrpcm.isPlaying()) {
    delay(1);
}

which will stop your sketch running until the last sound has finished.  Including the delay(1) is a good idea since it allows yield() to execute allowing anything that needs it to run (not really a problem on an Uno, but on things like an ESP8266 it's absolutely critical or you get a watchdog timeout).

Thank you :) it's working, although now it loops the wav over and over i only need it to do it once. Is there a quick way of fixing that?

You need to learn how to recognise when the switch changes position - that is, the moment in time when it changes from LOW to HIGH, and only play at that point.


text:
Connecting to Arduino Ethernet Shield
How do I figure out how to connect to my arduino using ethernet shield?
It prints the IP in the serial monitor, but it doesn't work, and adding the port doesn't make a difference.
The client example works, so it's not broken or anything.
I'm using Arduino 1.6.5 IDE on a Mega 2560. I'm trying to run the Examples/Ethernet/WebServer example.

Please state which Arduino you have. Also which version of the IDE. You need to run one of the "server" examples, please state which example you are trying.

@NickGammon Like this?

What IP address are you using? What are you typing into your web browser? What do you see in the Serial Monitor?

@NickGammon That's in the original post: "It prints the IP in the serial monitor, but it doesn't work, and adding the port doesn't make a difference." Meaning I take the printed ip. using ip:port doesn't work either.

It prints the IP in the serial monitor - I'm not asking you to describe what you see. Please copy and paste it. What IP addresses are you using on your local LAN? For example, do you see a message like "new client"?

@NickGammon well, I meant to imply that I tried this IP and "it doesn't work". My browser gives me a 'timed out' message. I don't really know how to connect to it locally (or rather, how to find that IP) but I'm connecting to the same switch as the arduino

Your question is kind of trivial, but from what I understood you're typing the IP address (that the Arduino displays on the serial monitor)  into your browser.
First, make sure you connect your Ethernet shield to your router using an ethernet cable. (Now it's connected locally...)
Second, even if you type in your Arduino's IP address into the browser, the browser will return nothing because the Arduino simply has nothing to display, and hasn't been programmed to accept requests.
To actually have the Arduino display something you can try the Webserver example sketch or you can follow this great Tutorial that I found very useful for beginners.
BTW ports are only used to expose your Arduino to the Internet, in other words if you don't portforward to your Arduino, your Arduino won't be able to get requests from outside your local network (Wi-Fi,Ethernet).

Like I stated in the question, I'm using the webserver example sketch. I also portforwarded my arduino.

I think it would be more accurate to say that ports are used to identify the service running on the Arduino (for example to differentiate between HTTP and NTP). Port forwarding happens on the router and makes a service running on an internal host (at a private IP address such as 192.168.0.42 or 10.0.4.2) visible from the "outside world" (the WAN interface).


text:
Script stops functioning after calling irsend() function in irlibrary!
I have the following script which checks if the user has pressed the numbers "770" or "769" continuously in the remote. The script works fine and displays all numbers. When I press the buttons "770" or "769" continuously the function powerOff() is called and I get no serial input.
/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

IRsend irsend;

decode_results results;

int intValue;
String strValue;
String str3;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    intValue = results.value;

    Serial.print("Integer value : ");
    Serial.println(intValue);

    strValue = String(intValue);
    Serial.print("String str : ");
    Serial.println(strValue);

    Serial.print("Length : ");
    Serial.print(strValue.length());
    Serial.println();

    if(strValue.length() <= 1){
      str3 += strValue;
      Serial.println(str3);
       // Receive the next value
   }

    delay(200);
    irrecv.resume();
  }
  //Serial.println(str3);
  if(str3.endsWith("770")){
    powerOff();
    str3 = "";
  }
  else if(str3.endsWith("769")){
    powerOff();
    str3 = "";
  }

  else{}
  //powerOff();
}

void powerOff(){
    irsend.sendRC6( 0xC0000C, 24);
    irrecv.resume(); // Receive the next value
}

Apparently you should be calling irrecv.enableIRIn() after sending, not irrecv.resume(). Sorry for suggesting the wrong thing on IRC before :-)


text:
Burning Arduino Leonardo Bootloader to ATmega32U4 with 8MHz internal clock
Burning question:
So, I'm trying to burn the Arduino Leo bootloader onto a ATmega32U4 that's on 3.3V and the internal 8MHz clock.  Do I have to modify and rebuild the bootloader to set the fuses correctly, and can this be done with AVR Studio?
All of the references on doing this are dated.  The folder structure for the Arduino IDE has changed. I've done it in the past with 5V 16MHz 32U4s using an Arduino as ISP, but never with the AVRISP mkII on the Arduino IDE.
On the good side, I do have it up and running Atmel Studio.
Thanks!
EDIT:  Sorry for double posting, I posted in electronics before I noticed there was an Arduino specific section.

Thank you! Though I've been trying to do this with an AVRISP mkII as ISP in the Arduino IDE, but for some reason I get this error message: "avrdude: usbdev_open(): did not find any USB device "usb""

If you have an appropriate crystal attached then you can do this in the Arduino IDE. Select your board and programmer in the IDE menu, connect the programmer to the board, and choose Burn Bootloader from the menu. This will both burn the prebuilt bootloader image and set the fuses in a single operation.
Note that you cannot use USB on the '32U4 if you are running off either a ceramic resonator or the internal oscillator, and so you should not attempt to use the Leonardo bootloader in either case.

Why can't the USB be used with the internal RC? Datasheet says that it's possible. I'm not doubting you, I'm just wondering the reason.

It is possible to use low speed USB if you have a way of keeping the oscillator calibrated. It is not accurate enough for high speed USB even if calibrated.


text:
SIM900 random shutdowns
I have a SIM900 GPRS/GSM Shield and an Arduino Mega. Now for the past week I have been using USB as power to send and receive GPRS data with no issue. Today the SIM900 module is continually randomly turning off, not even turning of at specific stages of communication.
I thought this could be power related, so have external power (5V 5A UBEC) into the 5V pin of the Mega, which I believe should cover the voltage and current requirements of the SIM900 shield. However this has not solved the problem.
Any ideas on what could be causing the random shutdowns?
EDIT:
Is it safe for me to wire power up like this:

Are the mega and the PSU sharing a common ground?

Cool, an UBEC is indeed a smart choice for powering a SIM900.
I could get away with a small switching power supply and just putting in a big capacitor (since the sim900 only draws high current in very short peaks).
But, the limiting factor in this case would be the 6AA batteries. Your UBEC may be able to supply 5A's but those AA's may not.
Also, look up "transient response" (related) according to the related article, you can have an 20A power supply, but still have the voltage drop out when the sim900 starts to transmit. This is because your supply needs to be able to deliver the required 2A in a very short period of time, so basically if your supply can't go from 100ma to 2A fast enough, it'll dip.
I suggest finding a more optimal source as AA's and adding a "big ass capacitor" close to the sim900's input.

Pumping 5Amps into the Mega isn't going to make a difference to the current the SIM900 is receiving (needs >2A)  it will still get 500mA (?).
You need to feed the power directly into the SIM900 from the PSU, because when it transmits it needs a nuclear reactor to power it.  Don't forget the common ground.

Ok, i'm not massively clued up on the power side of things. I have this UBEC. How can I safely power the Arduino AND the SIM900 with this?

Is it safe for me to wire power up as shown in the main post edit?

Hold on, even though I am plugging into the 5v pin, then current is still limited 500mA?

Looking at you diagram (could see it yesterday).  Does the "Turnigy" have two separate outputs?  You description seems to say that the SIM900 is powered from the Mega, but you picture seems to say the wire splits and goes separtly to each.
Rereading the description it looks like you have flat batteries, "worked last week but has stopped working", have you tried changing the bat's? (Sorry to ask a dumb question, I'm sure you have, but...)

You could always try adding a large electrolytic capacitor 10000uF to the power rail (- to GND and + to +5V), it might be that SIM900 resets when it just browns out due to transmission power usage.


text:
avrdude: ser_open(): can't open device "\\.\COM3"?
My computer cannot detect my Arduino Uno anymore,

Reset button- > L led light blinks and it turns on forever
Arduino 1.6.5: Tools->Port (greyed out) I remembered that previously it wasn't like this
Unable to upload any sketch codes into the Uno anymore
The existing code uploaded onto the Uno is FastLED(FirstLight) and it will work on my LEDs when I plugged them in

I have tried to .... but none fix my issue

Restart my computer
Press the reset button on the Uno
Using the device mananger to change COM ports
Device manager -> Other devices -> (nothing about Arduino Uno is found here)
Plugged Uno into another computer but still doesn't work
Reinstalled IDE

Problem shown in sketch,

avrdude: ser_open(): can't open device "\.\COM3": The system cannot find the file specified.
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Try to install the ardunio driver again. Connect your arduino to another pc & see if it is working or not.? or maybe try connecting any other serial device to your pc and check if it shows any com ports or not.?

I'm voting to close this question as off-topic because it has been abandoned for two years without any followup that could make it answerable ever being provided, and it has started to attract low quality responses.

I have experienced a similar issue after plugging in another Arduino device. I didn't set up my environment for a long time and thus forgot he iterates the COM-Index. Maybe this is too easy, but you didn't provide much information.
This solved my problem:
Open Arduino application > Tools > Port > Change to the target Port
If you are unsure which port to choose from: (on Windows)
Open Device Manager > Connections (COM & LPT) > Usb Serial Port (COM[x])
where "[x]" is the index you are looking for.

This is dangerously close to an "I'm having this problem too" response.  Changing the port seems unlikely to be a solution, since having the port menu greyed out suggests there are no valid choices there to choose.  The problem here would appear to be far more fundamental - an electrical fault, bad cable, or bad driver.

Try a different arduino w/ your first computer, see if that will work.


text:
Relay module and internal pull-up resistors
I'm currently assembling a prototype of the lightning infrastructure (based on several MEGAs interconnected via RS485, as described in this other post)
The prototype consists of three MEGAs, a couple of wall-push-button and the two relay modules here below:

250V 2A 8 Channel OMRON SSR G3MB-202P Solid State Relay Module For Arduino
5V 4 CH OMRON SSR G3MB-202P Solid Relay Module with Resistive Fuse For Arduino

Obviously I've:

connected one endpoint of each push-buttons to Arduino INPUT-PIN; the other endpoint to ground;
connected the relay-module control-pins to Arduino OUTPUT-PIN (and ensuring a properly connected ground).
connected lamps to relay-modules power connectors.

My question relates to "pull-up resistor": I've read in lots of places that when involving push-buttons, "pull-up resistors" are needed in order to prevent shorts between ground and input-pin. As such, there are lots of tutorial/videos on the web, showing a nice resistor added in the push-button circuit.
Further investigating, I've also learnt from the official documentation that "...There are 20K pullup resistors built into the Atmega chip that can be accessed from software....", by setting the pinMode() as INPUT_PULLUP or setting it to INPUT and the forcing a digitalWrite(<PIN>,HIGH).
So, I ended:

directly connecting the two relay-modules to MEGAs INPUT-PINs and...
...activating the internal pull-up, with digitalWrite(<INPUT_PIN>,HIGH);

Nothing more.
This is the second evening I'm "testing" my Arduino-luggage-prototype and... lamps are turning on/off like a charm, without any noticeable problem.
The question is: am I doing something nasty toward my MEGAs? Is the approach depicted above, a commonly-safe (as for the Arduino's health) approach?

P.S.: should you wonder about how the prototype looks like, here is a photo (actually, taken right after the first power-up ;-)

Connecting one side of a switch to ground and the other side to an input pin (with its pinmode set to INPUT_PULLUP) is a standard way of connecting control switches to an Arduino installation, and is not a problem.
Note, claims that built-in pull-ups are 20KΩ oversimplifies the situation.  See, for example, Table 28.2, DC Characteristics, in the ATmega48PA/88PA/168PA/328P specs, which shows a min value of 20KΩ for   I/O Pin Pull-up Resistors and a max value of 50KΩ.  I've measured resistances of about 40KΩ, IIRC, whenever I've measured the pull-up values.
Note, built-in pull-ups typically are of too much resistance to work as pull-ups for TWI/SPI/I2C communications.
Note, when you say in the question that you connected the relay-modules to input pins and they worked ok, I suppose that could be the case, but in general it is better to put i/o pins into output mode when you want to drive an output.  When you send LOW to an input pin, its built-in pull-up is turned off, the input impedance becomes high, and then the pin can float to any value between ground and Vcc. It might fail to turn off an attached device if that device also has high impedance.

As for the connection of relay-modules, I'm sorry! It's a typo (that I've just fixed): relay modules are driven by OUTPUT pins. Not input.

I am making the assumption the push buttons are wired directly to the mega.  This may work but for me it is not acceptable.  Why?  All of those wires act as an antenna array tuned to a lot of different frequencies.  My favorite trick is to use a 74C14 Schmidt trigger chip.  The reason is several fold. First it isolates the antennas from the processor.  The family I use will tolerate about 25volts input, giving a lot of head room.  Second it makes the software a bit easier, all switches come in positive true. Third I use a low pass network in front so if one of the mains hits it it will probably survive.  What I do is Pull up with a resistor that will cause about 1.5 ma to flow through the switch.  This value is dependent on your voltage, I typically use 12 or  24 VDC.  This input then goes through a 100K resistor to the input of the gate where I also put a .01 uF cap.
I am also working on a similar project, I made the same decision on a hardwired network about 15 years ago.  All the switching is on several output boards (5V) located in a PC AT. I also chose the mega for several reasons, first I needed full duplex with my network, the MAX485 will do that you just have to leave the receive enabled and cycle the transmit when you want to send something.  I also added a low pass on the (A line I Think) to another pin so I could determine if the network was busy,  I currently have about 150 outputs with very few inputs.  Code is all in ASM86.
I hope this helps, I will see if I can add to your reference question.
Thanks,
Gil


text:
Can't upload to Arduino Mini via Arduino USB 2 Serial Converter
I bought an Arduino Mini and also an Arduino USB 2 Serial Converter.
While trying to program the Arduino Mini, I get this error:
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00

After doing some research I tried many things like changing the settings, serial port, made sure I'm using the right Arduino etcetera.
Some points to consider:

I tried burning the bootloader using my Arduino Uno.
Uploading sketches to the Arduino Mini using my Arduino Uno works (so problem is not directly with the Mini).
I am pressing the Reset button before uploading. I also tried hooking a capacitor and the Reset wire directly. No change.

The wiring (I also tried connecting TX of Mini to RX of serial converter, and vice versa):

The Arduino USB 2 Serial converter was defect (even though brand new). I bought a cheaper (7 Euro) FTDI to USB and I can now upload.


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

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

Datasheet. Library source. Why think anywhere else?

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

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

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

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

So, you don't know a reason?

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

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

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

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

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

From the datasheet:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


text:
On UNO, when serial.print to UART pin 11, nothing comes out of pin 11
The problem: Message prints only to the Arduino IDE's Tools > Serial Monitor, not coming out of TX pin 11.
Question, please how to get Arduino Uno or Mega to send data out of pin 11?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX pins on Arduino
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.print("This is a test\n\n");
  delay(1000);
}

Where in that code are you doing anything at all with pin 11?!

Of course it's only coming out on the serial monitor - you are printing it to the hardware UART which comes out on the serial monitor.
You have created a SoftwareSerial object which you are then completely ignoring and then using the HardwareSerial UART object instead, which is on pins 0/1.
If you want to use a SoftwareSerial object you should actually use the SoftwareSerial object.
Replace all the references to Serial with mySerial instead.

Thank you for the speedy answer.  I will try that immediately.

I change  to my Serial and had to add mySerial.begin(9600).   Now it works. Thank you Majenko.


text:
ESP8266 does not respond after changing baud rate to 9600
I have ESP8266 WiFi module and Arduino Mega Board connected. I use external 5 to 3.3 V regulator to power up the module. Common (-ve) line on the external power source and Arduino Mega GND is connected. Then I used 1K and 2K voltage divider for WiFi module RX and TX use as same. I am sure my circuit is well works.
Then I connect RX0-RX and TX0-TX. Then i put CH-PD to 3.3v
Then I opened the Arduino IDE and upload the Blink sketch. Done.. Then I opened Serial Monitor and set baud rate to 115200. Then power up the module. It gave me a lots of garbage values and ready. Fine.
Then I downloaded the FLASH_DOWNLOAD_TOOLS_v0.9.5. configure the 0x0000, 0x1000 and 0x7c000

SPI speed = 40MHZ
SPI mode = QIO
FLASH size = 4Mbit
0x1000 = ai-thinker-0.9.5.2-9600.bin

Then O power off the module and connect GPIO0 to ground and again power on.
Then push start button. Then it downloaded to the chip. It worked. Done. Success fully uploaded. Then I again disconnected the GPIO0 and power on. Then I put AT and it results OK.
AT+GMR gives version 0.9.5 updated.done.
The problem was the module was responded for 115200 baud rate, not 9600. Then I:
AT+IPR=9600

it gives me nothing.
Now I can't communicate with it at either 115200 or 9600 baud. No respond whatever baud rate I put. Sometimes I am having same garbage values.

The command to change baud rate is AT+UART_DEF. Have you tried re-flashing the module?

This is a common issue. Using the AT+IPR command seems to brick the module. Try to re-flash your module, like you did the first time. If it works, use this command: AT+UART_DEF=9600,8,1,0,0 instead to change the baud rate.

Thank you reply me. I tried to reflash it. use baudrate 115200 .then the blue Led is blinking. after a little time blue LED went off. the software shows me to IDLE mode to Download mode but prograss bar doesn't update.it is stucked.

@KolithaWarnakulasooriya The flashing completed successfully? Have you tried sending AT?

No it didnt uploaded to the chip.software didnt show the success message.yes i tried to send AT. I set the end charachter type as Both NL & CR. baud rate 115200 ; nothing.

when i power up the module it gives me garbage values

Note:Serial port connected.
Note:Begin find ESP8266.
Note:ESP8266 ACK success.
Error:Read ESP8266 register timeout.

chip sync ok!    .
chip_flg 1 ,
r1: 0a; r2:88 ; r3: 31,
MAC AP : 1A-FE-34-0A-88-31 ,
MAC STA: 18-FE-34-0A-88-31 ,
filename:   ,D:\Adruino\FLASH_DOWNLOAD_TOOLS_v0.9.5_150414\FLASH_DOWNLOAD_TOOLS_v0.9.5_150414\bin_tmp\boot_v1.1.bin_rep
offset :  0,
Erasing flash...,
head: 1 ;total: 1,
erase size : 4096,
erase flash error,
com closed,

Thank you for help me to figure this out. I have made it. http://www.pratikpanda.com/completely-format-erase-esp8266-flash-memory/ this was helped me

@KolithaWarnakulasooriya What did you change? Does it respond now?


text:
Software Serial and multiple shields for Arduino Uno
I have a SIM900 GPRS/GSM Shield (details here) and I am looking to stack a GPS shield (such as this one here).
My question is: I believe that they both require software serial, also it says to use software serial on D7 and D8 for both. Is this possible on an Uno?
I am a bit confused at if software serial has to have these two specific pins, or if these are just what is chosen on schematics?
What would be the most effective way to stack these two shields so they don't interfere with each other?
EDIT: Using a gps shield such as this gives the option  of

If you need to move the software serial port pins, they can be custom-routed to any other pin by cutting the solder jumpers between pins GPS-RX and D8 and/or GPS-TX and D9.

This isn't entirely clear to me, but am I right in thinking it means I can have multiple software serials on my Uno, just using different pins?

SoftwareSerial can use any pins. That's the whole point of it. However, some shields are wired to use specific pins. If two shields try and use the same pins then you can't use them together. Not stacked, anyway. You will have to use flying leads, or physically alter the shield (cutting tracks, soldering in "bodge" wires) to use them together.
That said, though, you can only use ONE SoftwareSerial port reliably at a time. That means, regardless of what pins they use, you can't use two shields together that require pins other than 0 and 1 (hardware serial).
To use them both you will need a board with multiple hardware UART ports and modify the shields (as mentioned above) to use the correct pins for those UART ports.

Ah, so even if I have for example:
SIM900 on D7 and D8,
Wifi on D5 and D6,
GPS on D3 and D4.
and set up each of these with their own
SoftwareSerial serial1(7, 8);
SoftwareSerial serial2(5, 6);
SoftwareSerial serial3(3, 4);
It still wouldn't work?

Not reliably. SoftwareSerial is a blocking system. It uses interrupts to start reception of a character through a port, but while that character is being received nothing else can happen. So you can only receive through one port at a time. If anything arrives on one of the other ports while something is being received on one port it is lost forever.

If I did the same kind of pin redirection, just on a Mega to the hardware serials, then used serial1, serial2 and serial3. Would this be the best way to reliably communicate with each shield?

Yes. That would be ideal.

Just to confirm, in this case I could redirect all the shields hardware serial pins (D0 and D1 of each shield) to each hardware serial of the Mega. Meaning I don't even need software serial?


text:
SIM900 TCP Connection issue
I am having a strange issue where if I try and create a TCP connection to my service, it doesn't work. But any other website, such as google, works fine. The serial monitor output is also slightly different, but I cannot see any difference in the code. I am using this module for communications.
This is the method that I am using:
void SendPost()
{
  Serial1.println("AT+CGATT?");
  delay(1000);
  ShowSerialData();

  Serial1.println("AT+CSTT=\"everywhere\"");//start task and setting the APN,
  delay(1000);
  ShowSerialData();

  Serial1.println("AT+CIICR");//bring up wireless connection
  delay(3000);
  ShowSerialData();

  Serial1.println("AT+CIFSR");//get local IP adress
  delay(2000);
  ShowSerialData();

  Serial1.println("AT+CIPSPRT=0");
  delay(3000);
  ShowSerialData();

  Serial1.println("AT+CIPSTART=\"tcp\",\"www.google.com/\",\"80\"");//start up the connection //https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register
  delay(5000);
  ShowSerialData();

  Serial1.println("AT+CIPSEND");//begin send data to remote server
  delay(4000);
  ShowSerialData();

  Serial1.println("{\"device_info\":\"breadcrum-prototype-a\"}");
  delay(500);
  ShowSerialData();

  Serial1.println((char)26);//sending
  delay(5000);//waitting for reply, important! the time is base on the condition of internet

  Serial1.println();
  ShowSerialData();

  Serial1.println("AT+CIPCLOSE");//close the connection
  delay(100);
  ShowSerialData();
}

Using 'www.google.com' I get an OK upon tcp connection (with an expected error on the data as I try to POST):
Setup CompleteAT+CGATT?

+CGATT: 1

OK
AT+CSTT="everywhere"

OK
AT+CIICR

OK
AT+CIFSR

100.66.4.95
AT+CIPSPRT=0

OK
AT+CIPSTART="tcp","www.google.com/","80"

OK

STATE: IP STAAT+CIPSEND

ERROR
{"device_info":"breadcrum-prototype-a"}

AT+CIPCLOSE

ERROR

But using the address I actually want to post data to (https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register), it cannot connect and I get this:
Setup CompleteAT+CGATT?

+CGATT: 1

OK
AT+CSTT="everywhere"

OK
AT+CIICR

OK
AT+CIFSR

100.66.4.95
AT+CIPSPRT=0

OK
AT+CIPSTART="tcp","https://rocky-garden-56471.herokuapp.com/breAT+CIPSEND

ERROR
{"device_info":"breadcrum-prototype-a"}

AT+CIPCLOSE

ERROR

This errors on connection, and you can also see that the full address isn't printed out for some reason. Does anyone have any idea what could be causing this issue?
Thanks :)
EDIT:
@Majenko, my previous version did what I believe you are describing. The issue being I got an error that I struggled to resolve so attempted this version. The previous version is:
void SubmitHttpRequest()
{
  Serial1.println("AT+CSQ");
  delay(100);
  ShowSerialData();

  Serial1.println("AT+CGATT?");
  delay(100);
  ShowSerialData();

  Serial1.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
  delay(1000);
  ShowSerialData();

  Serial1.println("AT+SAPBR=3,1,\"APN\",\"everywhere\"");//setting the APN, the second need you fill in your local apn server
  delay(4000);
  ShowSerialData();

 //Enable GPRS
  Serial1.println("AT+SAPBR=1,1");
  delay(2000);
  ShowSerialData();

  //Query if connection is setup correctly, return IP address if it is
  Serial1.println("AT+SAPBR=2,1");
  delay(2000);
  ShowSerialData();

  Serial1.println("AT+HTTPINIT"); //init the HTTP request
  delay(2000);
  ShowSerialData();

//Set up bearer profile identifier (NEW PART)
  Serial1.println("AT+HTTPPARA=\"CID\",1");
  delay(2000);
  ShowSerialData();

  Serial1.println("AT+HTTPPARA=\"URL\",\"https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register\"");// setting the httppara, the second parameter is the website you want to access
  delay(3000);
  ShowSerialData();

  Serial1.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
  delay(3000);
  ShowSerialData();

  Serial1.println("AT+HTTPDATA=1000,10000");
  delay(3000);
  ShowSerialData();

  Serial1.println("{\"device_info\":\"breadcrum-prototype-a\"}");
  delay(3000);
  ShowSerialData();

  Serial1.println("AT+HTTPACTION=1");//submit the request //0:READ 1:POST 2:HEAD
  delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
  ShowSerialData();

  Serial1.println("AT+HTTPREAD");// read the data from the website you access
  delay(1000);
  ShowSerialData();

  Serial1.println("");
  delay(100);
}

But the results I got from this was another error when attempting to post:
Setup CompleteAT+CSQ

+CSQ: 18,0

OK
AT+CGATT?

+CGATT: 1

OK
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK
AT+SAPBR=3,1,"APN","everywhere"

OK
AT+SAPBR=1,1

OK
AT+SAPBR=2,1

+SAPBR: 1,1,"19.177.18.205"

OK
AT+HTTPINIT

OK
AT+HTTPPARA="CID",1

OK
AT+HTTPPARA="URL","https://rocky-garden-56471.herokuapp.com/breAT+HTTPPARA="CONTENT","application/json"

OK
AT+HTTPDATA=1000,10000

DOWNLOAD

ERROR
AT+HTTPREAD

OK

EDIT 2:
Following HTTPS commands:
 AT+CSQ

+CSQ: 18,0

OK
AT+CGATT?

+CGATT: 1

OK
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK
AT+SAPBR=3,1,"APN","everywhere"

OK
AT+SAPBR=1,1

ERROR
AT+SAPBR=2,1

+SAPBR: 1,1,"31.94.203.234"

OK
AT+HTTPSSL=1

OK
AT+HTTPINIT

OK
AT+HTTPPARA="CID",1

OK
AT+HTTPPARA="URL","https://rocky-garden-56471.herokuapp.com/breAT+HTTPPARA="CONTENT","application/json"

OK
AT+HTTPDATA=100,10000

DOWNLOAD

ERROR
AT+HTTPREAD

OK
AT+HTTPTERM

OK

There is so many things wrong that I don't know where to start.

You are trying to use a URL in place of a hostname.
You are trying to connect to an HTTPS service which runs on port 443 not on port 80
HTTPS is encrypted. You are opening a plain TCP socket to an encrypted service.

Your whole methodology is wrong. You need to use the SIM900 HTTPS AT Command Set to get the SIM900 to perform an HTTPS request on your behalf rather than opening a socket and sending / receiving data.

I have posted my previous version in an edit to the main question. I believe that version did what you are describing, but I also received errors on the result of this.

Not quite. Close, but not quite. In that version you're using HTTP commands to access an HTTPS site. You need to use HTTPS commands not HTTP commands.

Following the HTTPS commands I get very close, but with only errors occurring on the download. I have added "AT+HTTPSSL=1" to enable https. I have added another edit to reflect my new results.

Are you actually sending 1000 bytes of data to the server?

I am only sending Serial1.println("{\"device_info\":\"breadcrum-prototype-a\"}");.
But I believe the issue is being caused by the URL being chopped, there are logs which say 'not found /bre'. Why would the command:
Serial1.println("AT+HTTPPARA=\"URL\",\"https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register\""); be cut down?

That's 39 characters. Why tell it you're sending 1000 when you only want to send 39?

I have been testing varying values for that just to see if it affected anything. 1000 was simply what I had left in there when I pasted it through.

Setting the message size to the correct amount has worked. Thank you so much for your help Majenko!


text:
Advanced Arduino Project Help
So, I am an Engineer working on a very time tight project.
I want to create a system capable of collecting data from a Photodiode and compiling it in a way that will separate data into four columns which correspond to colours (red, green, blue, yellow) the columns will have rows of data corresponding to a number.
I have elected to use Arduino for this project but need some help on what to get and whether this is possible or not... I have an intermediate knowledge of C, C++ and previous Arduino experience, but have never undertaken something like this.
The project is envisaged to look like this.
Hardware:

Photodiode with RS232-C connection
An Arduino (Which sort is best? now I have Uno and Mega but can purchase others should these not be sufficient for the project)
Touchscreen Interface
Storage capacity (SD card or email/Bluetooth capability or something alike to collect the data to edit on PC).

The Process should is like this: Input = User interacting with GUI on Touchscreen - First page will have Four Colours Available (Once one of these inputs selected let’s say Red, jump to next page) -> Page two will have a Touch Number Pad Input (User selects number, let's say 2 in this case and hits enter), For less complexity this could be on one page correct? ->
The Data will then be read off a Photodiode communicating via RS232-C to Arduino and stored in a .csv or something similar under its previously selected values (Red, 2, Photodiode Value)
Output: A compiled list of all the data collected under their relative user inputs.
I currently have these items but am happy to purchase others.

S130C Thorlabs Photodiode Sensor
Null Modem Cable (Pins are swapped on S130C)
RS232 Shield (DFRobot RS232 Shield V0.1)
Arduino Uno, Arduino Mega
TouchScreen (Duinotech 2.8” TFT LCD)

After re-reading what I wrote I suppose there are a few:

Could I complete this project using Uno and Mega?
Is there a method for compiling data and storing/sending using Arduino?
What are the capabilities of Arduino? Could a project of this complexity be done using Arduino components or is there another microprocessor or microcomputer which would be a better choice for this project?

What is the actual question?

After re-reading what I wrote I suppose there are a couple:
Could I complete this project using Uno and Mega?
Is there a method for compiling data and storing/sending using Arduino?
What are the capabilities of Arduino? Could a project of this complexity be done using Arduino components or is there another microprocessor or microcomputer which would be a better choice for this project?

Ant1, Please edit your post to include the questions, rather than leaving them in comments.  More likely to be upvoted if question is unitary.

Your question is incredibly broad. However:
1. Could I complete this project using Uno and Mega?
Yes, almost certainly
2. Is there a method for compiling data and storing/sending using Arduino?
What? Yes, you can store data onto an SD card using a simple level-shifting piece of hardware like this:

3. What are the capabilities of Arduino?
This isn't a reasonable question (it's too broad). I suggest Googling for things people have done. For myself, I made a humidity and temperature sensor using the same processor as in a Uno. It also runs from batteries.

... a very time tight project ...

Time is going to be your enemy here. Learning how to drive a touchscreen, save files to an SD card, interpret RS232 data from your sensor, and make it all work reliably is not the sort of thing you will do in 3 days.
Even if you dumped all your hardware on my desk (and I know how to program Arduinos) I would estimate two or three weeks to calmly get each part going individually and then interface them all together.

Would you suggest using breakout boards over shields?

Shields are well and good if they do what you want them to do. A breakout board will have more flexibility.

because of pin availability would you suggest trying to use the Mega rather than Uno?

Depends how many pins you need. If you use SPI or I2C you can (probably) drive your display with only a handful of pins.
The Uno will probably have enough, and it has the flexibility that you can easily replace the processor chip if you damage it. You can't do that to the Mega. Plus, more code is written for the Uno so you are more likely to find libraries that work "out of the box" for a Uno.
I wouldn't be getting the "more powerful" device unless you have identified a specific reason to have it. For example, some of the faster and more powerful Arduinos (and other boards) with ARM processors may well do more under certain circumstances, but be somewhat harder to use.

Hi Nick Gammon,
Thanks very much for your answer!
I understand the questions are so broad it's difficult to nail down exactly what I am asking and I apologise for that. I am definitely intimidated by the time line, for that reason I have asked for help from people such as yourself and future questions will likely be more specific.
Would you suggest using breakout boards over shields?
and because of pin availability would you suggest trying to use the Mega rather than Uno?

See modified answer.

Thanks for all your help Nick, do you mind if I contacted you in the future? Say if I run into any further issues.

You are welcome to post further questions. I am unable to answer questions personally.

authors: عباس عبدالهی


text:
CIRC-03 Spin Motor Spin
I am experimenting with CIRC-03 but the DC motor won't start spinning with motorAcceleration(); unless I give it a push. Also, it makes a little noise when it stands still.  It does spin, however, with one of the first two functions (motorOnThenOff(); motorOnThenOffWithSpeed()). I've tried adding the 220 µF capacitor but that doesn't change a thing.
Could someone offer me a solution to this problem?

Where is the code?

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


text:
Some Arduino components seem ridiculously cheap
My project is an Arduino-based device, packed into a box.
It will need to use Speed, Latitude, Longitude and Altitude data to log hills it detects on to an SD. On the press of a button, it will need to upload the hill data to the server via Wi-Fi.
I need the following items:

GPS Module + Antenna
WiFi Module
SD Module
Altimeter
microSD Card
Inline switch for my battery pack

The cost? Well on the Pi Hut it was £120 or so:

GPS =
  https://thepihut.com/products/sim808-gps-gprs-gsm-shield-for-arduino =
  £42
WiFi =
  https://thepihut.com/products/wifi-shield-v3-for-arduino-rpsma-802-11b-g-n
  = £54
SD = https://thepihut.com/products/microsd-card-module-for-arduino =
  £6
microSD Card = https://thepihut.com/products/blank-micro-sd-cards
  (4GB) = £5
Altimeter =
  https://thepihut.com/products/adafruit-bmp280-i2c-or-spi-barometric-pressure-altitude-sensor
  = £10
Switch =
  https://thepihut.com/products/adafruit-in-line-power-switch-for-2-1mm-barrel-jack
  = £2.50

On Bang Good (a really cheap online shop I discovered) it was more like £30:

GPS =
  https://www.banggood.com/GPS-UBLOX-NEO-7N-Satellite-Positioning-Module-For-Arduino-51MCU-STM32-p-1203610.html?rmmds=cart_middle_products&cur_warehouse=CN
  = £10.54
GPS Antenna =
  https://www.banggood.com/GPS-Active-Ceramic-Antenna-IPX-IPEX-Interface-For-GPS-Module-p-1203537.html?rmmds=cart_middle_products&cur_warehouse=CN
  = £2.11
WiFi = https://www.banggood.com/Upgraded-Version-1M-Flash-ESP8266-ESP-01-WIFI-Transceiver-Wireless-Module-p-979509.html?rmmds=cart_middle_products
  = £2.53
SD = https://www.banggood.com/Micro-SD-TF-Card-Memory-Shield-Module-SPI-Mciro-SD-Adapter-For-Arduino-p-919914.html?rmmds=cart_middle_products&cur_warehouse=CN
  = £1.02
microSD Card = https://www.banggood.com/4GB-MicroSD-Card-with-Card-Reader-for-RC-FPV-Camera-Quadcopter-p-1050069.html?rmmds=cart_middle_products&cur_warehouse=CN
  = £3.96
Altimeter = https://www.banggood.com/MPL3115A2-IIC-I2C-Intelligent-Temperature-Pressure-Altitude-Sensor-V2_0-For-Arduino-p-1198222.html?rmmds=cart_middle_products
  = £5.16
Switch = https://thepihut.com/products/adafruit-in-line-power-switch-for-2-1mm-barrel-jack
= £2.50 (From Pi Hut, though)

I'm suspicious. I might be inexperienced, and this may be a bad question, but is the cheaper option lower in quality? Is the expensive one over the top? The cheap version really seems to good to be true.

buy at least one genuine Arduino product .... it supports Arduino development

@jsotola What is the best component to buy genuine? Wifi, GPS or SD Module? Should I look for a new Arduino (ie Yun)? What do you mean by Arduino development (libraries, general progress, Arduino foundation, other)?

i was talking about any product found here https://www.arduino.cc/ ....  i made the comment in case you are just starting out and buying a controller board .... i was referring to research and development of the products found at that website

@jsotola Even if they're more expensive?

The pi-hut GPS also has GSM, which makes it more expensive. The Wifi shield also has a way more expensive chip on it that the ESP8266 one you found on banggood. Ordering directly from china is often cheaper, but there is a risk of lesser quality.

fwiw, i've ordered about 1200 ardunio-related items (according to ebay), and i've only been "burned" 5 or 6 times with something that was mis-speced, deffective, or just so crudely made it was unusable. The vast majority of the cheap crap i've bought works fine. You get faster shipping, better packaging, better docs, and better support from someplace like adafruit, but the products themselves are alright, with few exceptions.

@dandavis would you still recommend eBay for starters? They do not know which exact part they need and they will have great help from manuals, datasheets, guides, libraries and example projects. It's very uncommon to get this for eBay parts, but Adafruit will give those.
If you're confident in your embedded systems skills, no worries on eBay parts (usually shops buy their stock through eBay, it seems), but as a starter, you need to have confidence in the parts you use and have enough background info to get you started.

@Paul What do you mean by starter? Perhaps I'm not?

@Paul: I've been using ebay since day 1, about 2-3 years ago. you can still use adafruit docs and libs on cheap parts; anything adafruit sells you can get for at least half-off on ebay, sometimes 10X less. That's great for a hobby you're getting started in and unsure of. I think it's better to go cheap at first; you're more likely to burn stuff up and it won't be as discouraging watching an LED smoke if you got 100 for $1 than w/ adafruit's "special" LEDs. I can get a whole project's part list shipped from ebay for less than adafruit shipping, and to me, that enables a whole lot more learning.

also note shipping times; items may be cheaper on banggood, but you'll be waiting 1-1.5 months for them to arrive (untracked and uninsured)

The cheaper option is not always lower in quality. You can find items for sale on Amazon, Ebay and Aliexpress that all have the same "seller name" and a identical picture of the item. The price is usually 5 to 10 times higher on Amazon than Ebay. Aliexpress is usually the cheapest.
During the past year, I've ordered over 100 Arduino related sensors/modules from Ebay and Aliexpress. Four from Ebay and one from Aliexpress were defective. I got a refund for all five items.
If you are going to buy the cheaper products, it's a good idea to order more than you need in case one is defective.
Some items should not be sold at any price. For example, I purchased a DHT11 temperature and humidity sensor when I first started with Arduinos. It's an inaccurate piece of garbage, and that's exactly where it went.

If something is too good to be true, it usually is.
In all seriousness, going with a reputable shop (Adafruit, Sparkfun, Pololu) can save you a bit of headaches later, especially if you are doing integration.  You might ask (email) the Pi Hut folks why you should buy from their place, rather than the other place, I'm curious what they would say.  I don't think this needs to be an accusatory sort of email (how dare you charge more!), but more of a "I see there is a price difference; obviously, something is going on which I don't know about, can you explain this?"
I've bought cheap stuff from Amazon (Arduino clones), and they'd work... after a fashion.  Bad solder masks, badly soldered components; all would make getting things going a real pain. Sometimes, a component (like a voltage regulator) wouldn't work, and so an Arduino clone would work when plugged in to a USB port, but not in a standalone mode.   Then again, this was a 4 for $10, vs 1 for $15, so it was a bit of a lark, but there was a build quality
If you are putting a lot of effort into the software for this, or paying someone for the software to be developed, or this experiment will be a costly one, the price difference wouldn't be as much of an issue.  Is £90
How many of these are you building, BTW?  If you are building many, cheaper components might be an issue.
Someone might have another take here; the other shop might be quite reputable, but you have to ask why there is a huge disparity in costs, yes.
If you are wanting to sell stuff online, people may ask for warranties, or expect something to work for N months/years; what would happen if these units fail?

BTW: I'm looking to build one as a prototype, see if I'm still interested, make it permanent, see if I'm still interested, then maybe sell a few online. But that doesn't matter. Do you mean actually ask (as in an e-mail)?

Question: do I email The Pi Hut or DFRobot, the manufacturer of most of the components?

I designed a battery backup power supply for a product at my work. I included the INA219 current/voltage measurement chip. For the prototype run I bought that part from two Aliexpress sellers since the cost was half of what it would cost through our normal distributors. (two orders of 50) Half of the chips we way out of spec. Some would read current okay but the voltage was off. Some the voltage was okay and the current was off. I suspect one order of the 50 was badly out of spec parts but since we didn't track which chips ended up in which boards we didn't know which was the bad batch.
In another case, we had been using a cheap buck converter (dc-dc power supply) normally called Mini360. It was a very good module and the chip was from a major IC manufacture. It was cheaper for us to buy the module than to buy the parts so I included it as a through hole component in some of my designs. A couple of months ago we had experienced some problems with a product and I then found that the Mini360 modules we were using was different. The pcb was different, a tiny bit smaller, and the switching regulator use was from a China manufacture. It was a knock-off of the original chip on the earlier Mini360. Because of what we were doing in our product, the new knock-off part caused problems for one of the designs. The part does the same job as the original part, but it wasn't the same. And how it worked for us, in one specific product, meant that I couldn't use it. On the next revision of the product I designed out the module and implemented the module onto our smd board. And we buy the original part from our normal distributors, not China. It costs us more but we need reliability.
For my hobby I use the Arduino framework as it was easier for coding. (I'm a hardware designer) I also use cheap available parts targetted for the Arduino user base. Most of the stuff is decent, good enough. But there always is a higher level of risk when we buy these cheap parts.

that "ebay gamble" is part of the excitement for amateurs, but you're right about relaying on loose-specification listings to refresh an existing supply line for a commercial finished product.

The main reason that some devices on eBay, or where ever, are markedly cheaper is that they are clones produced by a third party, using designs that have been copied/pirated or reverse engineered.
This reduces the third party's set up costs, quality assurance (QA) (i.e. testing) costs and research and development (R&D) costs to almost zero (compared to those of the original manufacturer).
So, generally, the board will, for all intents and purposes, be the same physically, just at a much lower cost, and, as dandavis states in his comment, probably with the same reliability and quality.
However, if you purchase these clones, then the research and development aren't being paid for and may inhibit further growth in the market.
In addition, sometimes the cost is reduced even further as the third party cloner will use inferior and cheaper, alternative, components which may cause the device to fail sooner than the original. They may even come from the same factory and be devices that are using the original components, but which have failed the QA process, for one reason or another... and then fail in extreme circumstances.
So, in summary, you are taking a gamble (albeit a small one), and whilst generally you will end up with a device of the same quality, you may sometimes end up with a bit of a lemon.

The stuff adafruit actually makes (PCB modules+learning kits) can't be beat. But don't forget they also sell a ton of stock items at prices that simply tax noobs, ex selling for a quarter something you can get for about a penny. I think adafruit just buys such items from 10 different ebay sellers, chooses the best sample, and orders thousands more from that vendor to hawk to suckers. Adafruit is not some non-profit, they are there to make money, and they are good at it.