Set Low Power Level or Enable Pin of stepper driver, so stepper does not get hot I am using the code below with this stepper shield:

https://www.dfrobot.com/wiki/index.php/Stepper_Motor_Shield_For_Arduino(DRV8825)_SKU:DRI0023

Everything works, but tends to get hot (62.3 Celsius) while holding in idle position. What I understood so far, to reduce the temperature I can:

Set enable pin only when I need to turn the motor, but loose my position.
I can use what the driver manual describes as low level. Which I did not entirely understand.

If I set the enable pin to low by doing digitalWrite(M1en,LOW); do I put the stepper in low power mode or do I switch off the power to the stepper ?

I could only enable the stepper (if by setting it to LOW or HIGH I enable, disable) when I need it. Which would be the best as I understood it.

Where in my code below would I have to add the digitalWrite LOW,HIGH to achieve this ? Or do I need to just set it LOW (for low power mode).

Or is there a much better way I don't know about.

Code:

const int dirPin = 4;
const int stepPin = 5;
const int M1en = 12;

int speed = 200;    // desired speed in steps per second
int steps = 0;      // the number of steps to make

void setup()
{
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  digitalWrite(M1en,LOW);// Low Level Enable
  Serial.begin(9600);
}

void loop()
{
  if ( Serial.available()) {
    char ch = Serial.read();

    if(isDigit(ch)){             // is ch a number?
      steps = steps * 10 + ch - '0';        // yes, accumulate the value
    }
    else if(ch == '+'){
      step(steps);
      steps = 0;
    }
    else if(ch == '-'){
      step(-steps);
      steps = 0;
    }
    else if(ch == 's'){
      speed = steps;
      Serial.print("Setting speed to ");
      Serial.println(steps);
      steps = 0;
    }
  }
}

void step(int steps)
{
  int stepDelay = 1000 / speed;  //delay in ms for speed given as steps per sec
  int stepsLeft;

  // determine direction based on whether steps_to_mode is + or -
  if (steps > 0)
  {
    digitalWrite(dirPin, HIGH);
    stepsLeft = steps;
  }
  if (steps < 0)
  {
    digitalWrite(dirPin, LOW);
    stepsLeft = -steps;
  }
  // decrement the number of steps, moving one step each time
  while(stepsLeft > 0)
  {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(1);
    digitalWrite(stepPin,LOW);
    delay(stepDelay);
    stepsLeft--;      // decrement the steps left
  }
}

The product page you gave has a link to the DRV8825 datasheet.

Reading this, it is clear that the enable pin(s) comlpetely disable the H-Bridge that drives the motor coils. This is low power mode. It'd doesn't mean low, but non-zero holding current. The driver only supports enabled and disabled.

If your steppers are getting hot, perhaps the current being supplied by the driver is too high. The maximum drive current is set by the current-sense resistors attached to the driver chip. These may not be easy to change. To decrease the maximum current, you increase the current-sense resistor.

The product page notes that the shield has the current set at 1.6A per coil.


Is there a pullup on I2C? I am using an Arduino Uno R3.

It is not clear on the schematic whether there are pullups on the A4 and A5 I2C pins.

Are there hardwired pullups or do I have to add them myself?

There are very weak internal pullups, but they are not strong enough to be considered compliant with I2C specs. Supply your own external 2.2k-10kohm pullup resistors.


Custom DAC for Arduino UNO I am currently following this tutorial on building a Simple Audio Player for the Arduino. I was about to finish the circuit only to realize that the required board is an Arduino Due and I have the Uno.

Because the Uno does not have its own DAC port, I was wondering what other options are available for me to accomplish the same thing while keeping the circuit as similar to the one listed in the tutorial.

Thanks

There are three basic ways of creating a DAC.

The simplest, though roughest, is to use PWM, then low-pass filter it.  Not perfect, but rough and ready. Only needs a resistor and a capacitor.

The highest quality way, though slowest for interfacing, is to use an external DAC chip. Fine for low frequency response reproduction, and the linearity is second to none. The MCP4821/2 is a popular choice (SPI connected).

The third option is to build your own DAC using an R-2R ladder. You can make an 8-bit DAC with very fast response by using all 8 pins of a single IO port (such as pins 0-7 on the Uno are bits 0-7 of port D). However the linearity of an R-2R ladder very much depends on how well matched your resistors are.

The R-2R ladder should be buffered with an amplifier of some form before driving a low impedance device like a speaker.

None of them are really great for audio work - for that you need a chip with much more processing power and memory, and a high speed digital audio interface, such as I2S, to interface a proper audio CODEC chip. Personally I use PIC32MZ chips for audio work.


Is it difficult to do high voltage parallel programming using Nick Gammon library? I have bricked a few AT328P by invalid fuse settings.

Has anybody used the above sketches and the associated circuitry to perform high voltage programming?

I have not tried with those instructions, as I have an AVRDragon, but it's a good exercise for precision, since you have to wire lots of pins.

20+ iirc

My guess is that if anything fails, it's likely to be because of a mistake in the wiring.

If you are planning to do it often, you might consider soldering the wires and the ZIF socket to a prototype board, to preserve your mental sanity.


ESP8266 Stops Working if I don't provide Wifi during specifc step To test the WiFi connection I'm sharing the WiFi of my cellphone.

If I stop the WiFi sharing during the command below, the ESP8266 stops working.
It only works if I do a hardware reset.

If I don't stop the WiFi it works normally.

    if(client->POST(urlCal, host, payload))
  { RetornoPost = client->getResponseBody(); }

HTTPS Redirect (Version 2.0)
ESP8266 library version 2.4.2

Does anyone know why ESP8266 stops working?

If by "stops working" you mean it doesn't do whatever follows the client->POST method invocation, then your interpretation is correct and you could have found my very same information if you had read the open issues on the library before submitting your own.

If I were the author of the library I would be upset by such behavior.


uint8_t etc as color variable I am very new to coding and I am attempting to teach myself the best I can.  I have no prior knowledge of coding and am filling in the blanks via YouTube and forums alike.  One place I keep getting hung up on is what seems to be an unsigned integer.

I have tried to figure out how these work (assignment and such) to no avail. I was wondering if anyone could offer some insight for me or at the least a link that gets specific for the Arduino.

I see them used as uint8_t, uint16_t, and uint_32 in various places.  Am I correct that it is an unsigned integer?  Meaning it is a whole positive number only.

The code I have attached is from Adafruit's article on multi-tasking.  I am trying to adapt my sketch for millis() over delay().

      uint32_t Color1, Color2;  // What colors are in use
      uint16_t TotalSteps;  // total number of steps in the pattern
      uint16_t Index;  // current step within the pattern

For instance: on the variable declarations they use these for the color.  I will need to change the colors, but have only seen them expressed in RGB.  They are in every sketch I see, but I am struggling to answer this question on my own.  Thanks in advance for any help.

If you search for information about C types on the internet, there will be much help to find, but effectively you are correct. One format of integer types in C take the form:
uint / int: Signed or unsigned integer. Unsigned integers are stored in simple binary representation, and signed integers are stored in two's complement form.
8 / 16 / 32 / 64: The number of bits to store the value. This means the number of possible values is 2x where x is the number of bits.
_t: Simply a suffix to indicate that it is a type name, not a variable.

Colour storage
Colours are generally stored as three components: red, green and blue (or sometimes four, adding alpha, the degree of transparency).
If each component is given an unsigned byte to be stored (so it has a value from 0–255), then the total colour size is 24 bits. However, 24 bit integers are not a standard size, so the next bigger size is selected, 32-bit. This also allows room for an alpha component if necessary, but otherwise the spare 8 bits are unused.
For example:
| 00000000 | 00000000 | 00000000 | 00000000  | = 32 bits
| red      | green    | blue     |alpha/empty|


What if I detach AVR micro controller from the Arduino Board after uploading program? What if I detach AVR microcontroller from the Arduino Board after uploading program? Does the microcontroller still have the program on it? Or the program will be deleted?

On the board where does Arduino store hex file?

I am very beginner in Embedded Programming. I am learning about microcontroller and Arduino. While learning about programming Arduino-Uno I got these question in my mind.

The AVR µC got a flash memory that can store the code loaded in. That mean you can load the code with the arduino board, detach the avr and put it on another circuit. If the µC is powered well, it will behave just like the arduino.

Don't forget to set the /reset pin to high, if you do, the µC will be stuck to the 1st line of code ;)


Can't send DHT11 temperature data to Xively from Yun I thought this would be easy but how wrong I am... All I want to do is plot temperature data but I can't seem to get it to work. It reads it out on the serial monitor and says it has sent the data (in the serial monitor) but nothing on the Xively plots! Why?? Below is the code.

I have the API key and feedID from the Xively site. The useragent I'm assuming is the name of the project. My channels are called sensorValue1 and sensorValue2. Please help - this is taking me far too long.

#include <Bridge.h>
#include <Console.h>
#include <Process.h>

#include "DHT.h"
#define DHTPIN 0
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

 #define APIKEY "BLablablablabla" // your pachube API key
 #define FEEDID blablabla // your feed ID
 #define USERAGENT "SebYun2" // user agent is the project name

// set up net client info:
const unsigned long postingInterval = 60000; //delay between updates to xively.com
unsigned long lastRequest = 0; // when you last made a request
String dataString = "";

void setup() {
  // start serial port:
  Bridge.begin();
  Serial.begin(9600);
  dht.begin();
  while(!Serial); // wait for Network Serial to open
  Serial.println("Xively client");
  // Do a first update immediately
  updateData();
  sendData();
  lastRequest = millis();
}

void loop() {
  // get a timestamp so you can calculate reading and sending intervals:
  long now = millis();
  // if the sending interval has passed since your
  // last connection, then connect again and send data:
  if (now - lastRequest >= postingInterval) {
    updateData();
    sendData();
    lastRequest = now;
  }
}

void updateData() {
  // convert the readings to a String to send it:
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  dataString = "Temperature,";
  dataString += dht.readTemperature(false);
  delay(250);
  // add pressure:
  dataString += "\nHumidity,";
  dataString += dht.readHumidity();
  int sensorValue1 =  analogRead(A0);
  delay(100);
  int sensorValue2 =  analogRead(A0);
  dataString += "\nVoltage1,";
  dataString += sensorValue1*0.0049;
  Serial.print(sensorValue1);
  dataString += "\nVoltage2,";
  Serial.print(sensorValue2);
  dataString += sensorValue2*0.0049;
  delay(1000);
}

// this method makes a HTTP connection to the server:
void sendData() {
  // form the string for the API header parameter:
  String apiString = "X-ApiKey: ";
  apiString += APIKEY;
  // form the string for the URL parameter:
  String url = "https://api.xively.com/v2/feeds/";
  url += FEEDID;
  url += ".csv";
  // Send the HTTP PUT request
  // It is better to declare the Process here, so when the
  // sendData function finishes the resources are immediately
  // released. Declaring it global works too, BTW.
  Process xively;
  Serial.print("\n\nSending data... ");
  xively.begin("curl");
  xively.addParameter("-k");
  xively.addParameter("--request");
  xively.addParameter("PUT");
  xively.addParameter("--data");
  xively.addParameter(dataString);
  xively.addParameter("--header");
  xively.addParameter(apiString);
  xively.addParameter(url);
  xively.run();
  Serial.println("done!");
  // If there's incoming data from the net connection,
  // send it out the Serial:
  while (xively.available()>0) {
    char c = xively.read();
    Serial.write(c);
  }
}

As long as I checked, this way of uploading data to Xively only works for up to tree pairs of name,data.

If you try with more pairs at the same time the response is "Done", but nothing happens. I finally divide the upload in groups of 3 parameters, and everything is Ok.

I saw your question yesterday when I was looking for a way to upload data to Xively from Yun. It was really helpful for me. Thank you.


9 DoF Sensor Accelerometer Readings Inconsistent I have the following sensor stick: https://www.sparkfun.com/products/10724

It has an accelerometer, gyroscope, and magnetometer.

I have connected it to an arduino and am reading the accelerometer values while the sensor is completely flat and the values jump all over the place:

ie
0
2
3
7
-5
12
35
-3
...

This is how I am reading them:

void Accel_Init()
{
  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.write(0x2D);  // Power register
  Wire.write(0x08);  // Measurement mode
  Wire.endTransmission();
  delay(5);
  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.write(0x31);  // Data format register
  Wire.write(0x08);  // Set to full resolution
  Wire.endTransmission();
  delay(5);

  // Because our main loop runs at 50Hz we adjust the output data rate to 50Hz (25Hz bandwidth)
  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.write(0x2C);  // Rate
  Wire.write(0x09);  // Set to 50Hz, normal operation
  Wire.endTransmission();
  delay(5);
}

// Reads x, y and z accelerometer registers
void Read_Accel()
{
  int i = 0;
  byte buff[6];

  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.write(0x32);  // Send address to read from
  Wire.endTransmission();

  Wire.beginTransmission(ACCEL_ADDRESS);
  Wire.requestFrom(ACCEL_ADDRESS, 6);  // Request 6 bytes
  while(Wire.available())  // ((Wire.available())&&(i<6))
  {
    buff[i] = Wire.read();  // Read one byte
    i++;
  }
  Wire.endTransmission();

  if (i == 6)  // All bytes received?
  {
    // No multiply by -1 for coordinate system transformation here, because of double negation:
    // We want the gravity vector, which is negated acceleration vector.
    accel[0] = (((int) buff[3]) << 8) | buff[2];  // X axis (internal sensor y axis)
    accel[1] = (((int) buff[1]) << 8) | buff[0];  // Y axis (internal sensor x axis)
    accel[2] = (((int) buff[5]) << 8) | buff[4];  // Z axis (internal sensor z axis)
  }
}

Am I doing something wrong that these values aren't the same?

In 'FULL_RES' mode the number you get is amount of 4mg units.

So 1 is 4mg, 2 is 8mg, -4 = -32mg.

Also note that your current code doesn't interpret the first bit (so the 13th from the right) as the sign bit, so you'll never get negative values. (Question related to this)

PS I think it is actually more like 3.9mg.


Unstable reading from pushbutton on digital pin I use the Pin 7 to get the status of a push button. I put 10Kohm R on the - .

The status is unstable because arduino says thet I push it but it is not true...

int button = 7;
...
// var for reading pushbutton value
int buttonState = 0;
...
buttonState = digitalRead(button);
  if(buttonState == HIGH)
  {
    myFunction();
  }

EDIT :

ARDUINO PIN 7 <---> R 10Kohm <--> [switch] <---> VCC

At the moment, your resistor isn't doing anything useful. When your switch is open, the pin is still 'floating', which means it's ending up with random stray readings from nearby electromagnetic fields.

You basically need two connections coming from your Arduino pin. One goes through a resistor straight to ground. The other goes through your switch straight to +5V.

In that case, the resistor is acting as a pull-down, because it holds your pin at Ground whenever the switch is open. You could swap over the ground and +5V, and it the resistor would function as a pull-up instead.

This question deals with the same kind of issue:

Button state changing randomly


panstamp device signature is random I Have 2panstamp. I can program the first but not the second with the arduino program.

When I upload the sketch (a simple blink) on the second, I got this

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

avrdude: Device signature = 0x004e22
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.

avrdude done.  Thank you.

And if I retry, I got this.

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

avrdude: Device signature = 0x81f014
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.

avrdude done.  Thank you.

The device signature is not the same anymore ...
I've changed the wire and re-open arduino program. But it don't change, the device signature change (often 0xE1E1E1). I've check the connection between the ATmega and the wire and everything is ok.

Is the Panstamp broken ? or should I do a kind of factory reset?

Is the Panstamp broken ?

Sounds like it. If one works, and the other does not, using the same wiring, it looks like you have a faulty one.

  or should I do a kind of factory reset?

You can't really "factory reset" a chip like that. Possibly there is a problem with the fuses. You may be able to explore further here:

Have I bricked my Arduino Uno? Problems with uploading to board


How to get air speed, which sensor to use? I want to measure the airspeed on a flying vehicle and get the data with arduino. Note that, there will not be any control mechanism on the flying object, it will be flying mechanicaly/passively, I mean no flight controller or something like that will be present.

However, I could not understand whether there is a sensor to measure the airspeed directly or is airspeed something you analyze by using other datas(temperature, pressure etc.)

I saw there are sensors which are sold as "airspeed sensor" however it is not so common that I cannot find examples in which the incoming data is shown.

Anybody ever experienced with this issue may lighten me.

Thanks in advance.

Typically you want to use Pitot tube sensor


Why to store a function parameter value in a class private variable? I'm just curious, I'm going through a C++ library for the mcu2.4 TFT display.

And this method I notice when I run through C++ libraries.

Which is when a parameter is passed through a function, it's stored in a private variable; like this one:

HCTFT::HCTFT(byte DisplayType)
{
    _Display = DisplayType;

What's the benefit of this method? What's the similar method when I want to do it in C code?

The reason is that _Display will be used probably after its construction.

So you pass the byte during construction, and afterwards the value is available during the object's lifetime.

In C you probably will do this by:

Passing the variable (byte DisplayType) in each function where the value is needed (you can use this way in C++ too but it's cumbersome in both C/C++ to pass the variable in all functions needed).
Storing it in a global variable (static for that .c file); this is the typically C method.

* Added explanation *

Such a variable is called class variables and are mostly made private. The reason is that other objects cannot change the value directly. The only way to change a variable is:

By initializing it in the class constructor (like in your example).
Within the class itself (by any method).
By a typical Set method (like SetDisplayType). This method can check if the value passed is within a range, and there is only one entry point in this class to change it.

To retrieve the value, typically a GetDisplayType method should be created which is public. The variable itself is private.


Error compiling: expected unqualified id before token { #include <LiquidCrystal.h>
#define trigPin 12              // the trig pin to digital pin 12
#define echoPin 13              // the Echo pin to digital pin 13
#define led 8
#include <Servo.h>
Servo servoMain; // Define our Servo

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600); // Starts the serial communication
  lcd.begin(16, 2);
  servoMain.attach(11); // servo on digital pin 11
}

void loop() {
  servoMain.write(5);  // Turn Servo Left to 5 degrees
  delay(1000); // Wait 1 second
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 3) {
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("PLEASE REFILL!");
    lcd.setCursor(0, 1);
  } else {
    digitalWrite(led, LOW);
  }
  if (distance < 6) {
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("U May Refill Now");
    lcd.setCursor(0, 1);
  } else {
    digitalWrite(led, LOW);
  }
  if (distance < 8) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Take it easy");
    lcd.setCursor(0, 1);
  }
  if (distance <= 16) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("FULL!!");
    lcd.setCursor(0, 1);
  }
  if (distance > 16 || distance <= 0) {
    Serial.println("Out of range");
  } else {
    Serial.print(distance);
    Serial.println(" cm");
  }
}
delay(1000);

}
    }

At line 82 you have the closing bracket of the loop function. Then after that you have:

  delay(1000);

}
}

Which is invalid.

If you format your code properly it's easy to see. Fix that and it will compile. Will it do what you want is an other question...

#include <LiquidCrystal.h>
#define trigPin 12        // the trig pin to digital pin 12
#define echoPin 13        // the Echo pin to digital pin 13
#define led 8
#include <Servo.h>
Servo servoMain; // Define our Servo

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup()
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600); // Starts the serial communication
  lcd.begin(16, 2);
  servoMain.attach(11); // servo on digital pin 11

}
void loop()
{
  servoMain.write(5); // Turn Servo Left to 5 degrees
  delay(1000);     // Wait 1 second

  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

  if (distance < 3) {
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("PLEASE REFILL!");
    lcd.setCursor(0, 1);
  }
  else {
    digitalWrite(led, LOW);
  }

  if (distance < 6) {
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("U May Refill Now");
    lcd.setCursor(0, 1);
  }
  else {
    digitalWrite(led, LOW);
  }

  if (distance < 8) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Take it easy");
    lcd.setCursor(0, 1);
  }

  if (distance <= 16) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("FULL!!");
    lcd.setCursor(0, 1);
  }

  if (distance > 16 || distance <= 0) {
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
}
delay(1000);

}
}


Using Serial Plotter with Visual Studio Code I'm using the Visual Studio Code extension to develop for Arduino which works great.

It doesn't have a Serial Plotter like the regular Arduino IDE, which I need to debug this project. I can run the Arduino IDE's Serial Plotter alongside Visual Studio Code without too much of a problem.

However, if I try to compile and upload from Visual Studio Code while the Arduino IDE is running, the port is busy (not a surprise):

avrdude: ser_open(): can't open device "/dev/cu.usbmodem14201": Resource busy
An error occurred while uploading the sketch

So I have to keep exiting and relaunching the Arduino IDE every time I build.

Anyone have a suggestion for how to work around this? Using an iMac as development environment.

Without very specialized software that can create two new devices with the correct "teeing" policy, it's not going to be possible.  Only one program can open a serial port at a time (certainly and have it get anything intelligible out of it...)

I would suggest you may want to add a second serial port.  Use an FT232 adaptor to communicate on another serial connection (or a SoftwareSerial connection at a pinch) for your debugging information.  You really want a board with more than one serial port for this - or a board with a native USB for programming and a hardware serial port for data communication.

Another alternative is to ditch the serial for programming altogether and program your board through a dedicated programmer, thus leaving your serial port free for data communication.


W5100 Ethernet Shield to Custom Board Problem I've been using an Arduino Ethernet shield and an Arduino Mega in my project, but now I'm trying to migrate all the components onto my own PCB. My board uses a W5100 same as the Arduino, but nothing shows up when I connect Ethernet to my computer. Even if there is no communication with the MCU the W5100 should show up as a network device and starting pinging.

I have spent A LOT of time troubleshooting this issue, and I would like to confirm one thing. Using the factory default register settings, I should be able to just connect the W5100 to my computer, and it will start pinging back and forth and be identified as a network device . . . assuming I have the circuit set up correctly just like the Ethernet shield. I used a combination of the recommendations from Wiznet and the Arduino Ethernet shield schematic to make mine.

Edit:
Here is my schematic for the Ethernet module. The question I'm really trying to get answered first is regarding the default state of the W5100. Do I need to set some registers or something to get the W5100 in the same state it is in on the Arduino shield?

A bit late to the party but... it may be that you are using pins 1, 2, 3 and 4 instead of 1, 2, 3 and 6 on the RJ45. It is unclear whether you are connecting via a header, in which case you my disregard this, or straight to the RJ45, in which case you need to change your pin:

1. white/orange
2. orange
3. white/green
6. green


Arduino IDE has no shortcut in openSUSE I just installed the Arduino IDE in openSUSE 13.1. I am able to open the application using the run dialogue, so I know it has installed. However, there is no way to open the IDE from any application launcher. I have tried both the Kickoff and Lancelot applciation managers. I have also tried to uninstall and re-install the IDE, both through the 1-click on the Arduino website as well as through the command line.

Does anyone know why I am unable to launch the application from the launcher? Thanks in advanced for any help!

I had the same problem and this seems to work. If you right click on the Kickoff Application launcher and open 'edit applications' with KDE Menu Editor, you can 'add new item' where you want and give it a name (ArduinoIDE) and then just put arduino (small case) in the 'command' box, and shut down KDE Menu Editor, it should appear in the menu where ever you placed it. At least it did for me.


What is the opposite of this data operation? If I store in an array a double-value in this format, in which format I should be able to read the same double out?

double myDouble = 12.123456;
byte myArray[] = {0x00, 0x00, 0x00, 0x00};

myArray[0] = (myDouble >> 0);
myArray[1] = (myDouble >> 8);
myArray[2] = (myDouble >> 16);
myArray[3] = (myDouble >> 24);

You are better off making a union, that will be compiler independent, and won't give you the (possibly) odd results that trying to shift a double would give.

Example:

  union
    {
    byte myArray [4];
    double myDouble;
    } foo;

   foo.myArray [0] = Serial.read ();
   foo.myArray [1] = Serial.read ();
   foo.myArray [2] = Serial.read ();
   foo.myArray [3] = Serial.read ();

   double f = foo.myDouble;

Even then be cautious that whatever is sending you this double in 4 bytes is using the same encoding for doubles that the Arduino does. For one thing, double and float are the same on the 8-bit Arduinos (they are only 4 bytes).


Problem with load cell and ADS1262 I'm using PROTOCENTRAL ADS1262 32-BIT PRECISION ADC BREAKOUT BOARD to read the voltage in simple a load cell.

The connections follows the instructions on its library

But I cannot make it work, the readings has lots of spikes and i cannot discover what is happening.

Can someone help?

This problem was solved on Texas Instruments Forum.
Thanks.

http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/p/627185/2344271#2344271

From the TI forum:

  I noticed that you are polling data ready and then performing the data processing/serial output. The serial output operation is likely taking a long time and preventing you from capturing data at the faster data rates. You can try disabling the serial output and using an oscilloscope to see if you're able to reading data at the full throughput; however, when outputting this data over a serial interface you might not be able to capture and display all of the data...

  I would try capturing data to memory and outputting the serial data in batches (for example, output 10 samples of data at a time). This might give you a little more data throughput.


Adruino Yun's Linux environment not working I was recently given an Arduino Yun board from my university. I am able to upload sketch to the board, and it seems to function properly. However, I am unable to see the Linux booting up. When I want to reset the WLAN, ressing the WLAN RST button does nothing at all, the WLAN LED doesn't even blink or light up. Pressing the YUN RST button also does nothing.

So I did some Googling and found out that I could upload the YunSerialTerminal to the Yun, so I did that. And when I am trying to monitor the Linux boot up from the serial monitor. Nothing is shown. I press the TUN RST button as taught by the Arduino website while monitoring the Serial Monitor, nothing shows. However, the RX button does blink whenever I press enter.

Can anybody help me?

You might need to re-flash the operating system. Unfortunately it's not a trivial task.

I had to do something similar with a Dragino shield (like a Yun on a shield) that uses the same OS and core chip. Instructions were scarce and hard to follow, plus I run Linux, so there's even less instructions. I worked it out, though, and wrote a tutorial here.

While that is for Linux and the Dragino shield I am sure the basic principles are the same for the Yun - just make sure you get the right image file for your Yun (don't get the Dragino one I link to).

The main thing is to gain access to the boot manager (dr-boot, or whatever the Yun has), which means setting up a wired (ethernet) network and messing with UDP sockets (using nc in Linux - no idea what you can use in Windows).

I'm sure you can find a tutorial for fixing the Yun from Windows (or whatever OS you use) to help you get into the boot manager and upload a new OS image.


Activate a DC motor for a fixed amount of time I have a single simple DC motor that upon a condition I wish to let it run for 3 minute. How can I do it in Arduino? a simple addition to the code will be great help.

As I use Adafruit motor shield this is my current code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);

void setup() {
   Serial.begin(9600);           // set up Serial library at 9600 bps
   AFMS.begin();  // create with the default frequency 1.6KHz
}

void loop() {
IOvalue = 1000

if (IOvalue = 1000) {

 //this is the motor I wish to run for 3 min
   myMotor->setSpeed(25);
   myMotor->run(FORWARD);
   delay(100);
 }
}

Thanks a lot

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
boolean motorRunning = false;
unsigned long motorStartMillis;
unsigned long motorRunMillis = 180000;

void setup() {
   Serial.begin(9600);           // set up Serial library at 9600 bps
   AFMS.begin();  // create with the default frequency 1.6KHz
}

void loop() {
  IOvalue = 1000

  if (IOvalue = 1000) {
    //this is the motor I wish to run for 3 min
    myMotor->setSpeed(25);
    myMotor->run(FORWARD);
    motorStartMillis = millis();
    motorRunning = true;
  }

  // check if motor is running and time-to-run has elapsed
  if( motorRunning && (millis()-motorStartMillis > motorRunMillis) )
  {
    myMotor->setSpeed(0);
    myMotor->run(RELEASE);
    motorRunning = false;
  }
}


ESP8266 reseted due to relay / AC plugged My Wemos card is reseting for unknown reason. For example, the pump plugged on the relay works fine till 1am and then the pump stop. After a few research I figured out the ESP should reset because all internal parameters are reseted.

My hardware is simple Wemos card + relay + sensors (not here because not connected yet).

My program is quite complex. I can command/configure the wemos via webservice (ex relay on pin 5 with on 5min/off 10min).
https://github.com/TittyPanda/ESP-commander/blob/master/ESP-COMMANDER

OK if no AC device is connected on relay (no reset)
OK if a light is connected on relay
The issue occurs only when the water pump is connected

Maybe it's an electrical/electromagnetical thing because the pump has motor. What do you think ?

Thanks,

EDIT
Power part are done with common wires from power extension cord

AC-DC converter 5 V 1A 1.5A 500mA

Pump 40W 3000L/H 220V 50Hz

Try add some power filter like this:

Between the breadboard and ESP board.


convert byte and float to char I am trying to send sensor values to internet via enc28j60 module and web client example.

My problem is that i chose byte and float form for some sensors i can't convert these values to char form.

Code example below

UVSensorValue = analogRead(A0);               // UVSensorValue is in byte form
concentration = 1.1*pow(duration,3)-3.8*p...  // concentration is in float form

I want to store them in a char variable like this:

  param = "uv=5&temp=23.2&dust=0.62..."

And send them here:

ether.browseUrl(PSTR("/measures?"), param, website, browseUrlCallback);

I tried strcpy function or String convention but nothing worked. I know its a silly question however i stuck and cant find solution.

If someone could help me i would be pleased. Thanks in advance!

In any other C/C++ platform, you can use "%f" as a format specifier when you want to print (or convert to string) a float using printf or its siblings. Any, except in Arduino.

To convert a float you need use dtostrf(),

char * dtostrf(
    double __val,
    signed char __width,
    unsigned char __prec,
    char * __s)

  The dtostrf() function converts the double value passed in val into an
  ASCII representationthat will be stored under s. The caller is
  responsible for providing sufficient storage in s.

  Conversion is done in the format "[-]d.ddd". The minimum field width
  of the output string (including the possible '.' and the possible sign
  for negative values) is given in width, and prec determines the number
  of digits after the decimal sign. width is signed value, negative for
  left adjustment.

  The dtostrf() function returns the pointer to the converted string s.

To convert a byte (or anything not float) to ascii, use snprintf()

int snprintf ( char * s,
               size_t n,
               const char * format,
               ... );

  Write formatted output to sized buffer.

  Composes a string with the same
  text that would be printed if format was used on printf, but instead
  of being printed, the content is stored as a C string in the buffer
  pointed by s (taking n as the maximum buffer capacity to fill).

You can read the details by yourself, but here is a demo.

The idea is to produce in buffer a traditional C-style string (null terminated). That string you can print or transmit.

The float value is printed in two step. First, we use dtostrf to convert the float value to his ascii representation. Then we use snprintf to include that value (as a string) inside a whole line, latter to be printed.

void setup() {
  Serial.begin(9600);
  while(!Serial);
  Serial.println("Start");

  float value = 123.45;
  byte balue = 128;

  char buffer[80];
  char fValue[16];
  dtostrf(value, 3, 2, fValue);
  snprintf(buffer, sizeof(buffer), "float %s", fValue);
  Serial.println(buffer);
  snprintf(buffer, sizeof(buffer), "byte value is %d", (int) balue);
  Serial.println(buffer);
}

void loop() {

}


Sketch Memory in Pro void storedata(File filename ,int type , String data)
{
    if(type == 1){
      Serial.println("Group Creation");
    }
    //Storing Data into file
    pinMode(10, OUTPUT);
    if (!SD.begin(SD_CS_PIN)) {
    Serial.println("initialization failed!");
    return;
  }
    Serial.println("initialization done.");
    filename = SD.open("filename.txt", FILE_WRITE);
    if (filename) {
    Serial.print("Writing to filename.txt...");
    SdFile file("sdfile.txt", O_WRITE | O_CREAT);
    if (!file.isOpen()) {
    Serial.println("filename.txt");
   }
    sdfile.println(data);
    //close the file:
    filename.close();
    Serial.println("done.");
    }else{
    // if the file didn't open, print an error:
    Serial.println("error opening filename.txt");
  }}

Im using this function to write on the Sd card , before calling this function the sketch memory is 28802 bytes ie ) 93% , simply just by calling this function from setup increased the sketch memory to 102% and iam unable to compile is there any unusual memory usage in this code ?

If you have a function that isn't called the compiler will just delete it (optimise it out). It also deletes any functions that the function calls that aren't used anywhere else.

By then calling that function the compiler keeps it, along with any other functions it relies on.

That includes the SDFat library code, much of which will have been removed before.

To make it now fit you will have to optimise your program. Look for blocks of code that do the same thing and replace them with calls to a function. Look for parts that could be replaced by a loop and an array instead of discrete calls to the same function(s) over and over again. Things like that.

Either that or use a board that has enough flash for your project.


Manual reset is required on power on I am powering a UNO through the 5V pin. I am using a tftlcd shield (2.8" mcufriend.com) on it.

To be able to use the shield with I2C I had to snip the RST leg from the shield. That was done because the shield used A4 which was required for I2C.
 When I power the UNO through the USB port the program starts correctly and a bitmap is loaded onto the screen. When I power up from the 5V pin or the power adapter, the screen remains white. I have to manually press the reset button on the UNO and then the program loads the bitmap.

The ladyAda examples had this to say;

#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

Does that mean I should solder the lcd RST pin to the RESET on the UNO? (if so I am not sure how I can do that without taking the lcd shield to pieces).

It isn't clear from the description whether your setup has a hardware problem or a software problem.  For example, the rationale for “I had to snip the RST leg from the shield” is unclear.

The comment in ladyAda's example, “Can alternately just connect to Arduino's reset pin”, means that it's suitable to hardware-reset the LCD at the same time the Arduino does a hardware reset.  If the “RST leg from the shield” that you snipped is the LCD reset pin, as opposed to a pin driven by the small tactile reset switch on the 2.8" mcufriend shield, you probably should restore that pin.  In other words, unsolder and remove the stub of the pin you snipped off, insert a new pin, and solder it in place.

Note, just reinstalling the pin might make things work.  It's possible the LCD is sitting there in a permanently-reset  state, due to its RST input hanging open.  It's also possible the library is already driving RST properly but that drive isn't getting through, due to the missing pin.  Whatever the case may be, with the pin in place you should be able to software-reset the LCD by pulsing A4.  (Ie, with consecutive digitalWrite() commands, in setup() and before shield initialization, take A4 high and then low, or vice versa.)

Edit: If A4 isn't available for resetting the LCD (due to its use as the SDA signal for I2C, per comment) you might try adding a jumper wire from the shield's LCD_RS pin (above A4) to an available pin, and adjust the #define LCD_RESET statement accordingly.

In general, to add a jumper wire, strip about 5 mm of each end of a short piece of #30 wire-wrap wire.  Form a small hook at each end.  Hold a hook onto the solder of the pin you wish to attach to and briefly heat the solder, letting the hook sink into the solder.  If you don't have wire-wrap wire, use a single strand from some old stranded cable (eg, mouse or keyboard).  Use thin heatshrink tubing or a bit of stripped-off cable insulation to insulate the jumper.  To keep pins in place while soldering, seat the pins being worked on into an old disk-drive connector, or another shield, or if you have nothing else, an Uno.

In your particular case, an mcufriend shield on an Uno, no pins are available unless you co-opt one of the SD-card-slot signals.  But before doing that, it's probably worthwhile to try your original idea of wiring to the Uno's RESET pin.  Your jumper would run from J3's second pin (A4) to J4's last pin (Reset), installed on the LCD side of the shield.  You should be able to see the trace between the Reset pin and the Reset switch, when identifying the Reset pin.


HC-05 Bluetooth Module Blinking Red Light-Arduino Uno I have looked on google for an answer to my problems to no avail. The you tube video I am following is here: https://www.youtube.com/watch?v=f1v0IMegCvU
So basically on my android, I can't see the HC-05 device show up and the module itself is flashing red unlike the video's flashing blue light. I have connected the circuit exactly like he has in the video with the 2 10K resisters. I am using the same app. What is wrong? Here is my code as I copied from the video.

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  Serial.println("Connection Successful!");
}
void loop()
{
  if(Serial.available()>0){
    int data=Serial.read();
    switch(data){
      case 'a': LEDON();break;
      case 'b': LEDOFF();break;
      default : break;
    }
  }
  delay(50);
}
void LEDON(){
  Serial.println("Led On!");
  digitalWrite(13,HIGH);
}
void LEDOFF(){
  Serial.println("Led Off!");
  digitalWrite(13,LOW);
}

I also get the error avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00 when connected through usb. I do not get any errors when just flashing the arduino without any wires connected to the arduino. I know that the port is correct. Any ideas would be helpful. Thanks.

There are several issues to consider:
• Program downloading
• HC-05 serial communication
• Bluetooth pairing

For the first issue:  The serial-over-USB connection between the development computer and the Uno ties up the Uno's hardware serial RX and TX pins.  There will be a conflict if the development computer transmits when the HC-05's TX is connected to the Uno's RX.  This can be resolved by disconnecting the HC-05 TX when downloading a program.

For the second issue:  The Uno schematic shows 1KΩ resistors between TX and RX on the ATmega328P and RX and TX on the USB chip (ie on an ATmega16U2, or a CH340, etc).  If the HC-05's TX drive is strong enough, it will overcome the drive from the USB chip and work ok.  Note, I would leave out the voltage divider (on the HC-05 RX line) that the video shows.

For the third issue:  The HC-05 in the video mentioned in the question has a blue LED that blinks steadily when the HC-05 isn't paired, and blinks at a long interval when it is paired.  Many HC-05's have red LEDs instead of blue; the LED color is not an issue.  Some HC-05's don't blink at all when paired; that's not an issue either.  What is an issue is that (according to description in question) your HC-05 keeps on blinking, so apparently isn't paired up.

Whether the HC-05 pairs with an Android app is more or less independent of whether you have the HC-05 connected to an Arduino; you should be able to pair your phone with the HC-05 when just Vcc and ground are connected to the HC-05.  If you are having trouble with pairing, try another app; try powering the HC-05 down and up; and try a different HC-05.  I mention trying another app because one serial-terminal app I installed on my Android phone needed the app or the HC-05 to be restarted to pair up after loss of pairing, and the serial-terminal app I replaced it with did not need those actions.  Note, pairing takes a few steps on my phone:  in Settings / Wireless, search for Bluetooth devices; select device; enter its passcode; run an app and tell the app which Bluetooth device to use.


How to make RGB LED blink rapidly one color using FOR or WHILE loop I found a code that turns on different RGB colors but I would like it to blink rapidly one color once called. I dont want to use void loop function to make this possible. My RGB is a cathode. Any help?

int redPin = 8;
int greenPin = 9;
int bluePin = 10;

//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop()
{
    for (int j = 0; j <= 10; j++) //LED simply stays on. No blinking occuring
     {
      setColor(255, 0, 0);
      delay(100);
      setColor(0, 0, 0);
        }
}

void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

Simply do this:

int redPin = 8;
int greenPin = 9;
int bluePin = 10;

//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop()
{
  blinkLed();
}

void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
  red = 255 - red;
  green = 255 - green;
  blue = 255 - blue;
#endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

void blinkLed()
{
  setColor(255, 0, 0);  // red
  delay(1000);
  setColor(0, 0, 0);  // off
  delay(1000);
}

This snippet will blink your led in the red color. Put it in your void loop and you are ready to go.

NOTE: Erase the rest of the void loop before putting this in. Don't delete the function though.

EDIT

FULL CODE ADDED


Can we use serial.begin command anywhere in code? When to use this command? What difference it would create if I add this command in loop function, setup function and declaration section?

You cannot call Serial.begin() in a declaration. Like any program
instruction, you can only use it from within a function. As stated in
Juraj's answer, you can call it as many times as you want. However,
most often it only makes sense to do this in setup(), in order to
initialize the serial link once and for all at the beginning of your
program. Why would you ever want to do this initialization multiple
times?

Thinking about it, I can see two possible scenarios:

Your UART is connected, through a suitable transceiver, to an RS-485
bus. You have several slaves on this bus that require different UART
configurations (different baud rates, or number of data bits, or
parity). Then, each time you want to address one slave, you first
set your UART to the configuration suitable for that particular
slave. In this kind of situation, however, it would be more
convenient to arrange for all the slaves to share the same UART
configuration, if at all possible.
Your UART is connected to a device that continually sends data you
are not interested in. This could be, e.g., a GPS module. Since you
don't want your program to be interrupted every time a character is
received, you keep the UART disabled. Only when you do want the data
you enable it with Serial.begin(), you read as much as you need,
then you disable it again with Serial.end().

There may be other situations, but I bet they are all quite atypical
scenarios. The common practice is to call Serial.begin() once in
setup(), and have the UART enable from there on.


General confusion about how to start I want to test around with my ESP32 and an E-Paper display - yet i am stuck at uploading sketches via Arduino IDE. I get those kind of errors:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x48

and looking into tools,i dont even see my board there - i bought it on amazon and the article just says "ILS - LOLIN32 Lite V1.0.0 Wifi and Bluetooth Board with ESP-32 Rev1 MicroPython 4MB FLASH".

What am i missing here? I am 99% sure i got the pins correct (finally), i got the USB-Serial driver, i got the right port - yet even a simple test sketch i found on the internet didnt work.

The Arduino IDE does not have a core for the ESP32 installed by default.

The problem was solved by explicitly installing the ESP32-Arduino Core in the Arduino IDE according to their manuals

https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/windows.md
https://www.smart-prototyping.com/blog/How%20to%20Install-ESP32-Core-Arduino-IDE


Is ATMEGA328P the same as 16U2? I've been playing with my Arduino for a few months.

But, I just bought a shield that says it needs to be used with ATMEGA328P.  My box says I have a 328P, however, reading the chip, it's inscribed with "ATMEL MEGA16U2".

Does that mean the box is wrong, or is that the same as 328P somehow?

Thanks!!

The 16u2 is related to the ATmega328p, and includes USB, but is more limited in resources.   While it would be possible to make an Arduino-type board from alone, this is unlikely to be what you have.

Rather, it is likely that you have a board with an ATmega328p as the main processor, and also a 16u2 which serves as a USB interface for it.

You could know for sure from what board type you select in the dropdown menu of the Arduino IDE.  If you are selecting something like "Uno" or "Duemilanove" you have a 328p as the main processor.

(The other presently common type of board is the "Leonardo" style where a 32u4 - essentially a bigger version of the 16u2 - is used as a single-chip solution that is both the primary processor and the USB interface.  But if that is what you had, it would not say 16u2 on it, unless it was an attempt to make a more limited "budget" version).


Fast switching of high load using an IGBT I want to control a high load with fast switching times (motorbike ignition coil) using an arduino. I found an IGBT that claims to be purpose built for that use case (ISL9V3040P3). This IGBT has an Vge (th) max of 2.2 V, so I thought I could simply switch the Gate with an Arduino Pin.
But I did some more digging and most people seem to use an additional IGBT driver (like IR2127PBF). What´s the reason for that? Is it because the arduino can´t provide sufficent current?

One of the key requirements for IGBT driver circuits is
that enough current be supplied to charge and discharge
the input capacitance of the IGBT and thus to switch the
IGBT on and off at very high Switching rates.


Arduino accepting only alternate characters I am writing an Arduino code to receive SMS from a SIM800 module and then send the same message back to the sender. My code is as follows:

#include<SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);//Connect to pin 9&10 on GSM module

const byte numChars = 128; //character size
char receivedChars[numChars]; // Store data read from SMS
boolean newData = false; //flag to check if new data has arrived

void setup() {
 Serial.begin(9600);
 mySerial.begin(9600);
 Serial.println("<Arduino is ready>");
 mySerial.println("AT");
 mySerial.println("AT+CMGF=1"); //text mode
 mySerial.println("AT+CNMI=1,2,0,0,0");
 mySerial.println("AT+CSQ"); //Check signal strength
   while (Serial.available())
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available())
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

void loop() {
  //code for checking sms
  scanSMS();
  //Print if a new data arrived
  showNewData();
  delay(25000);
}

void scanSMS() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '#'; //Start and end markers. Eg. SMS body will be sent as #status#
    char endMarker = '#';
    char rc;
    while (Serial.available())
    {
      mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
    }

    while (mySerial.available() > 0 && newData == false) {
      Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port

      rc = mySerial.read();

      if (recvInProgress == true) {
        if (rc != endMarker) {
          receivedChars[ndx] = rc;
          ndx++;
          if (ndx >= numChars) {
            ndx = numChars - 1;
          }
        }
        else {
          receivedChars[ndx] = '\0'; // terminate the string
          recvInProgress = false;
          ndx = 0;
          newData = true;
          }
        }
      else if (rc == startMarker) {
        recvInProgress = true;
      }
    }
}

/*PRINT IF THERE IS A NEW DATA*/
void showNewData() {
 if (newData == true) {
   SendMessage(receivedChars);
 newData = false;
 }
}

/*SEND BACK WHATEVER SMS IS RECEIVED*/
void SendMessage(String receivedChars)
{
  Serial.print("here");
  mySerial.println("AT+CMGS=\"+xxxxxxxxxx\"\r"); // Replace x with mobile number
  mySerial.println("Humidity Alert!");// The SMS text you want to send
  mySerial.print(receivedChars);
   mySerial.println((char)26);// ASCII code of CTRL+Z
}

The issue is that the module seems to receive only alternate characters instead of the whole message. For example, if I send the text #program#, the Arduino will only print porm or rga. Am I missing something here? Any help is highly appreciated.

You wrote:

Serial.write(mySerial.read());
rc = mySerial.read();

Here you are calling mySerial.read() twice, and thus reading two
characters from the port's input buffer. You then forward the first
character through Serial, and process the second one. Note that you
should normally not read two characters unless you have tested that
mySerial.available() >= 2.

You probably want to forward and process one character at a time, thus
only call mySerial.read() once within this loop:

rc = mySerial.read();  // read from mySerial
Serial.write(rc);      // forward through Serial
// now process rc


How to ensure electronic components make good connection with breadboard I just began following the projects in the Arduino Projects Book included in the Arduino Starter Kit.

While using LEDs, as in the first few examples of the book, I am having a difficult time keeping them in contact with the breadboard. I can usually move the LED around until it turns on, but even a push of a button can make it lose contact with the board. I haven't used much more than switches, jumpers, LEDs and resistors, so I don't know if any of the other components behave the same. For the more complex projects, it seems like it would be hard to tell if you have it setup properly if you can't be sure the components are making a connection with the breadboard.

Is there a particular way to get all the components to sit nicely in the breadboard, or to modify them to do so?

Sounds like you may not be pushing the leads into the board,I find long nose pliers handy for components with thicker leads.


Can I reuse crystal frequency of Arduino? If I use some IC which requires clock frequency like 16MHz, can I take one from Arduino?

Or this it too high frequency to travel to neighboring board?

Yes but you need to know what you are doing.  You will need a clock driver and possibly a clock receiver depending on the devices you select.  Then you need to modify both boards voiding any possible warranty.

The best answer is NO!


Bluetooth Communication Not Working with DC Power But Works With USB Power? I am running a HM-10 Bluetooth Low Energy (BLE) module to transmit serial data (using SoftwareSerial) from an analog sensor onboard my Arduino Uno to a serial terminal app on my Android phone. When I power the Arduino with a USB power bank, the data transmits flawlessly.

When I tried to power the Arduino with a 9V battery through the DC power jack instead of USB power, the BLE module connects to my phone, but no data is transmitted when a serial connection is established.

Any ideas why this would be?

Take two 9 volt batteries with same specifications and connect it into the parallel by using this efficiency of current increases and it full fill the current requirement at the time of data transmission and for others modules u r using with the arduino.


HID multiCLASS RFID reader all Mifare to Wiegand 32bit I'm using an Arduino Uno to read from a "HID multiCLASS (RP40CKPNN) reader", which is a stand-alone reader that reads cards and returns a number of bits via Weigand Data0/Data1 protocol.  The "multiCLASS" readers can read both 125HZ PROX tags, and 13.57MHz mifare tags.

I have it reading and decoding 125HZ (multiple-PROX format) tags of various bit-lengths just fine, but when the reader is presented with a 13MHz card (specifically Mifare cards) the reader decodes the CSR/UID of ALL Mifare cards to 32bits.  The Mifare cards come in two types, Classic (that use a 4byte UID), and Ultra (that use a 7byte UID), so I would expect 32bits for the Classic cards, and 56bits for the Ultra, but I only ever get back 32bits.

The reader's data-sheets specifically calls out that for mifare tags it should return a 32bit or 56bit CSR value based on the serial number of the card, but I've looked through lots of HID literature on this reader, and I can't find any specifics on how to change/modify its configuration.

Does anyone have any experience with these readers, and is there some trick to changing the configuration so that it returns more bits for Mifare cards?

For this specific reader, communication is only one way, from the reader to the Arduino via Weigand protocol.  Because of this, changes to the configuration for these readers is handled by proprietary RFID cards obtained from HID Global. The reader reads the card, and changes its configuration accordingly.  I was able to reach out to HID Global technical support and they are sending me a card that will change the configuration to output 56bit CSN/CSR/UID for mifare cards (which will cover the 7byte UID of mifare ultra).

Thanks for the comments that helped me work this through.


cannot upload my program to arduino uno I bought new Uno yesterday, i made my programme, and i compile it. it was good compiled. however, when i upload the programme to my Uno, it cannot be uploaded and there was a message like this

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x1b
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Help me please

Make sure u have selected the right COM port
Make sure nothing is connected to the pin 0 and 1 in arduino

This happens because the Arduino IDE could not find Arduino Board Connected to the system.


Arduino Yun - Sensor Data logging to MYSQL on External Server I want to log data from Sensors (Say Temperature, moisture or humidity) to a MYSQL database (provided by a online hosting company). Is it possible to establish communication between Arduino Yun and that database and log the data to it

Yes, you can do that using python as well as other languages, or you can use Temboo: there's an example bundled with the Arduino IDE, it's called "SendDataToMySQL"


Yun as a Conventional Wireless Access Point I want my YUN to act as a server in a client/server architecture so students can control their wifi robots via their desktops. I can plug the YUN directly into an ethernet port on our network and want to have robots communicate with it through a client/server architecture. Can somebody steer me in the right direction?

Check out this project, made by @Vadorequest the early days of the Yun: he hacked a car to control it via his smartphone. There's a nice video on youtube.


Programming a USB mouse connected to the Intel Edison Arduino expansion board How can I programme a USB mouse connected to the standard USB port of the Intel Edison's Arduino expansion board?  I would like to measure the displacement of the mouse and also specify the frequency of image capture using the mouse's optical sensor.  I do not know much about programming so tutorials relating to my project would be very helpful.

Thanks

Here's a simple introduction to using the USB mouse as an input device. That might be a good starting point.

http://tahmidmc.blogspot.com/2015/12/using-input-device-on-embedded-linux.html


Is it possible to press a button from Arduino and my computer will get a key event? My idea seems easy:

I connect a button with arduino, then write some code and upload it to arduino. Then I open the notepad(or any other editor) on my computer. When I press the button, there will be a character "A" displayed in the notepad.

I have tried with my Arduino uno, and use Serial.write/print function to send an A to serial port 9600, but it seems the character A only shows in the serial monitor GUI.

My question is:

Is "Arduino uno" is OK to implement this?
If not, what other board should I use?
Is Serial.write/print the correct function?
Or shall I use the Keyboard.??? function?
Do I have to write an application which runs on the computer and listens the serial port, and emit a real key event? (that's sad)

The Uno is not the best board for this. You may be able to get somewhere with the Virtual USB project but there are a couple of boards that are better suited for this.

Those are the Arduino Leonardo, Micro, and Due. In those, you can use the Keyboard Library just like you are using the Serial library now. This page has an example very similar to your project:

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send the message
    Keyboard.print("Hello!");
  }
}


Digital map in A* search algorithm in Arduino I am building an Automated Guided Vehicle as my graduation project. I'm new to path-finding algorithms and I've only worked with small projects based on Arduino as of now.
I've chosen A* search after careful understanding of many other algorithms (Dijkstra's/D*, etc.) and using Arduino Uno (will switch to Due later) for the robot.

I've implemented the code for A* in C++ as well.

But I've got stuck in its implementation in Arduino. I don't know how to create a digital map of the arena (I'm using a 4 sq.m area and using a 10X10 grid for it). I don't have any idea how to move the robot in that arena with the digital map (I reckon I'll need wheel encoders and an ultrasonic sensor mounted on a servo for orientation).

My main problem is creating a digital map of the arena and how to go about it.

I'm attaching a code for A* for reference and the grid used in it.

// Driver program to test above function
int main()
{
  //* Description of the Grid-
   1--> The cell is not blocked
   0--> The cell is blocked    *//
  int grid[ROW][COL] =
  {
    { 1, 0, 1, 1, 1, 1, 0, 1, 1, 1 },
    { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 },
    { 1, 1, 1, 0, 1, 1, 0, 1, 0, 1 },
    { 0, 0, 1, 0, 1, 0, 0, 0, 0, 1 },
    { 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 },
    { 1, 0, 1, 1, 1, 1, 0, 1, 0, 0 },
    { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
    { 1, 0, 1, 1, 1, 1, 0, 1, 1, 1 },
    { 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 }
  };

  // Source is the left-most bottom-most corner
  Pair src = make_pair(8, 0);

  // Destination is the left-most top-most corner
  Pair dest = make_pair(0, 0);

  aStarSearch(grid, src, dest);

  return(0);
}

first off, you need 2D array to store map segments.
then you have to update them according to the real map.
you have to implement a few measures:

a series of sensors to qualify adjacent segments. e.g. walls/road. map edges are considered walls.
an array (list) of current adjacent segments. (just a 4 member array, containing the up/down/left/right location. this array stores the index of the mentioned segments in the main 2D array.)
a beacon or something like that at the goal position. you can evaluate the segments based on the distance from beacon. (the simplest method, cartesian distance).
run a iteration of A* alg to find out which adjacent segment is suitable for next move.


5V on HIGH Digital Pins, Only While Using USB Power So I have a small problem with my Arduino Pro Mini here. May be worth noting that it is a clone, but otherwise this is still some weird functionality. I have done some experimenting so I'll just set the scene for you. I have everything that requires power connected to the + and - lines on my breadboard, that way I can avoid drawing more than about 20mA across any individual pins. I currently have my Arduino Pro Mini hooked up to the 5V power supply via the RAW and GND pins, but the supply is a regulated 5v wall supply. It actually is currently outputting 5.36V.

I have made sure all my pins I'm using for output are indeed set as output, the problem only arises when I attempt to power the device from something OTHER than USB power. I tested the output from my wall adapter connected to RAW and to a random VCC pin, both have the same effect.

When powering the device via USB (USB to Deek-Robot ASP, then to Pro Mini), if I set my digital output pin to HIGH, I get 5v. This is enough to turn on a 5v relay that then supplies power from the supply to a small water pump. However, if I use the regulated wall-power, I get about 3.7 to MAYBE 4.15v, which sadly is not enough to switch the relay to the NO position.

I have tested the voltage coming from the USB ASP as well, it is 4.95v.

EDIT: The wall-plug voltage drops from 5.36 with no load except the meter to 4.7v with the Arduino and a couple LEDs attached, if that means anything.

"Arduino Pro Mini hooked up to the 5V power supply via the RAW and GND pins, but the supply is a regulated 5v wall supply. "

That is the problem. RAW pin expects more like 6V to 6.5V for the regulator to output 5V.

If you are supplying 5V, connect to the 5V, or VCC and GND pins.

If you are connecting to USB via an  FTDI Basic or equivalent, and the 5V supply at the same time, then the computer may not like having the USB 5V line back driven from an external source (mine complains about a "power surge" and shuts down the USB port). Make up a breakout cable between the FTDI and the Promini and either disconnect the 5V line, or put a diode in series so the Promini can't supply 5V back thru the FTDI and into the USB port.  That way the FTDI chip is powered from USB, but the Promini is not, and all the hardware is happy.

Make sure to use series resistors with LEDs to avoid overcurrent from the Promini output pin, which will either damage the IO pin, possibly damaging the 328P, or damaging the LED from overheating from excess current.  (5.36V - 2.2V)/.02A = 156 ohm. A 180 ohm, 220, 270, 330, some value in that range will do. 1K will probably be fine, LEDs these days can be quite bright even at lower current; 20mA can be blindingly/annoyingly bright.


Switching lights by Harry Potter themed voice commands I'd like to know whether I can make the light in a room light up just by saying two voice commands. Specifically lumos and nox spells, like in Harry Potter. I have never worked with Arduino or with any programs it uses, but I have an idea how it should work. I watched some tutorials and read a bit about it, but I'm not entirely sure, if it will work and what exact types of Arduino components would be most suitable for it.

I'm thinking about connecting the voice command module's output directly to the light switch. But I don't know if it would be better if the Arduino would just somehow switch the light by enabling the current to flow or flipping the switch with a servomotor directly.

I also don't know if the module can work by itself when just plugged into the wall. If it has to be still plugged into a PC, that would be useless.

I'd also like to know which Arduino (or components in general) I should use and if the microphone could sense the commands from like 2-3 meters.

I really am thankful to anyone, who would be so kind and help me with this idea, because it should be a gift for my younger sister, probably the biggest Harry Potter fan in the world.

This might be a hard project to start with.

First, you need to process the 'voice' from the microphone. This will be probably impossible on an Arduino.

Than you need to program everything, can be quite complicated (for a beginner).

Making something respond to 'any' sound is easier and can be done by Arduino and limited programming. Voice recognition is completely different.


Can I use GSM and GPS modules at the same time? In my project I want to retrieve the Latitude and longitude and then transmit to a cell phone through GSM module. But the GSM as well as GPS modules uses the same pins i.e. Tx and Rx, so is it possible to use both modules at the same time?

Link to products

GSM - http://www.ebay.co.uk/itm/SIM800L-GPRS-GSM-Module-SIM-Board-Quadband-PCB-Antenna-for-MCU-Arduino-/191611848583?hash=item2c9cf4c787

GPS-- http://www.ebay.co.uk/itm/New-1PC-Ublox-NEO6MV2-GPS-Module-Aircraft-Flight-Controller-For-Arduino-/400830328802?hash=item5d53596fe2

Thank you.

Yes.  Use SoftwareSerial for one of them.  That way you can use any pins you like for that module.

I'd recommend using the GPS module on the SoftwareSerial since it's (mainly) half duplex, and SoftwareSerial can't both transmit and receive at the same time like the hardware UART can.

Either that or switch to a different Arduino board that has more than one hardware UART.


someVariable = { somethingThatLooksLikeAFunction }; possible? Wasn't sure how to title this question...

I was curious whether the title example is possible somehow, and are there any good tricks to using it?

I have been using something similar quite a lot:

newBool = (someTest) ? true:false;
newInt  = (x + (y / z));
[...]

However, I was curious if it was possible to add far more conditions, almost like a function?

For some simple(*) examples:

someThing = {
    int _x = aFunction(_x);
    if(_x) {
        something = somethingElse;
        for(...){ ... }; // etc
    } else {
        /* otherStuff */
    }
};

Or

someThing = {
    for(_x=0;_x<y;_x++){
        z++;
    }
    someThing = (z>y) ? a:b;
};

I understand it's worth just separating it off into functions most of the time, although I'm trying to get away from a function/library-fest as much as possible...  It's getting annoying crawling through everything when I could just have the useful stuff right there, where I need it, instead of 1000 lines away, or in another library.  It also allows the text editor to fold the code out of sight, starting from one variable, instead of on each clause.

With the few tests I have tried, I've not been successful in achieving what I'm experimenting with, so, is this kind of thing possible in any way? and if so, what are the rules/possibilities/different ways you could implement this?

* Emphasis on simple! And a semi-pointless/completely useless "function" alert too!  I'm just curious about the "proof of concept" in the examples...

You can do it with a lambda function, though the syntax is somewhat cryptic:

int someThing = [](int y, int z, int a, int b){
    for (int _x = 0; _x < y; _x++) {
        z++;
    }
    return (z > y) ? a : b;
}(100, 0, 10, 20);

In that you are defining a lamda function [] with four parameters, y, z, a and b. Then calling that function with four numbers (100, 0, 10, 20) and assigning the return value to someThing.

It's the same as writing a normal function but there's a lot more brackets around.


PWM help (input changing duty cycle) Is there a way to adjust the duty cycle (PWM) based upon input gained by a sensor. For example, if the sensor picks up a really high value, it would increase the duty cycle for an LED making it brighter. Can we also do this task without a potentiometer? Can all of this be done "hands-free" by the Arduino?

The example at the bottom of this Arduino reference page does exactly that. If you want to change the way the value varies, you can just modify the variables in a loop or in whatever approach you prefer instead of analogread'ing it.

https://www.arduino.cc/en/Reference/AnalogWrite


Too little current to trigger a relay? I try to use this relay with a Arduino Mega. I connected with jumper cables

5V pin to DC+,
GND to DC- and
Digital Pin 13 (because its a lucky number) to IN.

The power LED from the relay is lighting green.

I run this code, which should trigger the relay every 3s for 3s:

int pinOut = 13;

void setup() {
  pinMode(10, OUTPUT);
}

void loop() {
  digitalWrite(pinOut, LOW);
  delay(3000);

  digitalWrite(pinOut, HIGH);
  delay(3000);
}

When initializing the sketch, the red light (from the relay) is flashing and the relay is clicking. But afterwards nothing happens.

With my multimeter I check the currents:

5V to GND = ~5V
Pin13 to GND, when not connected to relay = ~4.7V
Pin13 to GND, when connected to relay = ~1.2V

The relay needs 5V and 5mA triggering current. I don't think the Arduino is not suited, since they promote the relay Arduino.

Any ideas? Do I need some kind of resistor? Or is the USB port from the laptop not sufficient? I used two different Arduino Mega's with two different relays. By the way i don't have a big background in electric.

You are using pin 13, but you set pin 10 as an OUTPUT.

pinMode(10, OUTPUT);

Try changing that to

pinMode(pinOut, OUTPUT);

PS by not setting pin 13 to OUTPUT, digitalWrite(pinOut, HIGH); enables the internal pull-up, instead of "connecting" it to 5V. The internal resistors are around 35kOhm. So pulling a bit of current through them will result in a lower voltage at the pin.


Powering Arduino Pro Mini + Driving LED Strip Just looking for a second opinion on my circuit below. Wired up everything works great, but last night as i was unplugging the FTDI programmer something seemed to have happend, and the mini was bricked.

I'm not sure if it has to do with my wiring below, or if it was me unplugging the cable in a haphazard manner.

What I'm attempting to do is run my arduino from 12v wall supply, but also drive an LED strip with it. I'm just unsure if this is the best way to go about it, any advice is welcome.

Thanks
Justin

According to the schematics, the Pro Mini uses the MIC5205, which is a linear regulator.
Using it directly with 12V is not a very good idea, in terms of power efficiency, as it will dissipate 35mW vs 25mW provided to the ATMega board.

From this perspective, I'd recommend a step-down converter for powering the Arduino.

However it will not cause any damage, at least at room temperature, as the power dissipation is well within operating margins, see calculation at page 8 of the MIC datasheet.

Edit: detailed pros and cons, power wise.


How will Arduino sketch and Android app communicate over GPS? How will I make Arduino with GPS communicate with an Android app? I just need this for my school project.

How will i make arduino with gps to communicate with android app? i just need this for my school project.

as gps is one-way communication, you will have to either launch your own birds capable of two way communications, or pick a different school.


Simple Text input using 5 buttons So I have to get this function done but I'm not so bright and got confused.
(excuse me! I'm total noob)

The function is basically inputing text using five buttons, directional buttons and an ok button. The up and down buttons will be used to cycle through letters (a-z), and the left and right buttons will be used to control which array to cycle letters.

The control will be:

up button (up): ASCII-1 (z, y, x...)
down button (dw): ASCII+1 (a, b, c...)
right button (ri): array[i] ~> i+1 (go to next character/array)
left button (le): array[i] ~> i-1 (go to previous character/array)
ok button (ok): confirm text and changes the limit to stop function looping

I can't get it work with this code I write.

void intext()
{
  int lim=16;
  lcd.setCursor(0,1);
  lcd.print(input);
  for(i=0; i<lim ; )
  {
    if(digitalRead(dw)==HIGH)
    {
      if(input[i]<'a')
        input[i]='z';
      if(input[i]>'z')
        input[i]='a';
      input[i]=input[i]+1;
      delay(1000);
    }
    if(digitalRead(up)==HIGH)
    {
      if(input[i]<'a')
        input[i]='z';
      if(input[i]>'z')
        input[i]='a';
      input[i]=input[i]-1;
      delay(1000);
    }
    if(digitalRead(ri)==HIGH)
    {
      delay(1000);
      i=i+1;
    }
    if(digitalRead(le)==HIGH)
    {
      delay(1000);
      i=i+1;
    }
    if(digitalRead(ok)==HIGH)
    {
      lim=i+1;
      delay(1000);
    }
  }
}

void loop()
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Type your text:");
  intext();
  lcd.setCursor(0,0);
  lcd.print("Success!!");
  lcd.setCursor(0,1);
  lcd.print(input);
}

The result I wanted it to be is like this:
first you got the "type your text:" on the first row and blank in the second row.
our cursor is in the first column of the second row, so we can cycle through the alphabet letters. if you press right you can edit the next column of second row. you can get to the previous column in second row by pressing left. you can input up to 15 characters.
after done typing pressing ok will stop the typing and you will see "Success!!" in the first row and typed text in the second row.

Please help. I'm stumped.
Thank you.

Several issues in the code you posted:

Every change to the text you do inside the for loop, will not be reflected to the LCD until the for loop will end (when i<limit will no longer be a true statement). You might want to add an additional code, inside the for loop and outside any of its conditional statements, that will repeatedly set the cursor and print input to the LCD. Something similar to the code you have prior to the for loop:

void intext()
{
  ... // rest of the code until the for loop

  for (int i; i<limit; )
  {
    ... // all the conditions for up/down/left/right/ok

    lcd.setCursor(0,1);
    lcd.print(input);
  }
}

Another problem is that when the user clicks left, the counter should be decremented, not incremented, and you should check for left boundary:

if(digitalRead(le)==HIGH && i>0) // left boundary check added
{
   delay(1000);
   i=i-1; // and not i=i+1;

}

After clicking Ok, and since the for loop does not increment i, the condition in the for loop (i<limit) will stay true, and the loop will not end until the user will click Right once more. To mitigate this, change the following

if(digitalRead(ok)==HIGH)
{
  lim=i; // and not: lim=i+1;
  delay(1000);
}

Otherwise, the user will have to click Right for completion, to increment i once more.

jfpoilpret comment about pull up/down is very important. Make sure you use pull up/pull down resistors in order to prevent input debounce (more details inside this link).


NodeMCU serial port - use with computer and device at the same time I'm trying to understand how serial communication for ESP8266 in NodeMCU actually works. I found a quote saying that normal Serial is mapped to ports GPIO 1 (TX) and GPIO 3 (RX). They are even labeled on the board like this, so I believe this is true.

However I'd like to understand the relationship between those pins and serial communication over USB. Does this work the same way as in normal Arduino where you can use either communication over USB or hardware serial on pins 0 & 1?

I did some tests and if I run simple program like:

Serial.begin();
//.......
Serial.println("Hello world");

I can see that in serial monitor on my PC. How does that impact serial communication on GPIO 1 & 3 ?

Yes, it is the same as Arduino. The TX and RX pins connect to a CH340G chip to convert the serial into USB. If you use USB serial you can't use the pins for anything else.


Noise when running Arduino close to analogue audio circuit TL;DR: My Arduino is injecting a lot of noise into an analogue audio circuit, even when not physically connected.

I'm experimenting with using an Arduino as a low-frequency oscillator in audio circuits (modular synths, guitar effects etc).  I'm using an Arduino Uno powered with a USB + mains plug.

As a test I set up a simple circuit -- I don't believe the circuit matters much in this case but I'm including it here anyway:

simulate this circuit – Schematic created using CircuitLab

The Arduino is set up with one PWM pin supplying 0-5v, varying in a triangle wave (i.e. ramping slowly up, then slowly down again). This is connected to the JFET, which acts as a variable resistor. I have tested the analogue part of the circuit manually and it works as expected.

With the Arduino connected, however, the circuit produces a very loud "squishing" noise that swamps the audio signal passing through it, not unlike someone tuning an old short-wave radio. The noise "squishes" in time to the oscillation of the voltage.  It's not unlike the sound in this video associated with the PC power supply: https://youtu.be/lXPJvSU8MwI?t=10m52s.

This happens even if I physically disconnect the PWM pin from the circuit -- the closer its wire is to the circuit, the louder the noise, but it's clearly audible even when they're separated by are a foot or more of air.

Things I've tried:

Tying the Arduino ground to the analogue circuit ground, and also keeping them separate.
Adding power filtering caps to both circuits.
Putting the Arduino in an aluminium box, grounded to either its own ground or the analogue circuit's, or both.
Powering the Arduino from my laptop instead of plugged directly into the mains.

The analogue circuit is on breadboard right now so some noise is expected, but this is far outside anything I've experienced before even with very badly-behaved circuits.

I'm FAR from knowledgeable about Arduino so my hope is that I'm doing something stupid and easily fixed. I would happily accept an answer that proposes an entirely different way to achieve the desired result.

Arduino PWM signal is about 500Hz, so it will be audible (read: noise) by itself. You could implement a low-pass filter between the PWM pin and your J-FET. A simple RC filter tuned to 5Hz would attenuate a 500Hz signal to -40dB, which probably won't be enough for high quality audio. There are filters with better rejection properties which usually require active components to build. One of the simplest of such filters is the Sallen-Key topology, which can practically double the rejection ratio using a signle active component (opamp).

Another option is to use a simple RC filter, but increase the the PWM frequency (as described here) to achieve high rejection ratio. Eventually, increasing the frequency past the audible range (about 16kHz) will ultimately resolve the noise problem, though I would still use an RC filter to keep the J-FET in linear mode. Apparently, the highest frequency you can achieve at full resolution is 62.5KHz, which is more than enough.


Arduino Google speech api I'm currently experimenting with my arduino Uno. I control it via an mobile (android) but wanted to just use a microphone on the board so I don't need to carry my mobile around. It is possible to record flac files from a mic and send it to Google speech api and get a return? And then maybe output it via the synthesis.

So it is possible to do this on an arduino uno and with C. If doesnt is there any other way I can go? I could buy a raspberry pi but I don't an whole operating system like linux installed. So any thoughts?

You can use a special voice recognition shield (for example: EasyVR Shield 3.0 - Voice Recognition Shield) to integrate a simple and basic voice recognition. I think it's a very fast and easy prototyping way...

For the use of the more complex Google Speech Recognition I would use a more powerful microcontroller (such as Raspberry PI or something like that)...


i am having Strange issues when trying to read form gps serial connection I have an Adafruit Ultimate GPS connected to a MEGA2560. I am trying to get the data from the buffer and do other data processing at the same time, however. when i allow other processing to be done the output becomes garbled such as below. the first out is correct and then becomes garbled and outputs now useful data.

16:34:54.466 -> $GPGGA,163453.155,,,,,0,00,,,M,,M,,*7F

16:34:57.111 -> $GPRMC,163453.155,V,,,,$GP$GPGGA,1$GPGGA,$GPGGA

    void loop()
    {

    GetTotalPressure();
      char c = GPS.read();
      Serial.print(c);
       if (GPS.newNMEAreceived()) {

        if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
          return;  // we can fail to parse a sentence in which case we should just wait for another
      }
      if (timer2 > millis())  timer2 = millis();

      if (millis() - timer2 > 1000) {
        timer2 = millis(); // reset the timer
    GPSScreenUpdate();
      SDcardSave();

      }

When GetTotalPressue is commented out The GPS serial output is correct when it is no the error above happens.

GetTotalPressure is below the sensor is connected to a I2C bus

void GetTotalPressure() {
  Totalpressure = ms5611.readPressure();

Many Thanks

You are not reading the GPS often enough. The method
Adafruit_GPS::read() is documented in the comments embedded in the
source code:

  Read one character from the GPS device.

  Call very frequently and multiple times per opportunity or the buffer
  may overflow if there are frequent NMEA sentences. An 82 character
  NMEA sentence 10 times per second will require 820 calls per second,
  and once a loop() may not be enough. Check for newNMEAreceived() after
  at least every 10 calls, or you may miss some short sentences.

  returns: The character that we received, or 0 if nothing was available

Accessing the I2C bus makes loop() slower, slow enough that you get a
buffer overflow, as explained above. I suggest that, instead of reading
a single character per loop iteration, you read as many as are present
in the buffer:

void loop()
{
    GetTotalPressure();

    // Empty the GPS port receive buffer.
    while (GPS.available()) {
        char c = GPS.read();
        Serial.print(c);
    }

    // Parse any newly received NMEA sentence.
    if (GPS.newNMEAreceived()) {  // clears the newNMEAreceived flag
        if (!GPS.parse(GPS.lastNMEA()))
            return;
    }

    // Display and log location every second.
    if (millis() - timer2 > 1000) {
        timer2 = millis(); // reset the timer
        GPSScreenUpdate();
        SDcardSave();
    }
}

As an aside, I removed the line

if (timer2 > millis()) timer2 = millis();

which serves no useful purpose. If you are trying to detect millis()
overflows, you are almost certainly doing something wrong.


Is an Ultrasonic Sensor or Infrared Sensor better for measuring distance (to/from a human body)? I'm trying to make a sensor to detect that a person is within 50cm to trigger a function. But when I use the HR-SR04 sensor, it works accurately on flat surfaces (e.g. walls, books) with a margin of error around 5cm, but not on uneven surfaces (e.g. humans) where the value randomly jumps between 0cm to 1000cm.
I was thinking whether using an IR distance sensor would be better.

That depends on your requirements. An IR distance sensor will work better with different materials, since IR light is mostly reflected in very broad angles (expect for very reflective materials, like mirrors), so that uneven surfaces are also detected. But you will get a significantly worse error margin in your 50cm range. Normal IR distance sensors are just an LED and an IR photo transistor, sometime with some extra components. So the LED is lighting up and the photo transistor is measuring, how much of the IR light is coming back. The IR sensor depends also on the reflectiveness of the materials and the level of surounding IR light.
But as you don't really need to measure the distance, but just want to know, if there is an object in the range, an IR sensor might be enough. You would need to change the threshold of your IR sensor according to your needs (by experimenting with it).
All in all I think, yes, an IR sensor can give you better results for your application, though not for really measuring the distance, but only for the presence in a range with rather big error margin.


Can the 2nd MCU on the UNO R3 be used for keyboard emulation? Following on from What's the 2nd ICSP header for in Arduino Uno R3? I was wondering how this could be hacked to our advantage.

For example, could that firmware be rewritten to have the UNO recognised as a mouse/keyboard input? Could this be done after the boot loader process and leave the uploading process in tact?

Given the limited IO, it seems it's functions might be limited. Plus I have no idea how much code is space is available.

Yes, it is possible. using LUFA, you can burn new firmware to the Serial converter. The only problem is that you need to re-burn the USB-Serial converter to upload another program.

Info: http://www.fourwalledcubicle.com/LUFA.php

Specific page: http://mitchtech.net/arduino-usb-hid-keyboard/


Proteus - How to Debug Invalid Opcode? While running a program compiled in the Arduino IDE 1.8.5 and then using the .ELF file inside LabCenter Proteus 8.0, for an Arduino Nano ATMEL Mega 328P, for a code involving the use of the SoftwareSerial.h Library, hence involving several loops, without user interaction, I am getting the following error:

Invalid opcode 0x0024 at PC=0x0096

Now I am completely lost. According the AVR Instruction Set Manual such opcode should (not sure about this?) be RETI - Return From Interrupt at the Program Line (?) no.150 = 0x096. The full code has 779 lines plus several library calls, and the line 150 happens to fall just before the loop() function (?), which should never repeat, being just a declaration.

So, how should I debug this error? Evidently I am not asking to solve the problem for me but, how should I proceed for debugging it and find the real error?

I have been unable to find in Proteus a tool for "Debug Stop if Error"

I have been unable to isolate the error in a simple way to share. It should be related someway with interruptions used by the library SoftwareSerial.h, because at some modifications of the program, the code freezes at an interruption return. I am working on that, but advancing really slowly actually.

Related question No.1.

First: Use the ino.hex file instead of the  .ELF file
Second: this error is showing because you are compiling your code with a different board. Make sure you are using the correct board over at the Arduino IDE. My advice is: switch your board to Arduino Uno both in proteus and over at the Arduino IDE and see if it works. Later on, you can try different boards.


How does the speed work in VirtualWire Library I'm analyzing the VirtualWire library and in it, the send messages are being sent with digitalWrite in the "send" method. However, there is a setup speed function. I'm reading that function and I see a lot of prescalers and TCCR variables. However, I'm not quite sure what these things do. Because, if it uses digitalWrite anyway to send the bits, then really is no intrabit delay, etc. Can someone please clarify this?

Sorry if question is convoluted. Happy to do any clarification. Thank you for all guidance!

EDIT: Also, how do I transmit a block of message. Something greater than a byte? I'm trying to calculate BLER of messages and software serial only transmits 1 byte at a time. While virtualWire uses low-level error detection (and i want to avoid the use of any error detection/correction).

I think that is used for receiving. By setting the speed, it knows how often it needs to read the input pin. It does this using timer interrupts, so it will run "in the background" without interfering with the main (loop) code.

The TCCR stuff is the set the interval for the timer interrupt.


Problems in calculating and printing long unsigned integers I have this code which provides an erroneous unsigned long number.
CODE:
char buff[100];

int unsigned long bytes;

bytes = 48 * 70 * 144;

sprintf(buff,"%lu bytes\n", bytes);

BTPort.print(buff);

OUTPUT:
20088 bytes
BUT: The correct value is 483840

This is because the default numeric type is int, which on Arduino is just 16 bits (and signed).
So 48 * 70 * 144 is 0x76200 in hex, which truncated to 16 bits is 0x6200, or 25088. This calculation is done by the preprocessor, not the compiler, so doesn't know (or care) about the destination variable type.
You need to force the values to be calculated as unsigned long by appending UL to them:
bytes = 48UL * 70UL * 144UL;


How to connect L298N motor driver to 5v input supply? I'm trying to connect 5v supply to a L298N motor driver at it's 12V-35V input pin but it's not working. If I'm connecting to 7.2V supply it's working. Is there any way to connect 5v supply? I want a constant 5v at output pins for motors.

Note: Since all vendors (checked Mouser, Octopart, and Sparkfun) link to the L298 datasheet when listing the L298N I will assume they are reasonably equivalent.

I will assume that the "12V-35V input pin" is the V_S pin, despite that label. There are only two supply pins on the L298 with the following electrical characteristics:

V_S, Supply Voltage, pin 4, Operative Condition V_IH + 2.546V (max.: 46V)
V_SS, Logic Supply Voltage, pin 9, typical 5V (min.: 4.5V, max.: 7V)

with

V_IH, Input High Voltage, ranging from 2.3V to V_SS

Which would explain that the circuit works at 7.2V under the assumption that the logic inputs (enable A and B as well as inputs 1 through 4) are at close to 5V high levels. And here's the trick that might make it work: as noted V_S (the supply voltage) needs to be at a level of V_IH + 2.546V while V_IH could be as low as 2.3V and 2.3V + 2.546V < 5V. So driving the L298's logic inputs with a lower voltage for logic 1, i.e. closer to 2.3V high levels, could help.

Why is this? (source):

  [..] The actual restriction is that the motor supply be somewhat greater than the logic "1" input, but that need not match the logic supply. [..]

A warning though:

this circuit is now operating at the fringes, one might call it shady at best, intolerable at worst
saturation voltage is related to output current and other parameters, e.g. temperature, so this might work now under certain conditions and fails horribly another day

Therefore better bets are:

use a higher supply voltage
ditch the L298 and its high voltage drop Darlingtons and use a MOSFET H-bridge motor driver, such as the TB6612FNG, see also
ditch the L298 and use single bipolar transistors, depending on the output current

Other things to check:

Make sure V_SS is connected to the logic supply voltage (see AnT's comment). Make sure GND of the Arduino's power supply is connected to the L298's GND.


How to programmatically choose "board model" and "port number" in Arduino IDE? I'm testing three different Arduino (nano, Uno and Mega) each of them having a nRF module. The codes (sketches) are different for each module.
I've connected the arduinos to my single laptop via 3 USB ports.

Problem is, whenever I want to re-upload a sketch and fix a bug, I have to choose board model and port number of that sketch by using the menus. It has become frustrating using mouse each time I need to change something.
How can I set these parameters in code so each sketch knows which port and model it is related to?

You can't in the Arduino IDE, it's not designed that way (you can't even have different board/port settings in different windows - it's stored in the Java equivalent of a single global).

Instead you will have to switch to a different programming environment.

Personally (since I am the author) I would suggest switching to UECIDE. That has far more advanced facilities than the Arduino IDE, yet still retains most of the simplicity of use.

In UECIDE you can not only have different ports and boards selected in different windows, you can also configure individual sketches to automatically select their board and port.

Sketch -> Sketch Properties... -> Objects tab