texts: Do I need a pull-up/down resistor for button LED circuit?

texts:
When reading up on how to make a circuit that turns an LED on when a button is held down, I keep finding people saying a pull up or down resistor must be involved, to avoid the flickering state of the LED seen with a floating pin. There's also code being implemented, where the state of a pin is read and monitored as the button is pressed down or left raised. What I don't understand, is why this is all necessary. Surely it isn't, considering the circuit below allows the button to be pressed with the LED turning on/off depending on the state of the button.

I made this circuit before drawing it online, and it works exactly as intended. No need for a pull up/down resistor or any code. I must be missing something here, can anyone please explain? It works perfectly with a buzzer as well.

Many thanks.


texts: Changing type of one variable dramatically changes compile size

texts:
I have a sketch containing the following method:

// Writes zeros to the complete screen clearing it:
void clearScreen(uint8_t val) {
  setDrawArea(0x00, 0x7f, 0x00, 0x07); // complete screen
  SSD1306.ssd1306_send_data_start();
  for (int c = 0; c < 128 * 8; c++) {
    SSD1306.ssd1306_send_byte(val);
  }
  SSD1306.ssd1306_send_data_stop();
}

The whole sketch compiles with a size of 6730 Bytes. While refactoring the code I mistakenly changed "c" to uint8_t. After this I compiled to 4124 Bytes. Does this come from the compiler recognizing that the loop condition will never be reached and cut off all code behind or is this some kind of strange optimization event? I'm asking because I can't test the sketch in the moment.


texts:
In a previous question (Append Text to Variable Names: Please Help Me Shorten This Code) I learned that in order to shorten this code:

fanSpeed = readEEPROM(AT24C32_ADDRESS, 1, fanSpeedPos);

I could define a macro at the top of the script like this:

#define readEE(VAR) VAR = readEEPROM(AT24C32_ADDRESS, 1, VAR ## Pos)

And then just use the following shorter code:

readEE(foo);

Which would be expanded out to:

foo = readEEPROM(AT24C32_ADDRESS, 1, fooPos);

My current question is: How can I write a macro that accepts 2 arguments instead of just 1? I couldn't find much information about this concerning Arduinos, so I studied about how to do it in C++ (like from here: http://en.cppreference.com/w/cpp/preprocessor/replace) but it was too complicated for me to understand.

In particular, I would like to learn if it's possible to shorten the following code:

void writeToEE(byte location, bool value, bool &var) {
  writeEE(loc, value); var = value;
}

(Sidenote: the writeEE function looks like this: void writeEE(uint8_t entry, uint8_t data) { writeEEPROM(AT24C32_ADDRESS, 1, entry, data); }. Since the first 2 arguments are almost always constants, that's why I shortened it with another function).

Since whenever I'm using writeToEE, the "entry" variable name is always the "data" variable name with "Pos" appended, I would ideally like to do this (pseudo-code):

#define wrEE(VAR, VAL) VAR = writeToEE(VAR ## Pos, VAL, VAR)

so that when I write this:

wrEE(fanSpeed, 3);

it will be expanded out to:

writeToEE(fanspeedPos, 3, fanspeed);

I just don't know how to pass the 2nd argument ("VAL") into the macro, which is the value being stored in the "fanSpeed" variable, in the "fanSpeedPos" location in the EEPROM. When I try to compile my pseudo code example (was hoping to get lucky!), I get the following error message: "void value not ignored as it ought to be"


texts:
Are there any i2c LCD screens that are larger than 2004 characters and larger than 4.8 x 2.7 x 1.2 inches in dimensions?

I have the Sainsmart 2004 LCD but it can't display all the information that I need. Maybe a 20x8 character screen? Because the screen will be viewed from a distance of about 50cm, the screen size should be at least 5" in diagonal.


texts:
So I'm working on a personal project using bluetooth abilities to start a BLE server and want to automatically retrieve a client's information after it's connected: ID so I can keep track of clients, but brand/make, serial.. and other information would be good as well.
My ServerCallback class looks like this
class ServerCallbacks: public BLEServerCallbacks
{
  void onConnect(BLEServer* pServer)
  {
    deviceConnected = true;
    BLEDevice::startAdvertising();

    String deviceID = "XXXXX";

    Serial.print("new device ");
    Serial.print(deviceID);
    Serial.println(" connected");

  };

  void onDisconnect(BLEServer* pServer)
  {
    deviceConnected = false;

    String deviceID = "XXXXX";

    Serial.print("device ");
    Serial.print(deviceID);
    Serial.println(" disconnected");

    pServer->startAdvertising(); // restart advertising
  }
};


texts: How would iconnect my Arduino Mega to house Mains, without buying a transformer, and having to make a whole setup for that.  Can i just use a regular phone adapter?  Or is 1 Amp too large (or 2 Amps).


texts:
Hy guys,

I am currently working on a quadcopter stabilization algorithm for an indoor quadcopter. I now need to setup a wireless communication between my onboard Arduino and my controlling Arduino (and/or RasperryPi (not shure yet)).

My question is: What would be the fastest wireless communication possibility?

I am not worrying about distance; they won't get far apart from eachother. I want to keep a lot of resources on the stabilization algorithm and to keep down resources used for the communication and thus get the fastest communication on very few resources.

What are your opinions and experiences, what is going to be fastest?


texts: If I was to use the Arduino A000024, would I be able to add a POE MODULE to the board to get a Ethernet board with POE to run my arduino project?


texts: Switch 230V 50Hz using a digital out pin

texts:
I would like to control normal household appliances like lamps, pumps etc. using my Arduino with up to 5 A. I looked a little around, but it seems, that most relais draw more current than the Arduino is capable of supplying.

How can I switch an 230 V AC current using my Arduino?


texts: How do I start a function with serial input?

texts:
I want to create a LED Sunrise/Sundown alarm clock. Therefore, I will use a Raspberry Pi that is sending commands over serial to a Teensy 3.1. Like:

"30 Minute Sunrise starting with Color(255,140,0)"
"20 Minute Sundown with Color(255,140,0)"
"start something else with these 3 parameter.

But I don't even get the basic serial part working. E.g. I tried this:

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.read() == 'A'){
      int inte1 = Serial.parseInt();
      int inte2 = Serial.parseInt();
      int inte3 = Serial.parseInt();
      int inte4 = Serial.parseInt();
      int inte5 = Serial.parseInt();
      if (Serial.read() == '\n') {
        Serial.print(inte1);
        Serial.print(inte2);
        Serial.print(inte3);
        Serial.print(inte4);
        Serial.println(inte5);
      }
    }
  }
}

I planned to do a case switch afterwards. Inte1 should define sunrise/sundown, Inte2 the minutes, 'Inte3-5' the rgb color.

However, when I enter "A 1 100 100 100" it is not printing anything at all.

What is the best way do get this working?

Thanks in advance!


texts: Arduino Uno - combined LCD and keypad interfacing problem

texts:
I have a problem with the Arduino Uno.

I need to use a 4x3 keypad and 16x2 LCD together with an Arduino Uno. As 4x3 keypad requires 7 pins, I have defined pins 2, 3, 4, 5, 6, 7 and 8 to it. A 16x2 LCD requires 6 pins but only 5 pins remain (9, 10, 11, 12 and 13). Pins 0 and 1 are used for serial.

Please suggest a probable solution.


texts: ESP8266 can't read parasitic DS18B20 temperature (reset during conversion, 85°C)

texts:
tl;dr at the end

I was running two DS18B20+PAR temperature sensors without any problems for the last two years on an ESP-01 module running on 3.3V on GPIO 2 using a 4.7K pullup resistor.

Now, wanting to develop a new firmware I started the development with new versions of everything (Arduino IDE and libraries), but now, with the exact same hardware setup that worked flawlessly for two years, the sensor always returns 85°C (error code for reset during conversion). I suspect that somehow, I don't know how, the ESP does not leave the data pin powered anymore.

To test this, I recompiled and flashed my old firmware that was running fine for two years and lo and behold, it still returned 85°C. Trying to isolate the issue, I flashed the old binary of the firmware and it returned the correct temperatures again.

To isolate the issue further, I tried numerous versions of the OneWire (2.3 to 2.3.2) and DallasTemperature (3.7.3 to 3.7.9) libraries, but to no effect. I am still getting 85°C all the time.

I also tried to compile it using Arduino IDE and PlatformIO, but both yielded the same issue still.
Trying on another ESP8266 (Wemos D1 mini and nodeMCU) did not change anything.

Slowly I am suspecting that the issue lies in the ESP8266-Arduino framework updating something or a change in the compiler, which now breaks keeping the data pin configured as output during the conversion.

Older versions of the ESP8266-Arduino framework (tried 2.2, 2.3, and up until latest) also produced the same error still.

A workaround, of course, is to use a lower value pullup resistor so that the sensors take power through that instead of the powered microcontroller pin. (One parasitic sensor requires 1K, two 470 Ohms) But this is not a solution.

Last weekend I debugged a bit deeper into the issue:

The OneWire library definitely leaves the pin as output (last macro called is DIRECT_MODE_OUTPUT()) and also the correct bit in the GPE pin mode register is set to output (1) during the conversion.
As far as I can see, the pin should be at 3.3V, but the oscilloscope definitely says the pin is dragged down too low (1.5V) during conversion. So it's only pulled up that far by the 4.7K pull-up resistor and not the GPIO pin for whatever reason...

I poked around here and there in the library but could not find the error. From what I can see, the code says that it should be working fine and my old binary says the hardware works fine too, but obviously it doesn't...

After five hours of unsuccessful debugging I gave up again.

I also opened an issue at the official OneWire GitHub Repo, but got no reaction in two weeks.

I will update this question in the following days by testing on other Arduino IDE versions and operating systems. Also, I want to try out the library fork from orgua to see if the issue happens in his library too.

tl;dr
- DS18B20+PAR with 4.7K pull-up always returns 85°C (error code indicating too little power on the data line) with newly compiled firmwares
- Hardware setup is working fine with old .bin
- Old code and new code freshly compiled yields error
- Doesn't depend on the library versions or what sketch is used
- Lower value pull-up resistor works, but is a dirty workaround

Hopefully someone else is able to reproduce or has already experienced this issue and is not satisfied with the workaround of using a lower pull-up resistor?


texts:
I have an Adafruit Trinket (5v, 16mhz, based off of the AtTiny85 chip), and am wishing to use it with a strip with 24 3 pin, individually addressable LEDs (WS2812B). When I try to compile my code, I get this error:  static_assert(validpin(), "Invalid pin specified"); I've tried using different pins, but of them are seeming to work. What can I do to fix this issue? Here's my current code:

#include <FastLED.h>
#define LEDCOUNT 24
#define DATAPIN 0

CRGB leds[LEDCOUNT];

void setup() {
  FastLED.addLeds<WS2812B, LEDCOUNT>(leds, LEDCOUNT);
}

void loop() {
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(30);
}


texts: Can I program the Arduino without having an actual board with the able to emulate a COM connection to the computer?

texts:
I have ordered my Arduino, but it is not going to arrive until 2 months, and I would like to be able to emulate a COM connection to the emulated Arduino. I am writing a program that listens on the com port, and would like to test it.

The program needs to run on Windows, and emulate a COM connection, and a breadboard with a LED, and motors on it.


texts:
I don't understand why the formatted string is displaying ?? instead of float values.
My code:
#include <Arduino.h>
#include <Wire.h>
#include "SparkFunCCS811.h"
#include <DFRobot_SHT3x.h>

DFRobot_SHT3x sht3x(&Wire, /*address=*/0x44, /*RST=*/4);

//* Get SHT31 readings

void readSHT(float &temp, float &humid)
{

    DFRobot_SHT3x::sRHAndTemp_t data = sht3x.readTemperatureAndHumidity(sht3x.eRepeatability_High);

    char shtVal[50];

    if (data.ERR == 0)
    {
        temp = data.TemperatureC;
        humid = data.Humidity;

        Serial.println(data.TemperatureC);
        Serial.println(data.Humidity);
    }

    snprintf(shtVal, 50, "Temp = %f  Humidity = %f", temp, humid);
    Serial.println(shtVal);
}

void setup()
{

    Serial.begin(115200);

    //*Initialize the chip
    while (sht3x.begin() != 0)
    {
        Serial.println("SHT31 Initialization Failed");
        delay(1000);

        Serial.print("Chip serial number");
        Serial.println(sht3x.readSerialNumber());

        if (!sht3x.softReset())
        {

            Serial.println("Failed to Initialize the chip....");
        }
    }
}

void loop()
{

    unsigned long newTime = millis();
    static unsigned long oldTime = 0;

    if (newTime - oldTime >= 5000)
    {

        float temp = 0.0;
        float humid = 0.0;

        oldTime = newTime;

        readSHT(temp, humid);
    }
}

& here is the output:
Here is what I get as output:
21.23
41.06
Temp = ?  Humidity = ?

The function readSHT()has no problem displaying the actual values but why the formatted string shows ???. Am I doing something wrong?


texts:
I'm at the stage where I can #include headerFiles.h into my arduino sketches.

I'm just beginning to wonder whether it's possible to append strings that are concatenated from integers which are analogRead from sensors to a .h file?

It'd make the arduino a lot more portable and would negate having to buy an SD card module.

How would the data be extracted? EEPROM is too small for datalogging past what you'd rack up in text over a reading every minute for a few hours.

Any clever clogs got ideas for this?


texts: Trying to read analog signal with digital pin using outside ADC

texts:
Is there a way to route an analog signal from a simple temperature sensor through an ADC, MCP3008, into a digital pin. I have used all the analog pins on my Arduino  Mega 2560 and am trying to utilize all the digital I/Os.

Any insights on the matter would be greatly appreciated.


texts: Deep sleep mode for the Uno without complicated circuits?

texts:
so I'm building something using an Uno that will run on batteries - so, I've watched a couple of these low power tutorials to lessen the energy consumption so the batteries can last longer, but they're not exactly what I want - they all require some sort of circuit. I've found this tutorial (http://www.engblaze.com/hush-little-microprocessor-avr-and-arduino-sleep-mode-basics/) which only needs an LED, and it's ideal, but I would like to know if you know of any other methods which would reduce consumption to less than 5mA without using any complicated circuits (other than unplugging the Uno)

Thank you!


texts: How do you balance an Arduino quadcopter using calculated gyro values?

texts:
I was working on an Arduino quadcopter project. I setup all my hardware and was having balancing problems with my software end. I am using an MPU-6050 gyro and accelerometer. I have calculated the angle of the quad in relation to the ground and was trying to implement these values by adjusting the output values to each of the four motors.

Here is some of my code:

    x=(-computedGyroAngleX-3.5)*10;
    y=(-computedGyroAngleY-2)*10;
    esc1.writeMicroseconds(rc_values[RC_CH1]+x-y);
    esc2.writeMicroseconds(rc_values[RC_CH1]+x+y);
    esc3.writeMicroseconds(rc_values[RC_CH1]-x-y);
    esc4.writeMicroseconds(rc_values[RC_CH1]-x+y);

If the quad is leaning forward I increase the power at the front of the quad and reduce it at the back. I do the same for the y axis. But I run into problems when I test out the quad. It flips over to the side or forward. How would I fix this?


texts: Trying to understand AccelStepper constant speed

texts:
I'm starting to learn the AccelStepper library for controlling stepper motors for a project I'm working on. I'm able to get the stepper motors running with the basic examples that use acceleration.
I know for parts or all of project I'll want to use constant speed, so I popped up the constant speed demo: https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library/blob/master/examples/Accel_ConstantSpeed/Accel_ConstantSpeed.ino
#include <Wire.h>
#include <AccelStepper.h>
#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);

void forwardstep1() {
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() {
  myStepper1->onestep(BACKWARD, SINGLE);
}

AccelStepper Astepper1(forwardstep1, backwardstep1);

void setup()
{
   Serial.begin(9600);
   Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz

  Astepper1.setSpeed(50);
}

void loop()
{
   Astepper1.runSpeed();
}

(I'm using the adafruit stepper motor wing)
I uploaded it to my arduino and it's working, the shaft is rotating, but it's doing it really slow. I figured this made sense because it's set at a speed of 50, so I tried turning up the speed:
Astepper1.setSpeed(200);

But the speed still seems to be the same speed. Considering this is a 200 step motor and setSpeed is steps per second you'd think this would whip the motor around fairly quick.
I'm positive that this is due to my misunderstanding of how the library works, but I'm having a hard time trying to figure out how to properly use the constant speed methods.


texts: Attaching Microcontroller to DAC evaluation board

texts:
For an independent undergraduate research project I'm trying to construct a digital feedback loop. I have never used an Arduino, or done much electrical/computer engineering, so I'm just taking things one thing at a time.
I've been given this
microcontroller
and this DAC eval board, and now I'm just trying to put them together.

From reading, I need to  attach jumper cables from #16 here to

the pins on the Eval Board here,

but I don't know where to find information on them, so I don't know which to plug into what. Any advice?


texts: Problem to Setting up i2c OLED wemos D1 mini shiled (64*24)

texts:
Hi

I used this shield before well. But it didn't work when I wanted to work with him last night!

this is my wireing :

Now I want to know how to test that it is healthy? Is i2c address missing or not?

I tried this code to find i2c address but no answer appeared on Arduino Serial monitor !! nothing ..

and i uploaded any more example code on Uno but OLED not worked .

//     ~~~~~~~~~~~ i2c Address Scanner ~~~~~~~~~~~

#include <Wire.h>

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

while (!Serial) {}

Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;

Wire.begin();
for (byte i = 8; i < 120; i++){
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0){
  Serial.print ("Found address: ");
  Serial.print (i, DEC);
  Serial.print (" (0x");
  Serial.print (i, HEX);
  Serial.println (")");
  count++;
  delay (1);
   }
  }
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
  }
  void loop() {}

.
   .

What is the problem ?


texts: Arduino Serial Monitor displaying weird characters and changes spelling

texts:
I am recieving the following in my serial monitor. There is a mix of wierd characters then the spelling changes for words once it gets repeated. I don't know why its doing this. my esp01 chip uses 115200 baud rate and the program is 115200 baud rate as well. What is going on.
#include <SoftwareSerial.h>

#define TIMEOUT 5000 // mS
#define LED 5

SoftwareSerial mySerial(7, 6); // RX, TX

const int button = 11;
int button_state = 0;

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(button, INPUT);

  Serial.begin(115200);
  mySerial.begin(115200);

  SendCommand("AT+RST", "Ready");

  delay(5000);

  SendCommand("AT+CWMODE=3", "OK");
  SendCommand("AT+CIFSR", "OK");
  SendCommand("AT+CIPMUX=1", "OK");
  SendCommand("AT+CIPSERVER=1,80", "OK");
}

void loop() {
  button_state = digitalRead(button);
  mySerial.println(button_state);

  if (button_state == HIGH) {
    SendCommand("AT+CIPSEND=0,23", "OK");

    delay(250);

    mySerial.println("
Button was pressed!
");

    delay(250);

    SendCommand("AT+CIPCLOSE=0", "OK");
  }

  String IncomingString = "";
  boolean StringReady = false;

  while (mySerial.available()) {
    IncomingString = mySerial.readString();
    StringReady = true;
  }

  if (StringReady) {
    Serial.println("Received String: " + IncomingString);

    if (IncomingString.indexOf("LED=ON") != -1) {
      digitalWrite(LED, HIGH);
    }

    if (IncomingString.indexOf("LED=OFF") != -1) {
      digitalWrite(LED, LOW);
    }
  }
}

boolean SendCommand(String cmd, String ack) {
  mySerial.println(cmd); // Send "AT+" command to module

  if (!echoFind(ack)) // timed out waiting for ack string
    return true; // ack blank or ack found
}

boolean echoFind(String keyword) {
  byte current_char = 0;
  byte keyword_length = keyword.length();
  long deadline = millis() + TIMEOUT;

  while (millis() < deadline) {
    if (mySerial.available()) {
      char ch = mySerial.read();
      Serial.write(ch);

      if (ch == keyword[current_char])
        if (++current_char == keyword_length) {
          Serial.println();
          return true;
        }
    }
  }

  return false; // Timed out
}


texts: How do you write to a free location on an external EEPROM?

texts:
I want to log GPS positions to an external EEPROM over I2C.

For example:
Latitude: 51.0000
Longitude: 4.0000

If I remove the decimal place then each of these addresses would consume up to two bytes each.

My question is: How can I log each new set of GPS data to a new memory address on the EEPROM each time?

Bearing in mind that the Arduino might be switched off between entries.


texts: Wire over 1ft does not work with sensors SRF02

texts: Im using an SRf02 ultrasonic sensor, and I need to make the wires long to elevate the sensor. They turn on and blink and are able to transmit a signal, yet they are not able to receive a signal. What is the error?


texts: Can I use 1 clock module for multiple Arduinos?

texts:
I want to connect an RTC to a master Arduino, send the time data to a slave Arduino through I2C, then connect an LCD to the slave and print it out.

can it be done? A think it would mean that the slave Arduino is a master for the LCD a the same time and it would mess up my code. Any input would be highly appreciated.


texts: How is a local variable address retrieved/returned inside the CPU of Arduino?

texts:
How is the address of a local variable retrieved in Arduino's ATMEGA328 micro-controller?

Lets say somewhere inside the main we have lines as:

int x = 5; //a variable declared and value of 5 stored in SRAM ??
int  *p; // a pointer is declared
p = &x; // p holds the address of the variable x

What happens above is &x retrieves the address of the variable x.

But how does this happen in a lower level?
Which function retrieves the address of a variable and how does it do it?
How does that function know the address of the variable x?
I'm wondering what happens step by step after the instruction comes to the instruction register.

edit: Another question for int x = 5; is 5 stored at CPU register or SRAM?
.


texts:
I realize it might be dumb question, but I've been at it for a few hours and I'm going nowhere. I am trying to figure out the standard Websocket library, however I have an issue casting the uint8_t to a String, so I can work with it easily, how do I do that and is it even possible? What I want to do is, get the payload from the main function as shown in the standard library and give it as a parameter to a function I have. This is the part I need, this is part of the switch statements in the standard library.

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {

   switch(type) {
     case WStype_DISCONNECTED:
     Serial.printf("[%u] Disconnected!\n", num);
   break;
   case WStype_CONNECTED:
    {
      IPAddress ip = webSocket.remoteIP(num);
      Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);

      // send message to client
      webSocket.sendTXT(num, "Connected");
    }
   break;
   case WStype_TEXT:
      Serial.printf("[%u] get Text: %s\n", num, payload);
      move(payload);


texts: Open the Uart0 Serial Port on Intel Edison

texts:
I'll preface this buy saying I am very new to working with Arduino boards or hardware in general.
I am attempting to follow a tutorial on instructables

http://www.instructables.com/id/PCBot/step4/Printer-test/

I have my board and printer wired up properly and I have git cloned the python thermal printer. My issue begins at this paragraph:

  Open the UART0 serial port
  by default the GPIO's of the edison are disables.

  You can enable them by programming the edison via the Arduino IDE or by using the MRAA library available for several programming languages.

  To open enable the UART0 port, TX RX on the edison breakout board, open a Python shell in the thermal and write:

  import mraa

  x=mraa.Uart(0)

I opened a python shell and entered the import mraa lines and tried to run the printertest.py

I receive an error that says no module named serial. I am not sure where the issue is. I thought the Edison already had python serial installed. I did try to install it with opkg install python-serial but it didn't work. If my issue is with enabling the Uart0 port I am not sure how to go about doing it. I have the Arduino IDE installed but I have no idea how to go about enabling it via the Arduino IDE. The instructions are a bit vague in that paragraph.

*Update I have successfully installed pip and got pyserial installed. Now when I try to run the printertest.py I get an error OSError: [Errno 2] No such file or directory: '/dev/ttyAMA0' which I think is potentially caused by me not succesfully opening Uart0 port but I am not sure how to. I tried adding the import in a shell as well as adding it directly to the code via nano


texts:
I created and learned this code myself from many examples. I tried to add another chip to it, but I have no idea. Do I need to rewrite all of it? Just some simple code is needed.

int latchPin = 2;
int dataPin = 3;
int clockPin = 4;
const int analogPin = A0;
const int ledPin = 13;
const int EmptyEn = 0;
const int GreenOne = 100;
const int GreenTwo = 200;
const int GreenThree = 300;
const int GreenFour = 400;
const int YellowOne = 500;
const int YellowTwo = 600;
const int RedOne = 750;
const int RedTwo = 900;
const int MaxHold = 1000;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void loop() {
  int analogValue = analogRead(analogPin);
  if (analogValue > GreenOne) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
    digitalWrite(latchPin, HIGH);
    delay(1);
  }
  if (analogValue > GreenOne) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B10000000);
    digitalWrite(latchPin, HIGH);
    delay(1);
  }
  if (analogValue > GreenTwo) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B11000000);
    digitalWrite(latchPin, HIGH);
    delay(1);
  }
  if (analogValue > GreenThree) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B11100000);
    digitalWrite(latchPin, LOW);
    delay(1);
  }
  if (analogValue > GreenFour) {
    digitalWrite(latchPin, HIGH);
    shiftOut(dataPin, clockPin, MSBFIRST, B11110000);
    digitalWrite(latchPin, LOW);
    delay(1);
  }
  if (analogValue > YellowOne) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B11111000);
    digitalWrite(latchPin, HIGH);
    delay(1);
  }
  if (analogValue > YellowTwo) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B11111100);
    digitalWrite(latchPin, HIGH);
    delay(1);
  }
  if (analogValue > RedOne) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B11111110);
    digitalWrite(latchPin, HIGH);
    delay(1);
  }
  if (analogValue > RedTwo) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
    digitalWrite(latchPin, HIGH);
    delay(1);
  }
  if (analogValue > MaxHold) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
    digitalWrite(latchPin, HIGH);
    delay(100);
  }
  Serial.println(analogValue);
  delay(1);
}


texts: What is the proper way to turn an Arduino UNO into an ISP?

texts:
I have a bricked Arduino Uno and I want to try to flash the bootloader. I'm trying to figure out how to do it. On this tutorial from SparkFun you can see this diagram:

They also show this table of the pinout

That seems simple enough but it's totally different than the official tutorial, "Circuit (targeting Arduino Uno, Duemilanove, or Diecimila)"

Which also says

  An Arduino board serving as an ISP to program the ATmega on another Arduino board. On the Arduino Uno, you'll need to connect a 10 uF capacitor between reset and ground (after uploading the ArduinoISP sketch). Note that you need access to the reset pin on the target board, which isn't available on NG or older boards.

So do I need a 10 uF capacitor between reset and ground? How do I put a 10 uF capacitor in between reset and ground when, in this configuration, reset is connected to PIN 10? Why are there two configurations? What's the upsides and downsides to either of them?


texts: LED doesn't register as LOW after a switch has cut all power to it

texts:
I have the following build:

And the following code:

const int buttonPin = 3;
const int ledPin = 2;
int buttonState = 0;

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

  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

}

void loop() {
  while (digitalRead(ledPin) != LOW){
    buttonState = digitalRead(buttonPin);

    if (buttonState == LOW){
      digitalWrite(ledPin, LOW);
    }
  }
}

But it doesn't seem like anything is registered, as my program doesn't respond to the shut down of the LED. What have I done wrong?


texts: How can I save my float 'ave' on the EEPROM continuously?

texts:
How can I save my output continuously to EEPROM? Or is this even possible? Please help me out.

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

void loop() {
  static unsigned long count = 0;
  static float sum = 0;
  float ave = 0;
  int volt = analogRead(A1);
  float voltage = map(volt, 0, 1023, 0, 2500) / 100.0;
  Serial.print("Voltage: ");
  Serial.println(voltage, 2);
  sum = sum + voltage;
  count++;
  ave = sum / count;
  Serial.print("Average: ");
  Serial.println(ave, 2);
  Serial.println("-----");
  delay(3000);
}


texts: Different voltage sources across Vin and DC jack

texts:
So I understand that the USB VBUS circuitry turns off provided there is a high enough vin voltage using the PFET and comparator.

I can see that the DC jack is connected to the Vin pin via a diode.
However, what is to stop someone from plugging a voltage source across the Vin and at the same time putting across a voltage on the DC jack.

If I incorrectly plugged in a voltage source of a low voltage like a coin cell battery across the VIN pin and also powered the device using the 9 V DC jack, wouldn't that then send current through the VIN pin and back to the coin cell battery?

Is that what would happen in this instance? And if so then shouldn't there be a design feature to prevent users from damaging it like that? Fool/fail safe?


texts: How to reverse BLDC motor using programming arduino?

texts:
I bought ESC from here but it rotates motor in one direction only.

Is there any program which will control direction of rotation clockwise or anticlockwise with same wire configuration.


texts: Using a pushbutton to power Arduino on and off

texts:
I need help adding a pushbutton to provide power to an Arduino to save power, as I am using a battery and the same button to power it off. This is the circuit I wish to implement.

Thanks.


texts:
I have a GSM shield connected with my Intel Galileo board.

I intend to connect the board with serial communication at a baud rate of 115200 instead of the GSM library. I want to print the results of "at" commands in my serial window, how should I do it?


texts: How to externally power HC-05 module with Arduino Pro Mini?

texts:
guys, I am new to arduino. I am trying to power my HC-05 (5v with regulator to 3.3v) from Arduino Pro Mini 3.3v but I can't get it to power on.

There is a problem: The site I bought HC-05 from says that it needs 3.3-6 volts to power on but the back of HC-05 shows only 5v pin. To confirm that it runs only on 5v I need to connect it to external 5v supply.

But how do I make the connection? What do I connect to negative of the battery if I choose to externally power it?

Second Problem: If my HC-05 turns out to need only 3.3v input voltage, how many coins cells do I connect in series to power both pro mini and HC-05 module.

I am using a coin cell (3.3v) for powering the pro mini.

Thanks...


texts: Reading and Writing to a JSON File on the Desktop from Arduino?

texts: I'm fairly new to Arduino. I'm working on a project where I'm making HTTP requests using a python code and this lets me read and write to a JSON file on my desktop. I have an Arduino with sensors that records values and I want to take those recorded values and update them to the JSON file on my desktop in real-time. I looked online and many suggested using some Arduino library, but it was only for reading. I'm still confused about reading and writing to the JSON file on my desktop. I appreciate any help to guide me in the right direction. Thank you.


texts:
This is my first time here and I hope someone can be of help!
I'll try to keep it as concise as possible.

So I have two sensors/modules, 1 is an LCD screen from elecrow and another is the DS1307. Both are connected through analog 4 and 5. I tried hooking them up with the help of my breadboard but I've stumbled upon the following issue with the libraries (I don't even know if what I'm trying to achieve is possible but I'm trying nevertheless(and failing horribly while at it))

In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:22:0:

    C:\Users\c\Documents\Arduino\libraries\RTClib/RTClib.h:79:31: error: redeclaration of 'OFF'

     enum Ds1307SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

                                   ^
In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:21:0:

    C:\Users\c\Documents\Arduino\libraries\I2C_LCD/I2C_LCD.h:457:5: note: previous declaration 'LCD_SwitchState OFF'
         OFF=0x00,

         ^
    In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:22:0:

    C:\Users\c\Documents\Arduino\libraries\RTClib/RTClib.h:79:42: error: redeclaration of 'ON'

     enum Ds1307SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

                                              ^
In file included from C:\Users\c\Documents\Arduino\Sketches\IC2_Checker\BME280_LCD_Time\BME280_LCD_Time.ino:21:0:

    C:\Users\c\Documents\Arduino\libraries\I2C_LCD/I2C_LCD.h:458:5: note: previous declaration 'LCD_SwitchState ON'

         ON=0x01

         ^

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

What I make out of this, is that the libraries are conflicting with each other on the following:

OFF = 0x00
ON = 0x80
ON= 0x01

Is there anyway to fix this? I know that I have to edit the .h libraries but I don't know what to change and to what it should be changed, here's the library code on the module itself:

// RTC based on the DS1307 chip connected via I2C and the Wire library
enum Ds1307SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

class RTC_DS1307 {
public:
   boolean begin(void);
   static void adjust(const DateTime& dt);
   uint8_t isrunning(void);
   static DateTime now();
   static Ds1307SqwPinMode readSqwPinMode();
   static void writeSqwPinMode(Ds1307SqwPinMode mode);
   uint8_t readnvram(uint8_t address);
   void readnvram(uint8_t* buf, uint8_t size, uint8_t address);
   void writenvram(uint8_t address, uint8_t data);
   void writenvram(uint8_t address, uint8_t* buf, uint8_t size);
};

Thank you for your help!

C.C

EDIT:
I think that I might have come a bit closer. I tried implementing one of the answers and that made me get the following error:

    C:\Users\c\Documents\Arduino\libraries\RTClib\RTClib.cpp:284:1: error: 'Ds1307SqwPinMode' does not name a type

 Ds1307SqwPinMode RTC_DS1307::readSqwPinMode() {

 ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

That's a whole lot less than before. I will keep this updated!

EDIT 2:

Meanwhile, I tried something entirely else like changing the name of OFF and ON Throughout the RTClib concerning only the DS1307 module. That however gives me an entirely new line of errors such as:

error: 'enum Ds1307SqwPinMode' is not a class or a namespace

  RTC_DS1307 Ds1307SqwPinMode::readSqwPinMode() {

                                              ^

and:

error: could not convert '(Ds1307SqwPinMode)mode' from 'Ds1307SqwPinMode' to 'RTC_DS1307'

   return static_cast<Ds1307SqwPinMode>(mode);

                                            ^

These errors in particular only take place in the .cpp library
This is where I am stuck now at the moment


texts:
I am using :
-arduino uno r3
-SIM800L

connection:

Arduino   SIM800L
5v     -->  vcc
gnd    -->  gnd
pin10  --> TX
pin11  --> RX

the led on the module blinks once each 3~5 seconds
but when i use the function sim.available() i got 0;
thus as i guess there is a problem .

the code :

#include <SoftwareSerial.h>
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;
String number = "000000000000"; //-> change with your number
void setup() {
  delay(7000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Sistem Started...");
  sim.begin(9600);
  delay(1000);
  Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
}
void loop() {
  Serial.print(Serial.available());
  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 's':
        SendMessage();
        break;
      case 'r':
        RecieveMessage();
        break;
      case 'c':
        callNumber();
        break;
    }
  if (sim.available() > 0)
    Serial.write(sim.read());
}

i looked the internet they say the voltage should be 3.7~4.2 itriedgivving 3.55 and it didn't work


texts: i'm trying to decode infrared signal recorded with the saleae. It makes me wonder why saleae shows so low values for the frequencies from 0.1kHz to 0.8kHz. I found that standard for the IR is around 38kHZ. Is there something wrong with my record? Or did i misread the sample?


texts: Is programming the ATTiny85 possible in 1.5?

texts:
I upgraded to Arduino 1.5.7 in hopes of using the command line interface for a larger project. However, the old package I was using to program the ATTiny85 chip with the Sparkfun Tiny AVR Programmer no longer works. I'm getting the following error:

Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer.
processing.app.debug.RunnerException
    at processing.app.debug.Compiler.getCommandCompilerCPP(Compiler.java:597)
    at processing.app.debug.Compiler.compileFiles(Compiler.java:275)
    at processing.app.debug.Compiler.compileSketch(Compiler.java:642)
    at processing.app.debug.Compiler.compile(Compiler.java:125)
    at processing.app.Sketch.build(Sketch.java:1589)
    at processing.app.Sketch.exportApplet(Sketch.java:1611)
    at processing.app.Sketch.exportApplet(Sketch.java:1597)
    at processing.app.Editor$DefaultExportHandler.run(Editor.java:2397)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at processing.app.helpers.StringReplacer.replaceFromMapping(StringReplacer.java:97)
    at processing.app.helpers.StringReplacer.replaceFromMapping(StringReplacer.java:89)
    at processing.app.helpers.StringReplacer.formatAndSplit(StringReplacer.java:37)
    at processing.app.debug.Compiler.getCommandCompilerCPP(Compiler.java:595)
    ... 8 more

Does a package exist that will allow me to program the chip in 1.5.7?


texts: Sending a value from one arduino to another

texts:
I wonder if it is possible to send a value from one  arduino to another.

Basically, I have one arduino measuring let's say weight, but I want to display that value using an lcd in another arduino.
Is it possible to  send the value to a pin using analogwrite or digital write in the arduino doing the measurement and use analogread/digitalread at the other arduino making the display?

I do not know if this is possible but what is attractive is that one can have several arduino making weight measurements, all showing up in the display of just one central one...


texts:
I'm wondering where the pin setting is manifested in the library.
I want to use the RC522 with other digital pins than the default 50-53 pins, because I am using a shield for a display on theese ports.

Where can I change the used ports?
why are two ports user-defineable #define RFID_SS  10 #define RFID_RST 5 while the rest is not?

I am with this Playground-Guide using this library from Github on my Arduino Mega


texts: SIM900a Mini Modem, IMEI 0, help with TX RX pins

texts:
I have Simcom SIM900a GSM (SIM900a Mini DEV Board v3.9.2) and I am interfacing it with Arduino UNO.
I have no idea how to connect SIM900a to Arduino UNO.
What I did now is:

I connect the following Pin from above image to:
5 to: GND (Digital GND near Pin 13)
6 to: 5V of Arduino
2 to: GND of Arduino near 5V
3 to: Digital Pin 0 of Arduino (RX)
4 to: Digital Pin 1 of Arduino (TX)
1 to: (No idea)
From Picture option 7, 8, 9 are not connected to anything.
Can you please guide me am I doing right?
I am getting hard time to find out what is TX and RX in my SIM900a module as it is not written there.
My SIM900a looks like this, this(Schematics given) and this.
When I upload the sketch:
File > Examples > GSM > TestModem:
to Arduino, I got this output from Serial Monitor:

Starting modem test...ERROR, no modem answer.
Checking IMEI...Modem's IMEI: 0
Reseting Modem... Modem is functioning properly: IMEI: 0

PS:
I saw this schematic here which is way different than what I am doing.
PSS:
Hints, am I supposed to provide external power supply of 5 V 2 A OR do I need some kind of converters (TTL to RS232 converter) ?


texts: AT command to put the A6 GSM/GPRS into sleep / power down

texts: The general AT command for sleep mode (for the SIMCOM GSM modules) is AT+CSCLK=1 (or AT+CSCLK=2). I have given both a shot but they don't work with the A6 module. Does anyone know of any other command that does the same? The manufacturers claim that it can function at very low current levels when in sleep. But sadly they don't mention the sleep AT command.


texts: SD Card store struct: force big-endian / little-endian?

texts:
Following MAJENKO's tutorial on sd card file optimization and data integrity, can I force the SDCard to read and write in either big-endian or little-endian?

I need this in order to maintain backup data integrity across a wide array of IoThings, using various boards (Arduino UNO, MEGA, Nano, NodeMCU, etc) for future parsing.


texts: Robust communication between Xbee and Python

texts:
I am using Xbee API library for Python to process the data received by the Xbee module. I am wondering how to construct the robust protocol for sending and receiving data. What I would like to build is

send the data request message to power monitoring uint (Xbee in remote).
Receive the transmitted power monitoring data and process it in Python.

If the aforementioned process works in just one time, it would be great, but sometimes it does not work. Thus, I would like to code autonomous acknowledging procedure into this communication. That is

send the data request message to power monitoring uint (Xbee in remote).
If the dat is not received, go back to 1.
If the data is received ok.

Here are my code, but it does not work all the time. Would you please look at how can I improve the code further to make it this

def listeningAndClusterData(targetWT):

#targetWT-->this will be used to construct the target address
targetAddress = struct.pack('b',0x00)+struct.pack('b',targetWT)
Data = struct.pack('h',0x0000) #prefix for requesting information
xbee.tx(dest_addr=targetAddress, data=Data)
ser.flush()
time.sleep(0.01)
response = xbee.wait_read_frame(100)#wait for data packet from Xbee, if packet is not recieved within 100ms, return 1

watingData = 1;
while watingData:
    try:

        if response != 1: # if the data is received
            sa = hex(response['source_addr'])
            rf = hex(response['rf_data'])
            datalength=len(rf)
            agentId = int(sa[2:4],24)
            # if datalength is compatible with two floats
            if datalength==16:
                voltage=struct.unpack('f',response['rf_data'][0:4])[0]
                current=struct.unpack('f',response['rf_data'][4:8])[0]
                power=voltage*current
                watingData = 0 # I received the average data and escape the loop
                ser.flush()
            else: #data is received but the format is not correct
                ser.flush()

        if watingData != 0: #if the data is not received--> keep sending the request message to other xbee
            xbee.tx(dest_addr=targetAddress, data=Data)
            print("data is requested again")
            time.sleep(0.01)
            ser.flush()
            response = xbee.wait_read_frame(100)

    except KeyboardInterrupt:
        break

return  voltage, current, power


texts:
I have an esp32cam that I've programmed and powered via an FTDI connected to a computer's USB. Now that this stage is over, I'd like to run it portably, using some sort of battery.
The esp32cam has a 5V input (also a 3.3V input which word is should be avoided because it causes brownout). I'm wondering if it's possible to power it (for a short period) using a 7.3V, 9V or 12.3V battery. All the datasheets I've seen seem to specify the input range is 5V, but, for the esp32 (non-cam version), unregulated 5V-12V seems to permissible. Is this true for the esp32cam? Also, what is the right way to search for this?


texts:
In my low power project, I'm using a Arduino Pro Mini (5V, 16 MHz, ATMEGA328) and a low wattage 3W power supply. Everything else on the system other than the Arduino uses a max of 1.98W.

How much power should I budget for the Arduino Pro Mini (without any mods, ie: disconnecting the voltage regulator and LED)?


texts: If any kind of character gets loaded into a string, what do I use for an end-of-line character?

texts:
I have an Arduino project that is converting floats to characters and then transferring those characters via the serial to a Python program. This is a portion of the Arduino code:

#define MEM_LEN (16 * 4 * 4) + 1
uint8_t dataBuf[MEM_LEN];

typedef union {
  float f;
  uint8_t b[4];
} cvt_t;

cvt_t cvt1;

// set up sensor stuff
MLX90621 sensor;
 .
 .
 .

void loop() {
    sensor.measure(); //get new readings from the sensor
    count = 0;
    for(uint8_t y=0;y<4;y++){ //go through all the rows
      for(uint8_t x=0;x<16;x++){ //go through all the columns
        cvt1.f = sensor.getTemperature(y+x*4); // data at position x/y
        dataBuf[count + 0] = cvt1.b[0];
        dataBuf[count + 1] = cvt1.b[1];
        dataBuf[count + 2] = cvt1.b[2];
        dataBuf[count + 3] = cvt1.b[3];
        count += 4;
      }
    }
    dataBuf[MEM_LEN - 1] = '\n'; // not a good delimeter
    Serial.write(dataBuf, MEM_LEN);
}

The problem is that float conversion loads any and all characters into dataBuf, so I don't have a good delimiter or "end-of-line". When the Python program ingests the incoming string, there's nothing to use to know it's received a complete frame. I don't want the Python to just count characters to know when it's received a frame. No good delimiter - what should I do?


texts: 256 (8x32) LED Matrix via ESP32-Pico-Kit_V4 possible? (Daft Punk Helmet)

texts:
I am currently planning on a Daft Punk Helmet. But the available kits are terribly expensive.

I am looking forward to using a 8x32 LED-Matrix(with 256 separate 5mm LEDs) and having a few different display modes which include static text and also repeating animations like a wave going back and forth, or digital eyes that wink. Also a Bluetooth connection would be nice and of course portability is important.

That's why I was looking at the ESP32-Pico-Kit_V4.

My question now: Is it possible to run such a big LED-Matrix off this ESP or would I need some extra boards/controllers and if so which would be necessary.
Or is this as a whole a much bigger project than I am expecting?

PS: I don't wanna use one of the prewired 8x32 panels because they are not see-through.

-- Arduino rookie needing some help


texts: Multiple definition error when linking firmware.elf

texts:
I just can't wrap my head around on how to properly work with multiple files. My code has been getting quite big so I decided to split all the classes into one file each. So I'm left with 6 files:

dataHandler.cpp
fileHandler.cpp
header.cpp
main.cpp
request.cpp
sensorData.cpp

header.cpp includes all the header files, and main.cpp the setup() and loop() functions.

Visual Studio Code shows me no errors while compiling. The includeguards have the name convention: CLASSNAME_INCG

So in my main.cpp for example I have something like:

#ifndef HEADER_INCG
#include "header.cpp"
#define HEADER_INCG
#endif

#ifndef SENSORDATA_INCG
    #include "SensorData.cpp"
    #define SENSORDATA_INCG
#endif

#ifndef DATAHANDLER_INCG
    #include "DataHandler.cpp"
    #define DATAHANDLER_INCG
#endif

setup()
{
    ...
}

...

When going into a class-file I have it defined in the following way (fileHandler.cpp):

#ifndef HEADER_INCG
#include "header.cpp"
#define HEADER_INCG
#endif

#ifndef FILEHANDLER_INCG
#define FILEHANDLER_INCG

class FileHandler{
    ...
}

#endif

So in summary I include the headerfile into every file, with includeguards arround. If I wouldn't include it I would get errors that crucial libaries like Serial etc. are missing. But when including the header into every file compiliing works just fine, but when it comes to linking the files togehter I get an error of multiple definitions.

So how can I define the headerfile just once for all files albeit I need it in every file?


texts: How do I install the firmware on an Arduino Mega clone?

texts:
I have a brand new board which is a clone of the Mega2560.  I need to install the USB firmware on the 16U2 and the bootloader on the 2650 chip.  I have Atmel Studio and a JTAGICE-3. Using those, I can download HEX files compiled with the Arduino  IDE, and they run successfully.

But I'm having trouble finding Mega-specific instructions for getting the firmware installed so that I can use the Arduino ISP protocol for downloading new sketches. I can find much more information about the Uno than the Mega. And much of the information I do find seems to be dated.

1) Which are the right files to download?
   I've tried to install the 'MEGA-dfu_and_usbserial_combined.hex' to the 16U2 and the 'stk500boot_v2_mega2560.hex' to the 2560.

But the IDE won't connect via AVR ISP, and I get no serial communications from a serial sample sketch downloaded with the ICE.

2) What are the correct Fuse settings after I flash those files?

3) Is there a good way to confirm that the 16U2  USB converter is working correctly in isolation from the 2560 chip?


texts: make EEPROM.h use custom eeprom partition

texts:
I created the below partition table for an esp32 and replaced the 'default_8MB.csv' with it.

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x330000,
app1,     app,  ota_1,   0x340000,0x330000,
eeprom,   data, 0x99,    0x670000,0x1000,
spiffs,   data, spiffs,  0x671000,0x18f000,

After uploading a sketch, I confirmed that the partition table was correctly uploaded to the flash at address 0x8000, using esptool.py --port /dev/ttyACM1 read_flash 0x8000 0x300 partition_table.bin && gen_esp32part.py partition_table.bin && cat partition_table.bin.

Now my question is: what do I have to do so that the EEPROM.h library maps the eeprom emulation to the address that I have specified in the partition table? I naively assumed that EEPROM.h would automatically use the partition named "eeprom", which doesn't seem to be the case.

I uploaded the following test sketch to analyse the situation:

#include <Arduino.h>
#include <EEPROM.h>

String s="this is a unique string";

void setup(){
  EEPROM.begin(1024);

  for (uint32_t i=0;i<s.length();i++){
    EEPROM.write(i,s[i]);
  }
  EEPROM.commit();
  Serial.println("EEPROM stored");
}

void loop() {
  delay(10000);
}

After the sketch has stored my unique string I read the flash memory using esptool and expected to find the string at an offset of 0x670000, but that wasn't the case. Instead it must be stored somewhere else because I can retrieve the string in a different sketch.

One thing that is confusing me: I'm pretty sure that I once ordered ESP-WROOM32s with 4MB flash, but the esptool's auto-flash-detection states that my board has 8MB. Can this flash-detection be trusted or does it simply fail because I try to flash 8MB to a 4MB ESP32? What is supposed to happen if I created a partition table that exceeds the flash memory size? When I put a partition table at an offset of 10M the build process still doesn't fail (is that what should happen?).

My main question: which additional steps do I have to take to get my ESP running with a custom_partion_table.csv (beside creating the table) and when using "EEPROM.h"?


texts: MIDI output circuit behaving incorrectly when not connecting with USB

texts:
I recreated this circuit to send MIDI notes to my MIDI-USB adapter to my computer.

It works fine when the Arduino is powered via USB. When I power the Arduino Nano with 9v on Vin however, the output is gibberish. It just spams the input monitor on my computer with random midi commands. For testing I used this code:

    #include <MIDI.h>

    MIDI_CREATE_DEFAULT_INSTANCE();

    static const unsigned ledPin = 13;
    bool on = false;
    void setup()
    {
        pinMode(ledPin, OUTPUT);
        MIDI.begin(MIDI_CHANNEL_OFF);
    }

    void loop()
    {
        digitalWrite(ledPin, on);
        on = !on;
        MIDI.sendControlChange(12, 127, 1);
        delay(1000);
    }

The Arduino itself seems to be working fine when powered with 9v (note that I tested with both a wall power supply as well as a 9v battery) as the TX-led still  flashes briefly and the built-in led also toggles nicely.

At first I blamed my power supply and/or my power supply, but both work fine on my MIDI-keyboard so I don't think they are to blame.

Worth mentioning: When the Arduino was powered by Vin, I also as a test plugged in the USB-cable in the Arduino, But only touched the connector on the USB-port on my computer. I then received the correct notes.

Because of this I think it is an issue with the grounding. What am I doing wrong?

EDIT: Thanks for the response guys. I think I diagnosed my problem incorrectly. I'm using a cheap Chinese MIDI-adapter which I pried open, and it lacks an optocoupler. I'm getting a decent MIDI adapter now. Thanks!


texts: How to get timestamp of when the data was collected

texts:
Basically I want to be able to display the time the arduino collected the data with the data value, not the time the arduino printed off the data. Theres a timestamp feature on the console, however I want to find the time the data was collected.
I'm a bit new to this so any help is greatly appreciated!


texts: Using Keyboard library for ISO-UK layout

texts:
I am creating a keyboard and the PC I use it with is configured for UK so the keyboard layout it expects is this

I've highlighted the ISO-UK vs ANSI-US differences but the only key I am having real problems with is the backslash key.
My physical layout is actually this (ortholinear "Planck") but it's essentially the same except with two logical layers and variation in positioning.

The above is a fully functional UK-layout keyboard with the exception of the "\" key.
The sketch I am using is too large and distracting to post here but the following test sketch
#include "Keyboard.h"

byte keylist[] = { '`', '2', '3', '\'', '#', '\\' };

void setup() {
  Keyboard.begin();
  delay(1000);

  // unshifted
  for (byte i = 0; i < sizeof(keylist); i++) {
    Keyboard.press(keylist[i]);      delay(100);
    Keyboard.release(keylist[i]);    delay(100);
  }

  Keyboard.press(KEY_RETURN);
  Keyboard.releaseAll();

  // shifted
  for (byte i = 0; i < sizeof(keylist); i++) {
    Keyboard.press(KEY_LEFT_SHIFT);
    Keyboard.press(keylist[i]);
    delay(100);
    Keyboard.releaseAll();
    delay(100);
  }
}

void loop() {
  delay(1000);
}

Creates this output (in a Notepad window)
`23'£#
¬"£@£~

I did try switching focus to a keyboard diagnostic tool - KeyHitter by Elite Keyboards which showed different results
12:31.0675 ` (0xDF, BIOS 0x29) DOWN
12:31.0771 ` (0xDF, BIOS 0x29) UP -> 100ms
12:32.0772 2 (0x32, BIOS 0x03) DOWN
12:32.0871 2 (0x32, BIOS 0x03) UP -> 100ms
12:33.0872 3 (0x33, BIOS 0x04) DOWN
12:33.0972 3 (0x33, BIOS 0x04) UP -> 100ms
12:34.0972 ' (0xC0, BIOS 0x28) DOWN
12:35.0072 ' (0xC0, BIOS 0x28) UP -> 100ms
12:36.0072 LShift (0x10, BIOS 0x2A) DOWN
12:36.0082 3 (0x33, BIOS 0x04) DOWN
12:36.0172 LShift (0x10, BIOS 0x2A) UP -> 100ms
12:36.0182 3 (0x33, BIOS 0x04) UP -> 100ms
12:37.0172 \ (0xDE, BIOS 0x2B) DOWN
12:37.0272 \ (0xDE, BIOS 0x2B) UP -> 100ms
12:38.0271 Enter (0x0D, BIOS 0x1C) DOWN
12:38.0273 Enter (0x0D, BIOS 0x1C) UP -> 2ms

...
So the Arduino Keyboard library translates '#' into shift+3 which is unhelpful for UK users but I'm mystified why Keyhitter sees that '\\' produces the expected \ but other programs see it producing #! I guess Keyhitter intercepts keystrokes at a lower level than normal applications - for example it correctly shows Win being pressed but prevents Windows opening a start-menu.
The result in Notepad is typical of the effect produced in normal applications. So that's probably more relevant.
I can work around the '#' producing a shift+3 since '\\' produces # but how then do I generate a \?


texts: Uno pin connection: Atmega16u2 & ATmega328P

texts:
On my Uno, I set up the HoodLoader2 (link below) so I can program both the ATMega16u2 and the ATmega328P. I can communicate between the two using the serial port. However, I need the serial port to communicate between the Uno and the PC. Can I communicate between the 328 and 16u2 using a common digital pin? All I need to communicate is a simple yes/no state, preferably in both directions. In other words: can I connect a digital pin (say 12) on the Uno to, say, PB1 pin on the 16u2's ICSP header, set pin 12 value to HIGH on the 328P, then read that state on the 16u2 via PB1? And vice versa, via another pair of pins? There's a Q that's close to what I want (link below) and the user there (@jsotola) seems to have the knowledge, but I can't comment under his comment, as I don't have 50 reputation.

HoodLoader2

Accessing digital pins from the ATMega16u2


texts: Can I control a cellphone's lcd (+touch screen)?

texts:
I had an Xperia txt pro just laying around and tried to revive it. I burned it like an idiot using 5v in the battery pins by accident :/
So I decided to read it apart and got to the lcd, can I use my Arduino Mega to control it? Bc I have no idea how to use it.

These are the pins


texts: Touch Sensor - Determining Pressing/Hold Length and Modifying Program Flow Accordingly

texts:
The code below is used for controlling a relay with an Arduino. Pressing the touch sensor connects and disconnects the relay.

If the user presses/touches/holds their finger on the touch sensor for longer than two seconds, how do I adjust the program to do something other than connecting or disconnecting the relay?

#define TouchSensor 9 // Pin for capactitive touch sensor

int relay = 2;

boolean currentState = LOW;
boolean lastState = LOW;
boolean RelayState = LOW;

void setup() {
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
  pinMode(TouchSensor, INPUT);
}

void loop() {
  currentState = digitalRead(TouchSensor);
    if (currentState == HIGH && lastState == LOW){
    Serial.println("pressed");
    delay(1);

    if (RelayState == HIGH){
      digitalWrite(relay, LOW);
      RelayState = LOW;
    } else {
      digitalWrite(relay, HIGH);
      RelayState = HIGH;
    }
  }
  lastState = currentState;
}


texts:
Is there anything like the link below that I can read/set with an arduino/raspberry pi?

I'd like to be able to control this completely from a computer in my kegerator setup.

Any search terms that might help me find something would be useful too.

Thanks

http://www.amazon.com/Taprite-Product-Pressure-Kegerator-Regulator/dp/B0060NOX40/ref=lh_ni_t?ie=UTF8&psc=1&smid=AEUC6GAA8XY7Y


texts: Bit shifting fails with warning: left shift count >= width of type

texts:
Given the following minimal working example. I tested this initially with uint16_t and it worked with no warnings. After that, I adjusted everything to work with uint32_t.

#include <stdint.h> /* needed for the uint16_t type*/
#include <inttypes.h> /* needed for sscanf uint16_t format placeholder  */
#include "printf.h"

#define SET_CMD_ID(ID)    ( (ID) << 27)
#define SET_CMD_CMD(CMD)  ( (CMD)  << 25)
#define SET_CMD_TYPE(TYPE)  ( (TYPE) << 19)
#define SET_CMD_PKT(PKT)  ( (PKT)    )

void setup() {
  Serial.begin(115200);
  printf_begin();
  Serial.print(F("\n\rExample command\n\r: "));

}

void loop() {
  uint32_t payload = 0;

  uint8_t id = 3;   // 00000 - 5
  uint8_t cmd = 2;  // 00    - 2
  uint8_t type = 1; // 000000 - 6
  uint32_t pkt = 0; // 0000000000000000000 - 19

  payload =
        SET_CMD_ID(id)   |
        SET_CMD_CMD(cmd)  |
        SET_CMD_TYPE(type) |
        SET_CMD_PKT(pkt);
  Serial.print(F("Now sending "));
  Serial.println(payload);
  delay(2000);        // Try again soon
}

Verifying this sketch outputs:

/path/to/ino/Arduino32bitTest.ino: In function 'void loop()':
/path/to/ino/Arduino32bitTest.ino:5:37: warning: left shift count >= width of type [enabled by default]
 #define SET_CMD_ID(ID)    ( (ID) << 27)
                                     ^
/path/to/ino/Arduino32bitTest.ino:28:9: note: in expansion of macro 'SET_CMD_ID'
         SET_CMD_ID(id)   |
         ^
/path/to/ino/Arduino32bitTest.ino:6:39: warning: left shift count >= width of type [enabled by default]
 #define SET_CMD_CMD(CMD)  ( (CMD)  << 25)
                                       ^
/path/to/ino/Arduino32bitTest.ino:29:9: note: in expansion of macro 'SET_CMD_CMD'
         SET_CMD_CMD(cmd)  |
         ^
/path/to/ino/Arduino32bitTest.ino:7:41: warning: left shift count >= width of type [enabled by default]
 #define SET_CMD_TYPE(TYPE)  ( (TYPE) << 19)
                                         ^
/path/to/ino/Arduino32bitTest.ino:30:9: note: in expansion of macro 'SET_CMD_TYPE'
         SET_CMD_TYPE(type) |
         ^

Sketch uses 3,174 bytes (9%) of program storage space. Maximum is 32,256 bytes.
Global variables use 216 bytes (10%) of dynamic memory, leaving 1,832 bytes for local variables. Maximum is 2,048 bytes.

Executing the sketch on an Arduino Uno results in:

Example command

: Now sending 0
Now sending 0
Now sending 0
Now sending 0

I googled the message of the warning and found out that it could mean that I'm trying to shift 32bit which is undefined, but I'm not sure on that. So my question is:
What am I doing wrong here? How can I get this to work?


texts: Arduino Nano Fried on Music Reactive Led Strip

texts:
I'm doing a project that involves an Arduino Nano, a sound detection microphone module and a RGB Led strip (individually adressable leds). I also bought an accumulator so I can connect everything straight to the outlet.

The problem is that on 12V this accumulator cannot power the led strip at all and when I connected it to the laptop the Nano micro USB fried after I did about 4 tests.

My question is why can't the accumulator power everything and why the Nano got fried from the laptop which should have even less power? Would an Arduino Mega solve the problem or is it something about the wiring? (the wiring was checked by someone with experience)


texts: "write" function in sd card is not working

texts:
I have recently started working with arduino UNO and the "write" function in sd Card library is not working. Below is my code. I have tried with "println" which is working fine. Any help regarding this is welcome.

void loop()
{
     byte b=10;
     File dataFile = SD.open("datalog.txt", FILE_WRITE);
    if (dataFile)
    {
        dataFile.write(b);
     }
}


texts: Multiple Buttons on Single Analog Pin and Trigger Pin Arduino Uno

texts:
I've researched how to attach multiple buttons to a single analog input using a resistor network. Instructables has a good lesson on this: http://www.instructables.com/id/How-to-access-5-buttons-through-1-Arduino-input/?ALLSTEPS

My requirement is that I need to attach an interrupt to buttons (ie the analog input) before reading the analog value, so that all the buttons can act as a trigger.

This works for voltages in the higher range, but not in the lower range (the trigger input waits for a RISING edge).

Can any one suggest a circuit that steps a >0V+ to +5V input to a +5V output so that any button push would trigger the input?

Otherwise, does anyone have other suggestions on how to use triggers for each button?


texts: How to set address for using more than MPU9250

texts: I am trying to build a project that contains more than one MPU 9250, until now I'm still confused to MPU9250. If I were going to that, does anybody here know how to set addresses to each of the MPU's I am going to use? Thank you for spending time reading my question. I hope someone will help me get through this.


texts: Preforming impedance termination for UART Communication (TX and RX) pins

texts:
I need two Arduino devices (Arduino Mega and Nano) to communicate with each other via UART. The two Arduino devices are long distance apart from each other. The distance is 1.5 meters.

The Arduino 1 TX pin is connected to Arduino 2 RX pin.
The Arduino 1 RX pin is connected to Arduino 2 TX pin.

Now, I have to use resistor to preform impedance termination so that the long distance does not cause transmitting and receiving issues between the two devices. I did some research and found an  image that shows the signal differences when impedance termination is preformed and when it is not.

I have two questions:

1. Since the distance between both Arduino devices is 1.5 meters, what resistor value should I use? How is that calculated?

2. Where do you put the resistors? It's not really clear on where to connect the resistors. Between ground and the RX pins on each device?

I don't know the gauge ratings of my wire but if that information is needed, I am using this wire.


texts: A1-A5 pins not declared in this scope error

texts:
When I set my board to 'Generic ESP8266 module'  then only A0 pin of arduino is working while all other analog  pins are coming out of scope ,
 when I set the board to 'arduino /genuino uno' ,
 then "Error compiling for board Arduino/Genuino Uno." this error is coming how to set the board such that all analog pins with ESP8266 will work?


texts:
I have a system where an Arduino controls a DSLR camera for environmental monitoring. The Arduino can power on/off the camera and control the shutter (through the standard plug for a external shutter). The Arduino record and transmit the status of the system (battery voltaje, time of the last shot, etc.).
I want the Arduino to be able to access the camera's SD card while the camera is powered off. In order to check if the pictures were actually taken and check available memory (I don't need to write to the card).
So my questions are:

If I create a contraption to connect a single card to the camera and the arduino. The fact that the card is connected to one device (although not been used) will interfere in the operation of the other?
Should I consider the use of a multiplexer or something alike to completely disconnect the data lines from one device while the other is using the card?


texts: Can anyone tell me about the onboard accelerometer of LightBlue Bean?

texts: I would like to know the specs of the accelerometer used on a LightBlue Bean before buying one, but I couldn't find any info online. Anybody has an idea?


texts:
How would you go about checking if an input pin has been set using the entire bank? I am thinking that I need to use bit twiddling with a bit mask but I have not used this enough to figure out how to do what I want.

Basically I have the following code:

void setup() {
   DDRA = 0x00;
   PORTA = 0xff;
}

void loop(){
   //Check if any pin from Port A has been pressed
   if (PINA & 0xff){
      //do stuff
   }
}

But the code above is not working how I expected it to. Has anyone tried to use this approach before? Am I going about this the wrong way? I figured since I was using all 8 pins from one bank, it would be better to check if any of the pins on that bank have been set instead of checking each individual pin. My thinking on this was to prevent any user input from being skipped in case a button press was initiated while the program was running other code. This way I only check if anything in the bank has been set saving time (I think).


texts:
I need some help with my proyect. I want send some data to an AFD Yaskawa V1000. I have the bytes test and I send it but I cant comunicate with it. The AFD just show an 'CALL' error, means dont have connection. We have many AFD connected to a PLC Omron and the 'CALL' is an error of comunication.
AFD Config:
ID: 3
BaudRate: 19200
Parity: none

#define SerialControlPin 3
#define RS485Transmit HIGH
#define RS485Receive LOW

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

  pinMode(SerialControlPin, OUTPUT);
  digitalWrite(SerialControlPin, RS485Receive);
  Serial1.begin(19200);
  delay(2000);
}
void loop()
{
  digitalWrite(SerialControlPin, RS485Transmit);

  byte request[] = {0x03, 0x08, 0x00, 0x00, 0xA5, 0x37, 0xDA, 0x8D};   // Test loop code
  //byte request[] = {0x03, 0x10, 0x00, 0x01, 0x00, 0x02, 0x04, 0x00, 0x01, 0x02, 0x58, 0x63, 0x39};    // Change to 60Hz and turn on
  Serial1.write(request, sizeof(request));

  digitalWrite(SerialControlPin, RS485Receive);
  delay(10);

  while(Serial1.available())
  {
    Serial.print(Serial1.read(), HEX);
    Serial.print(" ");
  }

  Serial.println();

  delay(500);
}

Thanks and sorry for my english. Also, this is my first post.


texts: How do I set the motor state to "HIGH" at the beginning of this sketch?

texts:
My intent with this sketch is to have motors run for one minute, then stand by for 18 minutes. In practice, the sketch starts the motor state at "low" for the OffTime interval, then goes to the OnTime interval and loops. The desired result is exactly the opposite: the "high" interval first, followed by the "low". I have tried setting the motorState to "HIGH" in the constructor and played with the order of the IF statements to no avail.

I would appreciate any insight into this problem, as well as an intuition for the practical use of millis(). I need a solution which doesn't use delay but am having trouble wrapping my head around the logic of millis() as used. (I adapted this code from a tutorial.)

class LifeTest
{
  // Class member variables initialized at startup
  int motorPin;
  long OnTime;
  long OffTime;
  // These maintain the current state
  int motorState;                               // Used to set the motor.
  unsigned long previousMillis;                 // Stores last time motor was updated.

  public:
  LifeTest(int pin, long on, long off)
  {
    motorPin = pin;
    pinMode(motorPin, OUTPUT);

    OnTime = on;
    OffTime = off;

    motorState = LOW;
    previousMillis = 0;
  }

  void Update()
  {
    unsigned long currentMillis = millis();     // Check to see if it's time to change the motor state.
    if((motorState == HIGH) && (currentMillis - previousMillis >= OnTime))
    {
    motorState = LOW;                         // Turn off motor.
    previousMillis = currentMillis;           // Remember the time.
    digitalWrite(motorPin, motorState);       // Update the motors.
    }
    else if((motorState == LOW) && (currentMillis - previousMillis >= OffTime))
    {
    motorState = HIGH;                        // Turn on motor.
    previousMillis = currentMillis;           // Remember the time.
    digitalWrite(motorPin, motorState);       // Update the motors.
    }
  }
};

LifeTest motor1(50, 60000, 1080000);
LifeTest motor2(51, 60000, 1080000);
LifeTest motor3(52, 60000, 1080000);
LifeTest motor4(53, 60000, 1080000);

void setup()
{
}

void loop()
{
  motor1.Update();
  motor2.Update();
  motor3.Update();
  motor4.Update();
}


texts: Differing Serial Values Between Arduino Uno and TTGO ESP32 SX1276

texts:
I'm wanting to analogRead the value off a MQ-135 gas sensor. I have tired this with both an Arduino Uno and an TTGO ESP32 SX1276.

When reading the value of the sensor off the Uno, I get values approximately equal to 400 which is expected, as shown in this video. When doing the same on the TTGO, I get values close to 2000. For some reason, this person gets a similar value range as shown in this video.

What I don't understand is how these values are different when only the board is being changed. Do different boards analogRead differently?

More or less, how do I get the TTGO to read the same values as the Uno?

Below is my code for both boards. Nothing is changed between the boards:

#define sensor 2 //sensor pin

int gasLevel = 0; //int variable for gas level

void setup() {
  Serial.begin(9600); //start serial comms
  pinMode(sensor,INPUT); //set sensor for input
}

void loop() {
  gasLevel = analogRead(sensor);
  Serial.println(gasLevel);
  delay(1000);
}

The following things I have tested:

Multiple boards of both the Arduino Uno and TTGO
Different pins, both analog and digital

I also am powering the sensor using 3.3V pin, so there is no variation in the voltage the sensor is receiving.


texts:
I'm using my HC-05 (Master) to receive strings from a sensor (Slave), each string is suppose to have 7 items divided by ',' like so "a,b,c,d,e,f,g". I also have to write these strings in a .txt file in the SD card, being that I receive the strings and save them in a string array to later be written to a file. For some reason I can't receive it and write it to a file simultaneously, it alters the string. So the best way would be an array but when i open the file it's blank and when I print it on screen it starts correctly then prints only the first char of what would be the string. I tried it with 80 strings and it works correctly, so I can only guess it would be insufficient memory, But wouldn't it still write to the file since there is something in the strings.

PS:I'm using Arduino Mega

#include <SD.h>

const int tam=480;
char aux;
File myFile;

void setup() {
  Serial1.begin(115200);
  Serial.begin(115200);
  Capture();
}

void openSD()
{
  SD.begin(4);
  if( SD.exists("test.txt") )
  {
    Serial.println("O arquivo de amostras sera removido");
    SD.remove("test.txt");
      if( !SD.exists("test.txt") )
        Serial.println("Arquivo removido com sucesso!");
  }
  myFile = SD.open("test.txt", FILE_WRITE);
}

void Capture()
{
  String test[tam];
  openSD();
  Serial.println("BEGIN");
  for(int i=0;i<tam;i++)
  {
    test[i]="";
    do
    {
      while(!Serial1.available());
      aux=Serial1.read();
      test[i]+=aux;
      Serial.print(aux);
    }while(aux!='\n');
  }
  Serial.println("END");
  for(int i=0;i<tam;i++)
    myFile.print(test[i]);
  myFile.close();
}

void loop() {

}


texts: Arduino Nano 33 IoT not connecting to WiFi

texts: I have been using my Nano 33 IoT for a while now and it has been behaving perfectly. All of a sudden though, I just cannot connect to WiFi. I am using the WiFi Nina library. Everything is updated to the latest version(Wifi Nina to 1.7.1 and the Wifi Nina firmware to 1.3.0). I have also tried older versions with no prevail. Any help is appreciated.


texts: ESP8266 NODEMCU V3, HOW TO USE AND CONTROL V3 OUTPUT POWER

texts:
this is my very first post in here so I apologise if I am not giving you all the information that I should.

I am creating this topic to ask you help regarding how to control and use the v3 output of my Nodemcu.

I have a script which is working fine to power on and off a led by using one of the GPIO and the ground. However, my project requires to power on a small motor for about 2 seconds and then stop it. If I connect this motor to one of the GPIO and the ground I can control it but it runs very slow. If I connect the motor to the 3V output it goes fine but I can't turn it on or off. The motor requires 3V to run properly. How can I turn it on and off by powering it from that 3V output?

What am I missing?

I have a 4n25 chip which I saw in a video that has been used for a similar project however the vide is in Portuguese and I am not able to follow it properly.

Can please someone advice?

Thank you for your time,

Ade


texts: Not Able to get INPUT_PULLUP pinmodes to work on multiple pins

texts:
I am working with an Arduino nano, and ic2 128x32 OLED display and a 1x4 membrane keypad. Problem is that only one of the 4 pins are detecting the button press. it's not the Arduino, I already was able to reproduce the same issue on another one. the keypad is also working fine, as I have tested it. (edit now only pin 9 is working)

#define b1 6
#define b2 7
#define b3 8
#define b4 9

// in setup

pinMode(b1, INPUT_PULLUP);
pinMode(b2, INPUT_PULLUP);
pinMode(b3, INPUT_PULLUP);
pinMode(b4, INPUT_PULLUP);

// in loop

int b1S = digitalRead(b1);
  int b2S = digitalRead(b2);
  int b3S = digitalRead(b3);
  int b4S = digitalRead(b4);

  if(!b1S){
    Serial.println("Button 1");
    }

  if(!b2S){
    Serial.println("Button 2");
    }

  if(!b3S){
    Serial.println("Button 3");
    }

  if(!b4S){
    Serial.println("Button 4");
    }

Please help! Thanks


texts: Reading three signals sent serially on Simulink from Arduino

texts:
I am sending three signals from one Arduino mega to another using xbees. On the receiving end I am using these signals in a Simulink code to control servo motors. Currently it is set up to read from analog pins without the wireless set up. With the wireless technology the signals are all being sent and received through one serial port. I believe I would need to change the inputs in Simulink to a serial receive block instead of an analog pin block. The problem is the documentation for the serial receive block says you can not assign more than one serial receive block to the same serial port. If anyone has a solution to this it would be greatly appreciated!

receiving code

int received1;
int received2;
int received3;
void setup() {
  Serial.begin(9600);
}
void loop() {
  if(Serial.available() )
  {
    received1, received2, received3 = Serial.read();
  }
}

transmitting code:

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

void loop() {
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);
  int sensorValue3 = analogRead(A2);
  Serial.write(sensorValue1, sensorValue2, sensorValue3);
  delay(1);
}


texts: When and where do I have to worry about accounting for sensor "noise"?

texts:
I just watched this excellent video tutorial that shows a simple Arduino program that toggles an LED via a pushbutton. Very cool!

Being brand new to electronics/robotics, I was shocked that something as simple as a pushbutton required his debounce behavior. That's something I would have never thought about in a million years. What is the 'rule of thumb' for when this type of debounce behavior (regardless of what sensor we're talking about, pushbutton or otherwise) must be accounted for? Is it simply that any type of analog sensor can generate this kind of unexpected 'noise'?

Can someone provide other examples for when special code must be put in place to accommodate unexpected sensor noise?


texts: DS3231 rtc.begin() always returning false

texts:
I am using Arduino UNO with a RTC DS3231 module.
I have connected SDA & SCL pins of RTC DS3231 with Arduino SDA & SCL pins near AREF pin.
RTC module is having attached battery also.
My code is as below :
#include <RTClib.h>
#include <Wire.h>
RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {
  "Sunday", "Monday", "Tuesday",
  "Wednesday", "Thursday", "Friday", "Saturday"
};

void setup() {
  Serial.begin(9600);
  Wire.begin();
  delay(3000);
  //rtc.begin();
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
       // Following line sets the RTC with an explicit date & time
    // for example to set January 27 2017 at 12:56 you would call:
    // rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
  }
}

void loop() {
  DateTime now = rtc.now();
  Serial.println("Current Date & Time: ");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    Serial.println("Unix Time: ");
    Serial.print("elapsed ");
    Serial.print(now.unixtime());
    Serial.print(" seconds/");
    Serial.print(now.unixtime() / 86400L);
    Serial.println(" days since 1/1/1970");

    // calculate a date which is 7 days & 30 seconds into the future
    DateTime future (now + TimeSpan(7,0,0,30));

    Serial.println("Future Date & Time (Now + 7days & 30s): ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();

    Serial.println();
    delay(1000);

}

While running the above command and opening the Serial Monitor, I always get following output:
Couldn't find RTC

Can anyone help me to correct this problem.


texts: PROGMEM : pgm_read_float_near() equivalent for double? (Arduino Due)

texts: I'm using an Arduino Due where double have a size of 8 bytes. In my software, I use double table const stored in prog memory, I was using an UNO before and used pgm_read_float_near() to retreive these values. What function should I use ?


texts:
I'm working on a simple ADC project, the goal is to adjust the on/off of the LEDs according to the binary reading (1-on,0-off). I've tried this with 8 bit, and it works as intended. But on 10 bit, two of the LEDs with representation of 2^8 and 2^9 won't turn on even though the reading on the serial monitor is 1023 (should be 1111111111 -all LEDs on). I wonder if there's anything wrong with my code or circuit?
(I'm totally new to arduino, sorry for the noobness)
-I'm using Arduino UNO R3, the details are shown in the image
void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);

  Serial.begin(9600);
}

void loop(){
  int sensorValue = analogRead(A0);
  Serial.print("Decimal=");
  Serial.print(sensorValue);
  Serial.print("\tBinary=");
  Serial.println(sensorValue,BIN);

  if(sensorValue>=0&&sensorValue<=1023){
    digitalWrite(4,(sensorValue&1));
    digitalWrite(5,(sensorValue&2));
    digitalWrite(6,(sensorValue&4));
    digitalWrite(7,(sensorValue&8));
    digitalWrite(8,(sensorValue&16));
    digitalWrite(9,(sensorValue&32));
    digitalWrite(10,(sensorValue&64));
    digitalWrite(11,(sensorValue&128));
    digitalWrite(12,(sensorValue&256));
    digitalWrite(13,(sensorValue&512));
  }
  delay(20);
}


texts: Generating PWM using Arduino Uno and Simulink (interfacing) pins 5 and 6. What's the maximum frequency?

texts: I am building a boost converter using a mosfet. The mosfet is driven by PWM generated by an Arduino Uno through Matlab Simulink. In Simulink I am giving 10 KHz pulse width 50%. Practically 10 KHz available at pins 5 and 6. Up to how much frequency can pins 5 and 6 handle?


texts:
I am interfacing a GSM modem via Arduino at Serial port 2.

I have seen that responses fron GSM modem are subject to time. Sometime its response are fast and sometime it are slow. I  have a code like below which checks for response from GSM modem based upon a user configurable timeout value:

sendATcommand(str_at_cmd, str_ok, 500);

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout)
{
    uint8_t x=0;
    char response[100];
    unsigned long previous;
    int answer = 0;
    memset(response, '\0', 100);
    answer = 0;;
    delay(100);
    ClearSerialData(); // read and flush all data
    debug_println(ATcommand);
    Serial2.println(ATcommand);
    delay(200);
    x = 0;
    previous = millis();
    do {
       if(Serial2.available() > 0){
       response[x] = Serial2.read();
       delay(100);
       debug_print(response[x]);
       response[++x] = '\0';
       if (strstr(response, expected_answer) != NULL)
       {
           debug_print("\nAnswer Mathced");
           answer = 1;
       }
       }
    }while((answer == 0) && ((millis() - previous) < timeout));
    debug_println("\nReturning from AT Command");
    return answer;
}

I was never able to set the correct timeout value - as at random test it failed once or twice and not received 100% success.

My question if I change the code like below

while(Serial2.available() > 0){
   response[x] = Serial2.read();
   delay(100);
   debug_print(response[x]);
   response[++x] = '\0';
   if (strstr(response, expected_answer) != NULL)
   {
       debug_print("\nAnswer Mathced");
       answer = 1;
   }
}

So when does Serial2.available() method returns <= 0 value. Is my above code correct - this way I overcome the timeout issue and all my GSM responses are being read - are there scenarios that I will end up in infinite loop?


texts: Connection of serial pin on ATMEGA328P to connector B type(female) D+ and D-

texts:
Now I am using ATMEGA328P and want to communicate with computer in serial using B connector female (also want to provide power from computer to ATMEGA328P using B connector).

So here is my question. How can I connect D+ and D- to ATMEGA328P's pin No. 2 (PD0/RX) and pin No. 3 (PD1/TX)? In other words which pin should I connect to D+ and D- ? Also is it possible to connect them directly?

Thank you in advance.


texts: I²C only works when I short-circuit my Arduino

texts:
I'm trying to connect an Arduino Nano with a Raspberry Pi 3 via I²C.

This is the small test-program I found and used for I²C.

#include <Arduino.h>
#include <Wire.h>

void setup() {
  Wire.begin(4);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop() {
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

After compiling and uploading, I ssh-ed into my Pi and executed sudo i2cdetect -y 1 which prints an empty I²C table.

Here are images of how I connected the two devices, as far as I know the connection itself is okay. I also tested the cables with a multimeter.

Now the strange thing is, when I short-circuit my Arduino for a brief moment between GND and VIN I²C works, but Serial via USB with my PC stops working. Also the chip gets very hot and stays hot even though it isn't short-circuited anymore.

Any ideas what I'm doing wrong? I don't think the Arduinos are broken, since I tested it with 2 different ones. (while testing I accidentally short-circuited one and it worked)

EDIT: I tested I²C between the two Arduinos and it works flawlessly, but still doesn't want to work with my Pi. :(


texts:
I have this code

#include <Ticker.h>  //Ticker Library
Ticker blinker;
/* ... */

//blinker.attach(1, []() { digitalWrite(LED,!digitalRead(LED)); }
while(!client.connect(laptop,port)) {
   Serial.println("Connecting...");
   delay(1000);
}

Which works fine, tries connecting, then eventually connects.

If I uncomment the line attaching to this 'blinker' Ticker, then I get a crash right after the first 'Connecting...' print. When I look at the stack trace, it mentions that the crash happens during the delay(1000) in my while loop (which is presumably the moment when the program yields and the blinker can do some work)

Is there anything I can do to make this timer work better?


texts: Arduino is freezing during Serial.Print() while passing a char array

texts:
This problem is on an Arduino Due.
I am trying to populate a char array buffer that is receiving information over a serial port. I am reading the information off of the serial port and storing it into a buffer array and passing it back to the original function call.

First is the code that initializes the buffer and writes the data that the Serial requires in order to issue a response. This function compares many types of expected responses (uint32_t expect) and returns a confirmation as an int.

//Receive a cmd to send over serial and expect a certain response
int SendCommand(char * cmd, uint32_t expect){
  int cmdSuccess = 0, j=0;
  char buffer[500];
  memset(&buffer,0,sizeof(buffer)); //0 out the buffer
  Serial3.print(F(cmd));
  delay(500);

  Response(buffer);

  if (expect == EXPECT_OK){
    for(int i=0;i<sizeof(RESP_OK);i++){
      if(buffer[i]==RESP_OK[i]){ //RESP_OK is an example of a response of length 6
        j++;
    }
  }
    if(j==sizeof(expect)-1){Serial.print(F("\nGOOD RESPONSE!\n")); return 1;}
  }
  else{return 0;}
  delete [] buffer;
}

void Response(char buffer[500])
{
  int index = 0; //message index;
  int count = 0; //used for timeouts
  while(1)
  {
  if(Serial3.available()) //Data will be coming across serial3
  {
    char data = Serial3.read();
    buffer[index]=data;
    index++;
  }
    count++;
    delay(100);
    if(count == 50){
    Serial.println(F("\nEnd of Response"));
    break;
  }

}

Edit: fixed the braces.

Right now, this code is hanging at the last part of Response right before break;. Am I having memory issues by the time it reaches the println at the end?
That last println was actually working until I began passing the buffer as a pointer and not returning it a char* and declaring void Response as char* Response. But the problem with this approach was that the buffer would reduce to sizeof(buffer) = 4 and would strip off the rest of the information when returned.

Edit: As Matt suggested down below, I declared a static const size_t bufferSize and pass it into the Response() call as well as passing in buffer as char*. Then I reset the buffer size by buffer = (char*)malloc(bufferSize).

What I still don't understand curious is the sizeof(buffer) after Response which is returning 4. However, 6 characters are stored into the array during Response. I've changed the pointer call to Response(char* buffer, const int size) with the following:

  if(index<size){
  buffer[index]=data;
  index++;
  }
  else{Serial.print(F("Buffer length exceeded!"));}

Thanks so much for your time!


texts: Connecting a motor to Arduino UNO Play breadboard

texts:
I am new to Arduino and have a small query. I am building a simple system that switches on a motor and switches it off after some time and repeats this in a loop.

The Arduino that I am using is a “DIY UNO Play Breadboard -ATMEGA328P with FT232 Breakout Board” (Rs. 825, or $12.38USD, from Mangalore).  The Arduino board is similar in size to a Nano but without USB.  The FT232 board has a USB B port on one end and serial pins on the other.

My query is whether I should connect the positive end of battery supply to the motor and then connect in series using a motor controller circuit to port 7 and connect the negative terminal to the gnd port.

Or do I need a separate voltage source for my Arduino, because this Arduino has no built in USB ports.

This is my code to switch on and switch off the motor:

int motorPin = 7;
   pinmode(motorPin,OUTPUT);
   digitalWrite(motorPin,HIGH); //turn motor on
   delay(500); //wait
   digitalWrite(motorPin,LOW); //turn motor off
   delay(500); //wait


texts: Atmega328 PWM frequency setting not working

texts:
I have an Arduino UNO with Atmega 328 SMD, and I am trying to use PWM, but by setting registers, not using analogWrite(). My code is:

DDRD |= (1 << PORTD6); //Setting pin D6 as output
OCR0A = 128; //50% duty cycle
TCCR0A |= (1 << COM0A1)|(1 << WGM01)|(1 << WGM00); //setting mode and fast pwm
TCCR0B |= (1 << CS01); //setting the prescaler to 8, which should yield PWM with frequency of 8 kHz

The problem is with the last line. No matter what I do, it results in PWM with frequency of 1 kHz. Setting different prescaler bits just yield 1 kHz PWM again. I was thinking that maybe its because I am programming this in Arduino IDE, and I kHz is Arduinos default frequency?
Or where am I making the mistake? Thanks for any answers.


texts:
I am new to Arduino programming and I would like to ask a question.

Firstly apologies if this has been answered before and I understand if it gets locked if this has been answered elsewhere.

I am trying to get three LED's (red, amber, green) to loop 5 times (in a do loop).

for this I have created a integer variable (x) and initialised the variable to 0.

I then increase x by 1 each time.

However I cannot get them to stop looping when x is greater than 5. The program does work as expected for everything else (green LED lit, wait 1 sec, Yellow LED lit, wait 1 sec, red LED lit and then loop).

   //set LED pins
int greenPin = 13;
int yellowPin = 12;
int redPin = 11;

void setup()
{
  pinMode(greenPin, OUTPUT);      // sets the digital pin as output
  pinMode(yellowPin, OUTPUT);
  pinMode(redPin, OUTPUT);
}

void loop(){
int x = 0;

 do {
  digitalWrite(greenPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(greenPin, LOW);
  digitalWrite(yellowPin, HIGH);    // sets the LED off
  delay(1000);
  digitalWrite(yellowPin, LOW);// waits for a second
  digitalWrite(redPin, HIGH);    // sets the LED off
  delay(1000);
  digitalWrite(redPin, LOW);
 }
   while(x<=5); {
    x = x + 1;
   }
}