texts: The Ethernet Shield Unable to Establish Full Duplex Communication

texts:
I am using Arduino Uno R3 board with Atmega 328p microcontroller along with an ethernet shield for showing tempererature over a network. However i am facing a problem that the FULLD(full duplex for communication) led on the ethernet shield is not solid. Hence I am unable to access the provided IP in my web browser. Apart from that when I directly connect it to my PC, the same thing happens. The FULLD led keeps blinking and i am unable to establish a solid contact. My code goes here:

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONEWIRE 7
#define SENSOR_READ_TIMEOUT 8000

OneWire oneWire(ONEWIRE);
DallasTemperature sensors(&oneWire);
EthernetClient client;
EthernetServer server(8080);

byte mac[] = {
  0xF0, 0xBF, 0x97, 0x67, 0xF6, 0x98
};
IPAddress ip(192, 168, 43, 94);

void setup() {
    Serial.begin(9600);
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);
    Serial.println("Boot");
    sensors.begin();
    delay(1000);
    Serial.print("OneWire Digital Pin Specified: ");
    Serial.println(ONEWIRE);
    Ethernet.begin(mac,ip);
    server.begin();
    delay(3000);

}

 void loop() {
   static unsigned long sensorPrevTime = 0;
   server.begin();
   EthernetClient client = server.available();
   Serial.print(".");
   sensors.requestTemperatures();
   float tempC1 = sensors.getTempCByIndex(0);
   float tempC2 = sensors.getTempCByIndex(1);
   if (millis() - sensorPrevTime > SENSOR_READ_TIMEOUT) {
   Serial.println();
   Serial.println("Requesting temperature...");
   Serial.print("Sensor 2:    ");
   Serial.print(tempC1);
   Serial.println(" C ..........DONE");
   Serial.print("Sensor 1:    ");
   Serial.print(tempC2);
   Serial.println(" C ..........DONE");
   if (client) {
   Serial.println("new client");
   boolean currentLineIsBlank = true;
   while (client.connected()) {
      if (client.available()) {
      char c = client.read();
      Serial.write(c);
      if (c == '\n' && currentLineIsBlank) {
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println("Connection: close");
        client.println("Refresh: 2");
        client.println();
        client.println("<!DOCTYPE HTML>");
        client.println("");
        client.print("Temperature for Requested Area is: ");
        client.print(tempC1);
        client.print(" C ");
        client.println("
");
        client.print("Reference Temperature is: ");
        client.print(tempC2);
        client.print(" C ");
        client.println("
");
        client.println("");
        break;
      }
      if (c == '\n') {
        // you're starting a new line
        currentLineIsBlank = true;
      }
      else if (c != '\r') {
        // you've gotten a character on the current line
        currentLineIsBlank = false;
      }
    }
  }
  delay(1);
  client.stop();
  Serial.println("client disconnected");
 }
 sensorPrevTime = millis();
}

delay(1000); //slow down loop
}


texts: What is the rise time of an output pin of atmega328 changing its state?

texts: I've already searched a lot and didn't found the answer. Also, I don't have an o'scope. Anyone can help me?


texts:
I was coding a class for "a kind of gun". I have this code for the classes:
Gun.h:

#ifndef Gun_h
#define Gun_h

#include "Arduino.h"

class Gun
{
  public:
    Gun(String identifier, String name, int teamIRCodes[]);
    String getIdentifier();
    String getName();
    int getIRCode();
  private:
    String _identifier;
    String _name;
    int _teamIRCodes[];
};

#endif

Gun.cpp:

#include "Arduino.h"
#include "Gun.h"

Gun::Gun(String identifier, String name, int teamIRCodes[])
{
  _identifier = identifier;
  _name = name;
  _teamIRCodes = teamIRCodes;
}

String Gun::getIdentifier(){
  return _identifier;
}
String Gun::getName(){
  return _name;
}
int Gun::getIRCode(){
  return _teamIRCodes[1];
}

It returns me this error while compiling:

sketch\Gun.cpp: In constructor 'Gun::Gun(String, String, int*)':

Gun.cpp:8: error: incompatible types in assignment of 'int*' to 'int [0]'

   _teamIRCodes = teamIRCodes;

                ^

exit status 1
incompatible types in assignment of 'int*' to 'int [0]'


texts: After uploading the code, can I connect a UART peripheral's RX, TX to TX, RX (D0 ,D1) and use the serial monitor of the arduino together ? Will data reception from the peripheral properly work in this case, or will it conflict with the serial monitor ?


texts: Can I force Arduino not to be powered by USB?

texts:
I'm building a 3D printer and I'm using an ATmega2560 + RAMPS board.

The whole thing is powered by an ATX PSU (12v for motors and stuff, 5v for the Arduino), but when I plug in my USB cable, I can't shut the printer down, as it switches over to USB power.

Is there a way to make the Arduino never use the USB power, only the external power source?

Thanks!


texts: freeMemory() function from memoryfree library not returning decreased value in arduino UNO

texts:
I burned the code written below, I expect that as we declare the local variable in the loop, freeMemory() function should return decreased value. But it remains constant..! please explain why..?  The output is attached :

#include <MemoryFree.h>
void setup()
{
  // put your setup code here, to run once:

  Serial.begin(9600); Serial.println(freeMemory(), DEC);  // print how much RAM is available.
  Serial.println("Lets Start");
}
void jack();
void loop()
{
    char c=0;
    c++;
    Serial.println("");
    Serial.println("Rajat0");
    Serial.println(freeMemory(), DEC);
    Serial.println("Rajat1");
    int x=0;
    x++;
    Serial.println("Rajat2");
    Serial.println(freeMemory(), DEC);
    Serial.println("Rajat3");
    jack();
    Serial.println("");
    delay(1000);
}
void jack()
{
    Serial.println("jack0");
    int x=0;
    x++;
    Serial.println(freeMemory(), DEC);
    Serial.println("jack1");
}


texts: Need library help for Arduino USB host shield

texts:
Recently Purchased a "TOOGOO(R) T45 USB Host Shield" from Amazon. I attempted to use the "USB Host Shield Library" from Github, but It seems like it might not support this particular shield.

I would really like to learn how to use this shield to interact with my joystick but the only tutorial information I have found to help me with this is from Circuits@home and they seem to be using a specific shield in their development of the code library.

Can anyone point me to a tutorial or Github library that can help me learn to work with this setup?

I'm using an Arduino Uno and a Thrustmaster USB joystick.

Thanks in advance.

UPDATE*

I fixed the initial problem of accessing the HIDDESC report. I now have the report, but the formatting of the report is particularly hard to understand. Using the Circuits@home articles I'm a little lost on how to read the report data I was given. It does not seem to be formatted in the same way as the example. Can anyone help with interpreting my device report?

  Start
  0000: 05 01 09 04 A1 01 09 01 A1 00 09 30 09 31 09 32
  0010: 09 BB 15 80 25 7F 46 FF 00 66 00 00 66 00 00 75
  0020: 08 95 04 81 02 C0 09 39 15 01 25 08 35 00 46 3B
  0030: 01 65 14 75 04 95 01 81 02 05 09 19 01 29 04 15
  0040: 00 25 01 75 01 95 04 81 02 95 08 81 01 05 08 09
  0050: 43 15 00 26 FF 00 35 00 46 FF 00 75 08 95 04 91
  0060: 82 55 00 65 00 55 00 65 00 55 00 C0
  Usage Page Gen Desktop Ctrls(01)
  Usage Game Pad
  Collection Application
  Usage Pointer
  Collection Physical
  Usage X
  Usage Y
  Usage Z
  Usage Undef
  Logical Min(80)
  Logical Max(7F)
  Physical Max(FF00)
  Unit(0000)
  Unit(0000)
  Report Size(08)
  Report Count(04)
  Input(00000010)
  End Collection
  Usage Hat Switch
  Logical Min(01)
  Logical Max(08)
  Physical Min(00)
  Physical Max(3B01)
  Unit(14)
  Report Size(04)
  Report Count(01)
  Input(00000010)
  Usage Page Button(09)
  Usage Min(01)
  Usage Max(04)
  Logical Min(00)
  Logical Max(01)
  Report Size(01)
  Report Count(04)
  Input(00000010)
  Report Count(08)
  Input(00000001)
  Usage Page LEDs(08)
  Usage Slow Blk On Time
  Logical Min(00)
  Logical Max(FF00)
  Physical Min(00)
  Physical Max(FF00)
  Report Size(08)
  Report Count(04)
  Output(10000010)
  Unit Exp(00)
  Unit(00)
  Unit Exp(00)
  Unit(00)
  Unit Exp(00)
  End Collection Game Pad Pointer X Y Z Undef(00)(00)(7F)(00)
  Hat Switch(00)
  Btn0001
  (00) Btn0002
  (00) Btn0003
  (00) Btn0004
  (00)
  (00)(00)(00)(00)(00)(00)(00)(00)
  Slow Blk On Time


texts: Reliably using analogRead as a compact digitalRead

texts:
My goal is to reduce pins being used for micro-controllers with limited pins, or projects requiring a few different digital input values.
How I intend to do so is by using ADC pins to gather four specific different values through resistors with analogRead, which would otherwise need 2 pins (!A+!B, !A+B, A+!B, and A+B).
value = analogRead(adcPin1) >> 8;

This would give, if properly wired, 4 possible results like some sort of "Quartary bit", as analogRead yields a 10-bit response.
So my questions are the following:

Can analogRead be sufficiently reliable to tell the difference between four possible values?
What would the wiring/casing/etc. need to look like to prevent any errors?

Thanks!


texts: Serial Communication Not Receiving Entire String

texts:
I have an Arduino connected to a pico motor driver that is supposed to take a number of steps for a specific number of triggers that gets from a source (i.e. waveform generator). I've setup the code so that it would ask the user to input number of steps and number of triggers. For example, if I want the motor to take 10 steps once it got 60 triggers, I should input s10; and t60; separately into Serial Monitor.

In addition, I want to be able to change the number of steps and triggers any time that I want. However the problem is that sometimes Arduino doesn't receive the input string entirely for the first time. Sometimes it works on the second try. Or even not at all. I really appreciate if someone can give a hint on why this is happening.

This is a simple version of the code (without the parts that move the motor):

#include<String.h>

long int steps;
long int num_triggers;
long int newtrigger;
long int newstep;
long int oldtrigger;
long int oldstep;

const int main_control = 0;
int triggers_count;
bool motor_trigger = true;

void setup() {

 Serial.begin(19200);
 Serial.println("Please enter chosen number of steps and triggers.");
 Serial.println("Example: \n If you want the pico-motor to take 10 steps per 40 triggers,");
 Serial.println(" write 's10;' and press enter then do the same for 't45;'(Order doesn't matter).");
}

void loop() {

  while (num_triggers == 0 || steps == 0) {

    getcommand(&steps, &num_triggers);

  }

  attachInterrupt(main_control, trigger, RISING);  // it starts looking for trigger

  if (motor_trigger == false) {

    getcommand(&steps, &num_triggers);
  }

  else if (motor_trigger == true) {

    motor_trigger = false;
    detachInterrupt(main_control);

    if (triggers_count <= (num_triggers - 1)) {

      getcommand(&steps, &num_triggers);

    }

    else {

      for (int i = 0; i < steps; i++) {

        oldstep = steps;
        oldtrigger = num_triggers;
        getcommand(&steps, &num_triggers);

        if (  num_triggers != oldtrigger || steps != oldstep) {
          break;
        }
      }
    }
  }
}

void trigger(void) {

  motor_trigger = true;
  triggers_count++;
}

void getcommand (long int *newstep, long int *newtrigger) {

    char   char_input;
    String string_input;
    String output_1;
    String output_2;

  while (Serial.available()) {

    char_input = Serial.read();
      if (char_input == ';'){
    Serial.println("done");

      }
      else{
    string_input += char_input;
    delay(500);
    }
  }

  Serial.println("Getting input...");
  Serial.println(string_input);
  Serial.println("Input printed.");

  int inputlen = string_input.length();
  output_1 = string_input[0];

    for ( int i = 1; i < inputlen; i++ ) {
      output_2 += string_input[i];
    }

      if ( output_2.toInt()<=0 && inputlen>0 ){   // check if there's an error

        Serial.println("Error with input number");
        delay(5000);
        Serial.println("Reading the input string");
        Serial.println(Serial.readString());
        Serial.println("Done reading the input string");
        }

    if (output_1 == "s") {

      *newstep = output_2.toInt();

    }

    else if (output_1 == "t") {

      *newtrigger = output_2.toInt();
    }

  }


texts:
I am working on a project involving 14 sections of EL tape. This is a circular array that incorporates a chaser effect with two lights lit on either side. originally I had found a small diy LED sequencer board that controlled both speed and brightness from 2 POTs.

Now I am attempting to adapt this to activate 7 relays (in place of the LEDs) which will in turn divert the power of the EL inverter to the tape sections.
Each relay is the connection of 2 EL panels to the (+) of the sole EL inverter while its (-) is hardwired in parallel among all the panels.

These are all small panels cut from a 3m length and have worked using this inverter independently both full length and cut. through some trial/error as well as some brightness and speed tweaking I have made this system work for a panel or 2, sometimes more, but other times the inverter and relays are working by the sound of it but the lights are not lighting or when they do they are skipping. It's intermittent too sometimes swapping panels works but at times it looks like the socket may be bad and the light is good other times it's the opposite even with the same pieces.

I have considered the sparkfun sequencer and it would most certainly save the day except that along with space being an issue my device also incorporates a few other Arduino devices including 2 servos, a sound module and a push button to start the sequence. however the sequencer doesn't seem capable to run 7 el connections as well as 4-6 other operations. is there a simpler way?
Am I missing components between my relays and lights?
Could I use my Uno in place of the sequencer? or can I expand the number of pins on the sequencer?

I would like to avoid daisy-chaining arduinos/boards as much as possible and even break down the number of separate boards I already have. I am trying to run this off of a single 9v and maybe a pair of button batteries.

Unfortunately I can no longer find the exact sequencer I am using but there are many 8 channel led chasers (w/o Brightness control) similar to mine on ebay.

Any help, insight, coding, recommendations anyone can offer would be greatly appreciated.

Thanks in advance.


texts:
I'm building a GPS tracker using an arduino nano, Adafruit Ultimate GPS breakout, a SD card slot and a SIM800L module.

So far everything works, the tracker uploads the data to a server as well as saving an extra copy to the SD card. The problem is now, that I don't really think that sending a HTTP request every cycle (gps data point) is very efficient and I would also like to have a way of storing information if there is no GPRS reception.

The idea is to save the GPS data to SD card and bulk send it out every 5 minutes or so.

What would be the best way to set up the data structure? I'm saving the deta in a csv style file:

2016-8-2 22:23:44, 52.53251922, 13.31121666, 18.30, 7, 1.33;

Parsing that is not the problem, but rather how to keep track of what has been sent already and what not. I was thinking about Marking the lines that I sent with a # or something similar as first character.

The only problem I could see with that would be performance, since it could take a while to go though it every time once it's getting a bit larger.

Thanks!

Lukas


texts: Serial communication between multiple devices (or Arduinos)

texts:
What I know from my search on the internet, for both SPI and I2C protocols, communication between multiple devices needs a master, which initiates the communication, and slaves, which respond to the master's request. Basically slaves can't initiate a transfer.

Is there any way to make different devices communicate on their will? I'm not sure about UART, but I think the story is the same here. But I know that it is possible to use a USB hub to connect multiple USB devices to one port on the computer. How can that be done? Can I use the same principle with Arduino?

To clarify what I want to do, consider that I have different modules (might be Arduinos) with different characteristics. I want to connect them on a bus line to a master Arduino. The module connections should be indifferent so that the user doesn't have to worry about which port should be used to connect the module. For this reason, using an Arduino Mega with more serial interfaces doesn't solve the problem, because we don't know which device is connected to which port.


texts:
I have recklessly bought the Baite Pro Mini and I find it difficult to upload any program. I use Ubuntu Linux, but out of frustration I am ready to install Windows, if it is necessary.

I've read the information from the blog http://nerdralph.blogspot.ca/2014/01/baite-pro-mini-review.html . Too bad, that the blog owner didn't put much details. Can anyone here fill some blanks for me?

How exactly should I connect the Arduino device to the computer?
I have a converter USB to serial pl2303HX:  which I tried to connect with the Baite Pro Mini in almost any plausible permutation of the wires, but never got any result.

edit:

Here is the description of pins of the pl2303HX:

I did connect it the following way:

Baite Pro Mini      pl2303HX
GND
GND  <------------> GND
VCC  <------------> +5V
RXI  <------------> TXD
TXC  <------------> RXD
DTR

I also tried the permutation with different GND pin. I also tried pressing the reset button on the Baite Pro Mini around the time of hitting the "Upload" button on the Arduino standard compiler.

I believe my failure might have something to do with the absence of DTR pin on the converter that resets the board just before upload. Are my worries justified? Is there anything I can do?

Which exactly Arduino bootloader do I need?
How to connect USBASP to the Beite Pro Mini?


texts: Arduino code is not working for unipolar stepper motor

texts:
I am using unipolar 1.8 degree stepper motor. I have written code to rotate stepper motor i.e. when A0 pin becomes HIGH it should rotate in clockwise and when A1 pin becomes HIGH it should move anti clockwise but motor is rotating only once when I am making A0/A1 HIGH and then stops. After that it is not rotating even if i am making A0, A1 pin high. I am very new to this please tell how to solve this problem. I am using microstepping drive, nema 17 stepper motor and Arduino Uno board.

#include <Stepper.h>

#define STEPS_PER_MOTOR_REVOLUTION 32

#define STEPS_PER_OUTPUT_REVOLUTION 32 * 200 //2048

Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 9, 8);
int  Steps2Take;
int buttonApin = A0;
int buttonBpin = A1;
int dirpin = 8;
int steppin = 9;
void setup()
{
  pinMode(buttonApin, INPUT);
  pinMode(buttonApin, INPUT);
  pinMode(dirpin, OUTPUT);
  pinMode(steppin, OUTPUT);
  small_stepper.setSpeed(1900);
}
void loop()
{
  int valA = digitalRead(buttonApin);

  if (valA == HIGH)
  { digitalWrite(dirpin, HIGH);
    for (int x = 0; x < 100; x++)
    { digitalWrite(steppin, HIGH);
      delayMicroseconds(1000);
      digitalWrite(steppin, LOW);
      delayMicroseconds(1000);
    }
  }
  int valB = digitalRead(buttonBpin);

  if (valB == HIGH)
  {
    digitalWrite(dirpin, LOW);
    for (int x = 0; x < 100; x++)
    {
      digitalWrite(steppin, LOW);
      delayMicroseconds(1000);
      digitalWrite(steppin, HIGH);
      delayMicroseconds(1000);
    }
  }
}


texts: ERROR on SIM900AT comand HTTPDATA (POST method)

texts:
Good day community, I have a project which is VEHICLE GPS Tracker and I'm using Arduino Mega, NEO GPS6MV2 and SIM900. I'm using SIM900 to send the GPS coordinates on a web server. I'm using the POST method and SIM900 is capable of this by using AT commands. I will also save the coordinates on a MySQL database.
My problem here is I can't send the data on the MySQL database. As you can see on the latter part of the commands, it response "ERROR".  That's why the coordinates failed to enter on the database. This is what I have on the database: What do you think is the problem here?


texts: How to stop uno from running program when powered on?

texts:
Does anyone know how to prevent the Uno from running the last program when it's powered on?
Many times I have changed hardware and wiring without clearing the program first.  Then when I power it on to upload the new program it will run the old program until it's uploaded.  This has many potential unwanted effects when the old program is running with the new hardware installed.


texts: stm8tool is not available for you operating system (ubuntu OS)

texts:
I have tried to  add STM8 to arduino by this instruction :
but i have this error:

also my system is :
so@so-notebook:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

Also googled the :
stm8tool is not available for you operating system
but don't find any result to solve ...
Update:
based of comments :
so@so-notebook:~$ uname -a
Linux so-notebook 5.6.9-050609-generic #202005051753 SMP Tue May 5 22:00:17 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Thanks.


texts: Reading HMC5883L hex values in 2's compliment C code

texts:
I want to develop my C code for HMC5883L.

I have 2 questions for my current code development.

My first question is:
But what I found in the datasheet is that the values are in the 2's compliment, so I don't know how to deal with them?! Do I have to take the values as they are in the data registers and convert them to decimal values and that's it? Or I have to convert them from 2's compliment to the original hex values?

This is a quote from the datasheet:

  Send 0x3D 0x06 (Read all 6 bytes. If gain is changed then this data set is using previous gain)
  Convert three 16-bit 2’s compliment hex values to decimal values and assign to X, Z, Y, respectively.

My second question:
How o read the data registers? What is the procedure?
I saw in the datasheet the following method but I didn't understand it.

  Loop
  Send 0x3D 0x06 (Read all 6 bytes. If gain is changed then this data set is using previous gain)
  Convert three 16-bit 2’s compliment hex values to decimal values and assign to X, Z, Y, respectively.
  Send 0x3C 0x03 (point to first data register 03)
  Wait about 67 ms (if 15 Hz rate) or monitor status register or DRDY hardware interrupt pin
  End_loop

So, I didn't understand that I send read command then I send write command, so how HMC5883L would return the value to me?

Regards,


texts: Use a PIR Sensor to detect the movements of a paper

texts: I need to detect when a paper comes out from a laser printer and count the number of printed papers. For that I hope to use a PIR sensor to detect the movement of the paper from the printer. Is it possible to detect the movement of a paper using a PIR sensor? Please be kind enough to help me.


texts:
I am compiling the sketch found here. I just downloaded the .ino and .h files and opened them, so I have not modded the code at all. I keep getting the following error.

In file included from flappyDuino.ino:7:0:
Sprite.h:3: error: variable 'flappybird_frame_1' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 static unsigned char PROGMEM flappybird_frame_1[] = { 0x03, 0xF0, 0x0C, 0x48, 0x10, 0x84, 0x78, 0x8A, 0x84, 0x8A, 0x82, 0x42, 0x82, 0x3E, 0x44, 0x41,0x38, 0xBE, 0x20, 0x41, 0x18, 0x3E, 0x07, 0xC0 };

                                                 ^
In file included from flappyDuino.ino:7:0:
Sprite.h:4: error: variable 'flappybird_frame_2' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 static unsigned char PROGMEM flappybird_frame_2[] = { 0x03, 0xF0, 0x0C, 0x48, 0x10, 0x84, 0x20, 0x8A, 0x40, 0x8A, 0x40, 0x42, 0x7C, 0x3E, 0x82, 0x41, 0x84, 0xBE, 0x88, 0x41, 0x78, 0x3E, 0x07, 0xC0 };

                                                 ^
Sprite.h:5: error: variable 'bar_bottom' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 static unsigned char PROGMEM bar_bottom[] = { 0xFF, 0xFF, 0xFF, 0x42, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E };

                                         ^
Sprite.h:6: error: variable 'bar_top' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 static unsigned char PROGMEM bar_top[] = { 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x42, 0xFF, 0xFF, 0xFF };

                                      ^
variable 'flappybird_frame_1' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

I'd appreciate any help.


texts: Connect 5V relay to ESP32 WROVER B board

texts: I need to use a ESP32 WROVER B based MCU board with a standard (cheap) one-channel 5V relay (e.g. to switch on a mains-power appliance). Attempted removal of excess solder around the headers permanently disabled the 5V power output line from the board (to power a relay or other modules); but other pins functional/board boots up correctly. So at present, there is only a 3.3V power source and 3.3V GPIO pins (and others such as for external microphone and speaker). I assume it is safe to connect a 3.3V GPIO from the MCU to IN and external 5V power source to VCC ad GND of the relay and connect the grounds of the MCU AND relay together to complete circuitry. The relay only needs to switch the appliance on when triggered (for example a lamp) and switch off when triggered again. I have a 3.3 ↔ 5V bidirectional level shifter, but don't think it is suitable here (unless it can be incorporated directly). An alternative may be is to use an arduino uno to connect with the relay, itself triggered by the ES32 and more complex circuitry (bearing in mind the ESP32 GPIO is 3.3V and arduino 5V).


texts: Thermosensor Error - 'Wire' does not name type?

texts:
Here is the code I am using:

#define D6T_ID 0x0A
#define D6T_CMD 0x4C

int ReadBuffer[35];
float ptat;
float tdata[16];

#include <Wire.h>
void setup() {
  Wire.begin();
  Serial.begin(9600);
  delay(500);

}

void loop() {

}
  int i;
  Wire.beginTransmission(D6T_ID);
  Wire.write(D6T_CMD);
  Wire.endTransmission();

  Wire.requestFrom(D6T_ID,35);

  for (i=0; i<35; ++i) {
    ReadBuffer[i] = Wire.read();
  }

  ptat = (ReadBuffer[0]+(ReadBuffer[1]*256))*0.1; //Reference Temp

  for (i=0; i<16; ++i) {
    tdata[i] = (ReadBuffer[(i*2+2)]+(ReadBuffer[(i*2+3)]*256))*0.1;
  }

  float tempF;

  if ( ((tdata[0]*9.0/5.0)+32.0)>0 )
  {
    for (i=0; i<16; ++i)
    {
      tempF = (tdata[i]*9.0/5.0)+32.0;
      Serial.print(tempF);
      Serial.print(',');
    }
    Serial.print((ptat*9.0/5.0)+32.0;
    Serial.print(',');
    Serial.println();
  }

    }
  }

This is the error I am getting:

exit status 1
'Wire' does not name a type

And it highlights this area of code:

Wire.requestFrom(D6T_ID,35);

I am completely new to using the arduino and coding so I am not sure if I already have the wire library that this code requires but when I look at the libraries in the Tools menu it is there. Do I need to download another library? If so can someone send me the link? Can someone explain what the error means? This is all foreign to me.

Thank you


texts:
I bought some ATtiny boards on ebay but I can't get my computers to see them.  When I plug them in I get the USB connected sound then a couple of seconds later it gives the USB unplugged sound.

The power light stays on and the LED blinks, I assume it has the blink sketch already loaded.

I have added the drivers to the IDE but I reckon the problem is before that, something to do with the Win10 PC even seeing it.  I have two versions of the board, one with a USB socket and one with a USB plug, neither work.  [UPDATE] Should have mentioned that the board doesn't show up as being connected to a port

I've looked around for solutions with no joy, I have tried everything I can think of.

Does anyone have a suggestion on where to start troubleshooting this?


texts: Making three led's blink at different times in Arduino

texts:
I have a breadboard connected to an Arduino Uno, 220k resistors connected to an led, of course it has a common ground and a pin connected to 5v. All pins are digital.

Now, I want led 1 to turn on for one second, the next led for two seconds and the next for three seconds, but that means, when the second led which has to be on for two seconds then the first led will come back on after one second has past on the second led, the third led would be on for three seconds, so the second led will also be on when two seconds pass and the first would be on when one second passes. So basically, all leds are on for their given duration.

How do I do this? I have been trying to do this since three days. It would be a pleasure if someone helps me out. Thanks.

int ledPin1= 2;
int ledPin2 = 4;
int ledPin3 = 7;

void setup(){
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  }

  void loop(){
  digitalWrite(ledPin1, HIGH);
  delay(500);
  digitalWrite(ledPin1, LOW);
  delay(500);

  digitalWrite(ledPin2, HIGH);
  delay(1000);
  digitalWrite(ledPin2, LOW);
  delay(1000);

  digitalWrite(ledPin3, HIGH);
  delay(1500);
  digitalWrite(ledPin3, LOW);
  delay(1500);
    }

So far this is the code. But it delays the whole program. Need leds on at given times.


texts:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'E'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
int count = 0; char num[4];
char key;
byte rowPins[ROWS] = {A0, A1, A2, A3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 5, 4, 3}; //connect to the column pinouts of the keypad

char adhaar[4][4] = {
  {'1', '0', '8', '3'},
  {'9', '1', '6', '0'},
  {'5', '7', '6', '1'},
  {'6', '7', '9', '3'}
};

char adhaar0[4] = {'1', '0', '8', '3'};
char adhaar1[4] = {'9', '1', '6', '0'};
char adhaar2[4] = {'5', '7', '6', '1'};
char adhaar3[4] = {'6', '7', '9', '3'};
boolean check, control, adhar, tag_status;
int i = 0, j, p, q;

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
  Serial.begin(9600);
  Serial.println(" enter your adhaar ");
}

void loop() {
  getkey();
  checkkey();
}

void getkey() {
  while (i < 4) {
    char key = keypad.getKey();
    if (key) {
      num[i] = key;
      Serial.print(num[i]);
      i++;
    }
  }
}

void checkkey() {
  if (i == 4) {
    control = true;
    for (p = 0; p < 4; p++) {
      for (q = 0; q < 4; q++) {
        if (adhaar[p][q] == num[q]) {
          check = true;
          Serial.println(num[q]);
        } else {
          check = false;
          Serial.println(" not eligile");
          break;
        }
      }
      if (check == true) {
        adhar = true;
        Serial.println(" cast your vote");
      }
    }
    i = 0;
  }
}

My problem is once the adhaar matches with the values initialised in the array I have, it's going to "cast your vote" as expected, but after that it's again executing "not eligible" 3 times.


texts:
I am trying to use serial communication to open and close a Blue Robotics Newton gripper. The gripper works with normal commands, but when I try to use serial communication to control it, it is extremely slow and my commands do not correspond to the action I would like. For example, I'll write a "o" in the serial monitor and the gripper will not open.
Does anyone know what is wrong?
#include "Servo.h"

#define GRIPPER_PWM_PIN   10    // Gripper PWM output pin
#define OPEN_TIME         5.0   // Gripper open time (seconds)
#define CLOSE_TIME        5.0   // Gripper close time (seconds)

#define OPEN_PWM_US       1100  // Gripper open PWM output (us)
#define CLOSE_PWM_US      1900  // Gripper close PWM output (us)
int incomingByte =0; // for incoming serial data
Servo gripper;

void setup() {
 // Attach gripper to proper pin
 gripper.attach(GRIPPER_PWM_PIN);
 Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

}

void loop() {
 if (Serial.available() > 0){
   incomingByte = Serial.read();
   if (incomingByte == 'o')
   {
     // Open the gripper
     gripper.writeMicroseconds(1100);
     // Let the gripper open up (microseconds)
     delay(OPEN_TIME*1000);
   }

   if (incomingByte == 'c')
   {
     // Close the gripper
     gripper.writeMicroseconds(1900);
     // Let the gripper close for a while (microseconds)
     delay(CLOSE_TIME*1000);
   }
 }
}


texts: Image from Arduino with camera ov7670 to Raspberry pi

texts:
i am stuck at sending picture to Raspberry pi from Arduino , how can i do this ? One way that i am using now is saving the picture on SD card module on the arduino , how to transfer that image to Raspberry pi? One problem is that the image on the SD card is in very "Raw format" which means , it needs to be converted to HEX and then we need to Add (bmp)headers or something i am not even sure, i have the python scripts that do this but the problem is it will slow down pi , and for my project its not acceptable that way. One other option is if i can stream the video that will be great . Some suggestions ?
Thank yoin

EDIT
About the process of Opening with HEX edtior:

The image data that Arduino is going to write to the SD card is raw image data i.e. just plain byte data-one byte for one pixel. If you try to open it as an image file then it won’t work. It is not in proper format to be read as an image. That’s why you need to write a bmp file with proper headers and use the raw image data to fill in for the pixel data in the bmp file. Now, here is the part where I cheated a little bit. I just opened up the file containing raw image data that Arduino wrote and opened it in a hex editor.

LINK: https://hkalasua.wordpress.com/2017/09/11/ov7670-arduino-sd/


texts: Is there a semi-permanent way to attach wires to the Nano?

texts:
At least for prototyping, is there a semi-permanent way to attach wires to the Nano posts?

And yes, usually the Nano is hanging in free space by its wires (yes I know, quick and dirty, should be using something cleaner, even for prototypes).  So I'm hoping for the best of both worlds, sturdy "enough" to stay attached, yet possible to remove and switch around.  Having no luck finding such advice on the internet, perhaps searching for the wrong terms.

EDIT:  I neglected one important point, each wire is attached individually just like the SparkFun wires with the female header as mentioned in @TheDoctor's answer below.


texts: I want to send pushbutton status from the nrf24l01 module to the app named nrfConnect. I could only find libraries that allow me to send float values. How could I send String values to the app? Thank You!


texts: Safely enabling voltage divider on a 12V battery

texts:
I'm planning to monitor voltage of a 12V battery with an Arduino's ADC pin connected via a voltage divider. Since I don't want the circuit itself to drain the battery when not in use, I want to use a transistor to "enable" it via an Arduino DIO pin like:

Is this a safe circuit to use?

If I set EN low to disable the divider, will that risk putting 12V directly on the ADC pin and burn it out? I've found alternative designs, but they seem overly complicated.

Edit: The battery is a Lipo which is also powering the Arduino through a step-down DC converter.


texts:
I needed to use TC1 for input capture, but also analogWrite() and an approximate 1 ms interrupt to poll the user interface (encoder, button).

The Arduino Nano's ATmega328p (datasheet, beware: a lot of bit symbol typos) has three timers:

TC0
TC1
TC2

It is not easy to find information on the "Arduino core" structure and it's use of peripherals. The Arduino Reference does not seem to refer to any information. Nor does Arduino Hacking.

Some info can be found on

https://arduino-info.wikispaces.com/Timers-Arduino

but I am not sure it's up to date. For instance, I find disabling TC2 also disables the analogWrite() PWM.
Trying to use TC0 results in an error, as TIMER0_OVF_vect is already being used ("multiple definition of `__vector_16'").

How can I use the timers (and their interrupts) that are already used for the core?


texts: Reading a part of bitmap image on Arduino

texts:
I'm pretty much a beginner when it comes to programming and have only recently started learning C++. Right now I'm stuck trying to covert a bitmap into a binary array. This is for a Robotics competition I've entered. The bitmap is a 54*96 pixel monochromatic 1 bpp image. I'm confused with the offset positions while trying to read the header. This is the code I've written so far and would greatly appreciate any help. I think the error lies in increment of the lineNo variable which needs to be in hex, but how to increment such values?

What I want to ultimately achieve is to read only some parts of the bitmap particularly the boxes with cross on them (see image below). How do I find out the pixel locations?

#include <SD.h>
#include <SPI.h>
File bMap;
File Text;
void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  int height = 0;
  int width = 0;
  int  bitmapOffset = 0xa;
  bMap = SD.open("map.bmp", FILE_READ);
  Text = SD.open("test.txt", FILE_WRITE);
  \\bMap.seek(0xa);
  \\bitmapOffset = bMap.read();
  \\Serial.println(bitmapOffset, BIN);
  \\Serial.println(bMap, HEX);
  bMap.seek(0x16);
  for (int i = 0; i < 4; i++) {
    height += (bMap.read() << (8 * i));
    Serial.println(height);
    int lineNo;
    int fileposition = 0;
    for (lineNo = 0; lineNo < height; lineNo++)
      fileposition = bitmapOffset + (lineNo);
    bMap.seek(fileposition);
    //Serial.print(lineNo);
    Serial.print(fileposition);
    //Serial.print(bitmapOffset);

  }

  bMap.seek(0x12);
  for (int i = 0; i < 4; i++) {
    width += (bMap.read() << (8 * i));
    Serial.println(width);
    if (Text) {
      Text.println(height, width);
      Text.close();
    }
  }
}

void loop() {}


texts: How to add toggle button for LCD display text and backlight?

texts:
I have set up a BMP180 and a DHT11 to display data on an HD44780 20x4 LCD.

I want to be able to toggle the altitude from meters to feet, the temperature from Celsius to Fahrenheit, and the pressure from absolute to sea level pressure using a tactile push button.

Here is the software code I have:

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

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <SFE_BMP180.h>
#include<dht.h>
dht DHT;

#define DHT11_PIN 8 // Second pin, leave 3rd pin unconnected 4th is ground
#include <SFE_BMP180.h>
#include <Wire.h>

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

#define ALTITUDE 237.0 // Altitude of Phillaur in Punjab, India. in meters

void setup() {
  lcd.begin(20, 4);
  lcd.setCursor(0, 0); // Zeroth Row
  lcd.print("hello, world!");
  lcd.clear();
  int chk = DHT.read11(DHT11_PIN);
  // Initialize the sensor (it is important to get calibration values stored on the device).
  if (pressure.begin()) {
    lcd.print("BMP180 init Success");
    delay(300);
  } else {
    lcd.print("BMP180 init fail");
    while (1); // Pause forever.
  }
}

void loop() {
  char status;
  double T, P, p0, a;
  lcd.clear();
  lcd.setCursor(0,0);
  //TODO Display in Feet as well using toggle
  lcd.print("Altitude: ");
  lcd.print(ALTITUDE, 0);
  lcd.print(" mtrs ");
  status = pressure.startTemperature();
  if (status != 0) {
    // Wait for the measurement to complete:
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0) {
      // Print out the measurement:
      Serial.print("temperature in deg C, From BMP180: ");
      lcd.setCursor(0, 1);
      lcd.print("Tmpratre: ");
      lcd.print(T, 2);
      lcd.print("'C");
      lcd.setCursor(0, 2);
      lcd.print("Humidity: ");
      lcd.print(DHT.humidity, 1);
      lcd.print("%");
      status = pressure.startPressure(3);
      if (status != 0) {
        // Wait for the measurement to complete:
        delay(status);
        status = pressure.getPressure(P, T);
        if (status != 0) {
          lcd.setCursor(0,3);
          // Print out the measurement:
          lcd.print("Pressure: ");
          lcd.print(P * 0.0295333727, 2);
          lcd.print(" mb");
          p0 = pressure.sealevel(P, ALTITUDE);
          // we're at 234 meters (Phillaur, Pb)
          // TODO: toggle to sea level to absolute pressure
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0, 2);
          Serial.print(" mb, ");
          Serial.print(p0 * 0.0295333727, 2);
          Serial.println(" inHg");
          a = pressure.altitude(P, p0);
          Serial.print("computed altitude: ");
          Serial.print(a, 0);
          Serial.print(" meters, ");
          Serial.print(a * 3.28084, 0);
          Serial.println(" feet");
        } else Serial.println("error retrieving pressure measurement\n");
      } else Serial.println("error starting pressure measurement\n");
    } else Serial.println("error retrieving temperature measurement\n");
  } else Serial.println("error starting temperature measurement\n");
  delay(5000);  // Pause for 5 seconds.
}


texts: High rate of transmission errors (~50%) using Xbee Radio

texts:
I am using a two Arduino setup with two XBee radios. One radio is sending data and the other is receiving data. I am sending three sensor readings following a protocol which uses three bytes for each sensor reading. Byte one is sensor information, byte two is data, and byte three is for error checking. When I run the set up for about 5 minutes I get approximately 47% errors in transmission. When I use the same size output and paste it all into the serial monitor I get 5 errors and all five come with the reading of the last 5 blocks of three bytes. Here is the code to send the data:

        delay(2000);

        // Calcuate weather parameters for serial and web
        calcWeather(); // Go calc all the various sensors

        // send weather out to serial port
        if (prevtemplm34_1 == templm34_1) // 2 in a row must be the same to send
        {
            Serial.write(0);
            Serial.write(templm34_1);
            Serial.write(templm34_1 ^ 0);
        }

        // send weather out to serial port
        if(prevtemplm34_2 == templm34_2) // 2 in a row must be the same to send
        {
            Serial.write(1);
            Serial.write(templm34_2);
            Serial.write(templm34_2 ^ 1);
        }

        // send weather out to serial port
        if(prevtemplm34_3 == templm34_3) // 2 in a row must be the same to send
        {
            Serial.write(2);
            Serial.write(templm34_3);
            Serial.write(templm34_3 ^ 2);
        }
        delay(2000);

The code for parsing received data is:

int readData ()
{
// There must be at least three available bytes to satisfy the protocol
// Otherwise, wait until three bytes have arrived to read anything
if (Serial.available() >= 3) {

      // Read the next three byte in the serial buffer
      incomingByteOne = Serial.read();
      Serial.write("Byte One: ");
      Serial.write(incomingByteOne);
      Serial.println();
      incomingByteTwo = Serial.read();
      Serial.write("Byte Two: ");
      Serial.write(incomingByteTwo);
      Serial.println();
      incomingByteThree = Serial.read();
      Serial.write("Byte Three: ");
      Serial.write(incomingByteThree);
      Serial.println();

      // XOR the first and second incoming bytes so that the result can be checked against the third error checking byte
      byte xorValue = incomingByteOne ^ incomingByteTwo;
      Serial.write("XOR VALUE: ");
      Serial.write(xorValue);
      Serial.println("Number of Errors: ");
      Serial.println(numberOfErrors);
      Serial.println();
      Serial.println();
      if(xorValue != incomingByteThree) {
        numberOfErrors++; // Add one to the total count of number of errors in transmission
      }
      else {
        // Mask for retrieving the five rightmost bits from incomingByteOne (00011111)
        byte maskForSensorNumber = 0x1f;

        // Shift incomingByteOne right 5 times in order to obtain the three bits representing the unit number
        int unitNumber = incomingByteOne >> 5;

        // AND incomingByteOne with the mask in order to retrieve only the five righmost bits representing the sensor number
        int sensorNumber = incomingByteOne & maskForSensorNumber;

        // Store the data for the correct sensor on the correct unit
        data[unitNumber][sensorNumber] = incomingByteTwo*1;
     }
}
}

It seems like the error is at least partially with my code. What could I do to reduce errors?


texts:
I have an IR Receiver hooked up to my arduino and a remote with an IR Trasmitter in it. I have some code to decode the values that are received but the values change even when I am pressing the same button!

Here is the code I am using:

#include <IRremote.h>

int IRpin = 8;
IRrecv irrecv(IRpin);
decode_results results;

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

void loop()
{
  if (irrecv.decode(&results))
    {
      Serial.println(results.value, HEX);
      irrecv.resume();
    }
}

and here is me pressing the same button 10 times and the output for it:

  9C01C8E1
  FFFFFFFF
  82A6A14C
  FFFFFFFF
  FFFFFFFF
  70D67871
  FFFFFFFF
  BCB5C227
  FFFFFFFF
  B358F5ED
  FFFFFFFF
  FFFFFFFF
  FFFFFFFF
  FFFFFFFF
  FFFFFFFF
  FFFFFFFF
  58EE9A27
  FFFFFFFF
  90750A0D
  FFFFFFFF
  FFFFFFFF
  FFFFFFFF


texts:
I have a Pro Micro board at which tried to upload a sketch with sparkfun's Pro Micro 3.3v processor selected.

After the upload completed successfully the board did not run again and is not even detected from the arduino ide anymore.

When I uploaded sketches with the leonardo 5.5v board selected everything went well and I had no problem. Now I can not burn the bootloader because of the arduino ide not detecting the board.

What can i do?


texts: 433Mhz transmitter interference when using long cable, only on Arduino Due

texts:
When the 433 transmitter is wired close to the Arduino Due (within 12" away), it works as expected. But when I put it on the end of a 15' cable, it has the following 2 symptoms:

-All the other nearby 433Mhz transmitters and receivers stop working. (I've never seen this happen from any other cause).

-My Extech 480836 EMF meter shows a big jump in electromagnetic radiation along the entire length of the 15' cable (it jumps from 0.1 uW/m2 to 3 mW/m2 a few inches away). The reading only goes down to normal if I unplug the transmitter's data wire from the Arduino.

The transmitter in question is still able to send signals correctly when wired with a 15' cable to the Due (properly activating remote switches), even though it disables every other 433 transmitter in the area.

I've tested this with 2 different kinds of 433 transmitters, getting the same result. Both of the transmitters work fine whenever wired closely to the Arduino Due, and both work as expected when connected to an Arduino Uno. The problems still occur even if I'm not sending any wireless transmissions from the code. Disconnecting the transmitter's data wire from the Arduino Due causes the problem to stop immediately.

I'm using the RCSwitch library. The simple code below works fine on an Arduino Uno, whether the transmitter is wired far or close to the Uno. The same code works fine with the Due when the transmitter is close to the Due. But when the transmitter is wired 15' away from the Due, then the problems occur. On the Due I've tested using 5v and 3v for powering the transmitter. Changing the voltages doesn't seem to affect the problem.

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();

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

  // Transmitter is connected to Arduino Pin #8
  mySwitch.enableTransmit(8);
}

void loop() {}

Why am I having this strange behavior? Do you have any suggestions on how to fix it?


texts: Faster and lighter approximate timing code without using timer

texts:
I want to use loop() iterations counter to execute some tasks periodically or tasks like debouncing. My other sketch is running every loop() at least 20 ms, and if i am using 5 ms time to wait to
debounce a button, it will still be at least 20 ms waiting, also cpu will have to compare two not zero values, which is a bit slower.
I think it is more difficult for cpu than just incrementing and decrementing one variable and comparing it to 0. So i came up with pattern like that:

boolean onOff=1; // arduino led state. My task here is LED blinking.
byte loopCounter=2; // number of iterations made by loop(). Set as little variable as possible to save ram and cpu time.
//Code will be executed every "loopCounter" iteration of loop().
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
      if (--loopCounter == 0) { //comparing with 0 should be a bit faster and easier for Arduino to process. Correct me if i am wrong.
        loopCounter=2; // That digit sets how often your code will be executed. Every 2(3,4... set your own value) iterations of loop().
        digitalWrite(13, onOff= !onOff); // the task itself.
        }
}

It may be more convenient in some ways than millis() and micros() patterns. Also i do want want to use hardware timers for timing.
It may be convenient in cases, when you don't care when exactly task will be done, you just want it to be done ASAP (as soon as possible), but
not during that particular iteration of loop(). Basicly you can use it as a timer if you know how it takes one iteration to be done.
So, if your sketch runs 1 iteration of loop() for 1 ms, and you need some action to be done every 1 sec, 1ms*1000 == 1 sec. So you
need it to be done every 1000 iterations.

So, is that really can save some ram and cpu time?
Is comparing with zero is faster for arduino than comparing with not
zero?
Are millis() and micros() timing patterns using more operations
(setting value to variable, computing the difference between 2
values and than comparing it to a period you have set) instead of
decrementing and comparing to zero with my pattern?
Any side-effects of using my pattern? I can only think of very
unaccurate timing and delays more than you think if your sketch done
smth more than usual, because of button push for example or some
sensor changed value.

Thank you!


texts:
I'm trying to use EspMQTTClient inside a class, called myIOT32.

An error, which I don't find the reason for is generated.

/home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.cpp: In lambda function:
/home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.cpp:25:5: error: 'this' was not captured for this lambda function
     client.publish("mytopic/test", "This is a message sent 5 seconds later");
     ^
/home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.cpp:25:5: error: invalid use of non-static data member 'myIOT32::client'
In file included from /home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.cpp:1:0:
/home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.h:20:19: note: declared here
     EspMQTTClient client;
                   ^
Multiple libraries were found for "WiFi.h"
 Used: /home/guy/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WiFi
 Not used: /home/guy/arduino-1.8.12/libraries/WiFi
exit status 1
Error compiling for board LOLIN D32.

.h file:

#ifndef myIOT32_h
#define myIOT32_h

// OTA libraries
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

#include "secrets.h"
#include "EspMQTTClient.h"
#include "Arduino.h"

class myIOT32
{
private:
    void onConnectionEstablished();  // <--- this is a must have function ( was taken as is from lib's built-in example

public:
    EspMQTTClient client;
    myIOT32(char *ssid, char *wifi_p, char *mqtt_broker, char *mqttU, char *mqttP, char *devTopic, int port = 1883);
};

#endif

.cpp file:

#include "myIOTesp32.h"

myIOT32::myIOT32(char *ssid, char *wifi_p, char *mqtt_broker, char *mqttU, char *mqttP, char *devTopic, int port)
    : client(ssid, wifi_p, mqtt_broker, mqttU, mqttP, devTopic, port)
{
}

void myIOT32::onConnectionEstablished()
{
  // Subscribe to "mytopic/test" and display received message to Serial
  client.subscribe("mytopic/test", [](const String & payload) {
    Serial.println(payload);
  });

  // Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
  client.subscribe("mytopic/wildcardtest/#", [](const String & topic, const String & payload) {
    Serial.println(topic + ": " + payload);
  });

  // Publish a message to "mytopic/test"
  client.publish("mytopic/test", "This is a message"); // You can activate the retain flag by setting the third parameter to true

  // Execute delayed instructions
  client.executeDelayed(5 * 1000, []() {
    client.publish("mytopic/test", "This is a message sent 5 seconds later");
  });
}

Appreciate any help in constructing such a class


texts: what is the analog reference, I know that it can be used as a voltage reference, but not exactly what  it is all about please someone help.


texts:
I am working on a project that records the elevation changes of a 1 foot wide section using sonar distance measurement. I have 10 HC-SR04 sensors arranged in a straight line over this 1 foot section.

The issue I am having is that when I send an output from my sonar sensor, I must wait until the return signal is recorded before I can trigger the next sonar sensor to take a measurement. This is rather slow and decreases the sampling frequency significantly. I need each sonar sensor to take 1000 measurements per second for my project.

Is there a way to have the HC-SR04 sensors simultaneously output and listen for the return signal? I would want all 10 sensors to send a 40 kHz pulse at the same time, and then when a return signal is recorded, another 40 kHz pulse is sent out.

The average distance to the 1 foot wide section is about 11 inch. If the Arduino is limited and there are other control boards that can accomplish this, it would help a lot if you can point me in the right direction.


texts:
I have a NodeMcu Lua ESP8266 ESP-12E which i want to use to control to a relais via Wifi network.

The first step was to write an Arduino Sketch which scans networks and connects to the network. However, even the standard example from the examples menu didn't work (c.f.,https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiScan/WiFiScan.ino) .

To rule out hardware problems I tried the LUA version from the list API doc (see below), which worked.

 -- print ap list
function listap(t)
      for k,v in pairs(t) do
        print(k.." : "..v)
      end
end

wifi.sta.getap(listap)

Using a firmware build from http://nodemcu.com/index_en.html

I gave the INO version another try and it seemed to work as well. However, it turned out it only works if the previous firmware has been the firmware from http://nodemcu.com/index_en.html

To I need to include a library or something ?

Thanks in advance,
Cafebabe


texts:
I am a student and currently doing a semester project. The first goal is to get accelerometer and gyroscope data from FIS1100 using the Arduino (Uno). I've got the FIS1100 Evaluation Kit user guide from my supervisor. I've simply separated the sensor PCB from the MCU and connected this sensor to an Arduino Uno as shown on this photo:

The connections are as following:

SCL (on the header of FIS) - A5 (Arduino)
SDA (on the header of FIS) - A4 (Arduino)
GND (on the header of FIS) - GND (Arduino)
3V3-to VIOREF (on the header of FIS) - 3V3 (Arduino)

I wrote this simple code, which I uploaded to the Arduino board. Unfortunately as a result, I got zeros as output.

#include <Wire.h>
const int I2C_address = 0b1101010;
long a_X, a_Y, a_Z;
float g_X, g_Y, g_Z;

long gyro_X, gyro_Y, gyro_Z;
float rot_X, rot_Y, rot_Z;

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

}

void loop() {
  recordAccelRegisters();
  recordGyroRegisters();
  printData();
  delay(800);

}

void setupFIS(){
  Wire.beginTransmission(I2C_address);
  Wire.write(0x02);
  Wire.write(0b00000000);
  Wire.endTransmission(true);

  Wire.beginTransmission(I2C_address);
  Wire.write(0x08);
  Wire.write(0b10000011);
  Wire.endTransmission(true);

  Wire.beginTransmission(I2C_address);
  Wire.write(0x04);
  Wire.write(0b00000000);
  Wire.endTransmission(true);

  Wire.beginTransmission(I2C_address);
  Wire.write(0x03);
  Wire.write(0b00000000);
  Wire.endTransmission(true);

  Wire.beginTransmission(I2C_address);
  Wire.write(0x05);
  Wire.write(0b00000000);
  Wire.endTransmission(true);

  Wire.beginTransmission(I2C_address);
  Wire.write(0x06);
  Wire.write(0b00000000);
  Wire.endTransmission(true);

  Wire.beginTransmission(I2C_address);
  Wire.write(0x07);
  Wire.write(0b00000000);
  Wire.endTransmission(true);
}

void recordAccelRegisters(){
  Wire.beginTransmission(I2C_address);
  Wire.write(0x19);
  Wire.endTransmission(false);
  Wire.requestFrom(I2C_address,6,true);
  //while(Wire.available()<6);
  a_X = Wire.read()<<8|Wire.read();
  a_Y = Wire.read()<<8|Wire.read();
  a_Z = Wire.read()<<8|Wire.read();
  processAccelData();
}

void processAccelData(){
  g_X = a_X/16384.0;
  g_Y = a_Y/16384.0;
  g_Z= a_Z/16384.0;
}

void recordGyroRegisters(){
  Wire.beginTransmission(I2C_address);
  Wire.write(0x1F);
  Wire.endTransmission(false);
  Wire.requestFrom(I2C_address,6,true);
  //while(Wire.available()<6);
  gyro_X = Wire.read()<<8|Wire.read();
  gyro_Y = Wire.read()<<8|Wire.read();
  gyro_Z = Wire.read()<<8|Wire.read();
  processGyroData();
}

void processGyroData(){
  rot_X = gyro_X/1024.0;
  rot_Y = gyro_Y/1024.0;
  rot_Z= gyro_Z/1024.0;
}

void printData(){
  Serial.print("Gyro(deg)");
  Serial.print(" X=");
  Serial.print(rot_X);
  Serial.print(" Y=");
  Serial.print(rot_Y);
  Serial.print(" Z=");
  Serial.print(rot_Z);

  Serial.print("   Accel(g)");
  Serial.print(" X=");
  Serial.print(g_X);
  Serial.print(" Y=");
  Serial.print(g_Y);
  Serial.print(" Z=");
  Serial.println(g_Z);
}

So, I really need help to get some relevant data.

And also I have doubts concerning the I2C-address of the FIS1100. In the datasheet of the FIS1100 on page 50 it is said:

  the address is 0b1101010 in case when pin SA0 is left unconnected, internally there is a weak pull-down of 200k; the address is 0b1101011 in case when pin SA0 is pulled-up externally.

Now lets go again to user guide and on page 25 (schematic of pull-up/down resistors) we see that SA0 is externally pulled-down.

Question: which I2C-address should I use?


texts: How should I use an optocoupler to control a 12Vcc load with Arduino?

texts:
I am developing a project to operate a load of about 12Vdc.  I considered the use of an optocoupler to avoid mechanical wear of a relay.  The design I have tried is this:

This configuration seems to work OK, but I am a biologist and this is my first attempt with an opto of any kind!!!!  I had a lot of trouble with the transistor until I changed to a PNP.  Is this right?  Can it be done with an NPN or even without any transistor at all?


texts:
I'm trying to get a robot car(elegoo one) to do the obstacle avoidance course. I am trying to write my own one from scratch to better myself and thus would really appreciate it if someone were to tell me what's wrong with my code and why it's not working
#include <Servo.h>  //servo library
Servo myservo;      // create servo object to control servo
Servo servosweep;
int Echo = A4;
int Trig = A5;

#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11
#define carSpeedForward 100
#define carSpeedLeftandRight 150
int rightDistance = 0, leftDistance = 0, middleDistance = 0;
int pos=0;

void forward(){
  analogWrite(ENA, carSpeedForward);
  analogWrite(ENB, carSpeedForward);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("Forward");
}

void back() {
  analogWrite(ENA, carSpeedForward);
  analogWrite(ENB, carSpeedForward);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Back");
}

void left() {
  analogWrite(ENA, carSpeedLeftandRight);
  analogWrite(ENB, carSpeedLeftandRight);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("Left");
}

void right() {
  analogWrite(ENA, carSpeedLeftandRight);
  analogWrite(ENB, carSpeedLeftandRight);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Right");
}

void stop() {
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
  Serial.println("Stop!");
}

//Ultrasonic distance measurement Sub function
int Distance_test() {
  digitalWrite(Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);
  delayMicroseconds(20);
  digitalWrite(Trig, LOW);
  float Fdistance = pulseIn(Echo, HIGH);
  Fdistance= Fdistance / 58;
  return (int)Fdistance;
}

void setup() {
  myservo.write(pos);
  myservo.attach(3);  // attach servo on pin 3 to servo object
  Serial.begin(9600);
  pinMode(Echo, INPUT);
  pinMode(Trig, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  //stop();
}

void loop(){
  for (pos = 0; pos < 90; pos += 1.0) {
  servosweep.write(pos);
  delay(50);
  leftDistance=Distance_test();
  }

  myservo.write(90);
  middleDistance=Distance_test();

  for (pos=90;pos<=180;pos+=1.0){
    servosweep.write(pos);
    delay(50);
    rightDistance=Distance_test();

  }

  if(rightDistance > leftDistance) {
        right();
        delay(360);
      }
      else if(rightDistance < leftDistance) {
        left();
        delay(360);
      }
      else if((rightDistance <= 40) || (leftDistance <= 40)) {
        back();
        delay(180);
      }
      else {
        forward();
      }
}

I'm trying to get the ultrasonic sensor to read values from the left(0 to 90), the middle(90) and the right(90 to 180) and then use them for comparison to decide where to go. When I run this code my car goes in circles and I don't know what the problem is. Any help would be appreciated.


texts: L298 Motor Driver not showing Red light when connecting power supply

texts:
I recently bought an L298 motor driver module for controlling 2 motors(5v each).
When i connect the power supply(which is a normal RC car battery holder(3)) the red light doesn't light up.
Instead if i connect the +ve to the 5v on the motor driver, the red light is glowing, but the motors don't work.


texts: Why are Tone.cpp and IPAddress.cpp getting built for my project?

texts:
I'm using avr-size to see the size of library objects to free up some FLASH. Why are Tone.cpp and IPAddress.cpp getting built? e.g.

$ cd /var/folders/3j/6wp3hvrj34n0xg3xzq6vjq380000gn/T/build8391693238079360471.tmp/
localhost:build8391693238079360471.tmp
$ /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-size *.o
   text    data     bss     dec     hex filename
      0       0       0       0       0 CDC.cpp.o
      0       0       0       0       0 HID.cpp.o
   1816       0     170    1986     7c2 HardwareSerial.cpp.o
    512       0       6     518     206 IPAddress.cpp.o
  10186     391     377   10954    2aca MainINOFile.cpp.o
   1872      14       0    1886     75e Print.cpp.o
   1414       1       0    1415     587 Stream.cpp.o
   1365       1      21    1387     56b Tone.cpp.o
      0       0       0       0       0 USBCore.cpp.o
    288       0       4     292     124 WInterrupts.c.o
    306       0       0     306     132 WMath.cpp.o
   4796       1       1    4798    12be WString.cpp.o
     30       0       0      30      1e main.cpp.o
    618       6       0     624     270 malloc.c.o
     56       0       0      56      38 new.cpp.o
    450       0       0     450     1c2 realloc.c.o
    588       0       9     597     255 wiring.c.o
    266       1       0     267     10b wiring_analog.c.o
    550       0       0     550     226 wiring_digital.c.o
    320       0       0     320     140 wiring_pulse.c.o
    260       0       0     260     104 wiring_shift.c.o
$ /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-size */*.o
   text    data     bss     dec     hex filename
   2790       0       0    2790     ae6 DS3231/DS3231.cpp.o
     38       0       1      39      27 EEPROM/EEPROM.cpp.o
   1444       0       0    1444     5a4 LSM303/lsm303.cpp.o
    782       0       0     782     30e Messenger/Messenger.cpp.o
    116       0       1     117      75 SPI/SPI.cpp.o
    142       0       4     146      92 SdFat/MinimumSerial.cpp.o
   2568       0       0    2568     a08 SdFat/Sd2Card.cpp.o
  10644       0       4   10648    2998 SdFat/SdBaseFile.cpp.o
   1322       2       0    1324     52c SdFat/SdFat.cpp.o
    152       0       0     152      98 SdFat/SdFatUtil.cpp.o
    233       0       0     233      e9 SdFat/SdFile.cpp.o
    736       0       0     736     2e0 SdFat/SdStream.cpp.o
   2604       0     523    3127     c37 SdFat/SdVolume.cpp.o
   3395       0       0    3395     d43 SdFat/istream.cpp.o
   1635       0       0    1635     663 SdFat/ostream.cpp.o
    754       0      86     840     348 Wire/Wire.cpp.o
$ /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-size *.elf
   text    data     bss     dec     hex filename
  29204     442    1279   30925    78cd MainINOFile.cpp.elf


texts: Why so different not connected analog inputs?

texts:
I took just Arduino Uno board, connected Ethernet Shield to it and compiled Web Server example. And it works.

But it outputs:

analog input 0 is 1023
analog input 1 is 1023
analog input 2 is 789
analog input 3 is 663
analog input 4 is 525
analog input 5 is 449

Why so different values? Shouldn't it be zeros? Is this static electricity or what?


texts: Connecting a push button to a stepper motor problem

texts:
I can't get this code to work. The button code and the step motor code works separately. However, when I code using an if statement saying when the button is pressed the motor will move or else it won't. PLEASE HELP.
const int buttonPin = 7;

int buttonState = 0;
int serialData = 0;

#define IN_1 8
#define IN_2 9
#define IN_3 10
#define IN_4 11
#define DELAY_TIME 30

int i = 0;

void setup() {
  Serial.begin(9600);
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.print ("start");
}

void loop() {
  buttonState = digitalRead (buttonPin);
  if (buttonState == HIGH) {
    //delay(1000);
    for (i=0; i<4; i++)
      Serial.println ("pressed");
    switch (i) {
      case 3: // ASCII value for '1'
        digitalWrite(IN_1, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_1, LOW);
        break;
      case 1: // ASCII value for '2'
        digitalWrite(IN_2, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_2, LOW);
        break;
      case 0: // ASCII value for '3'
        digitalWrite(IN_3, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_3, LOW);
        break;
      case 2: // ASCII value for '4'
        digitalWrite(IN_4, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_4, LOW);
        break;
      default:
        Serial.println("Not a valid case");
        break;
    }
    if (i == 4) {
      i = 0;
    } else {
      i = 5;
    }
  }
}


texts: Flame sensor and MQ2 sensor not working with Esp8266?

texts:
When ever flame is detected sms will be send this is what i am doing,but the  flame and smoke sensor works awesome when they are tested seperately(Without Esp8266) when they are integrated with Esp8266 they are not at all responding to the flame or smoke . I have tested flame Sensor with serial monitor the values are 150,148,147,......
When it is tested without Esp8266 it has given 1000,996.....(Without Flame)
52,64,38.....(With Flame )

Flame sensor Connections:
VCC : 5V
GND : GND
D0 : 7`

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

const char *ssid = "NUS_006";
const char *password = "shankar006";
int flame=7;
void setup() {
    delay(1000);
    pinMode(flame,INPUT);
    Serial.begin(115200);
    WiFi.mode(WIFI_OFF);
    delay(1000);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    Serial.println("");
    Serial.print("Connecting");
    while (WiFi.status() != WL_CONNECTED) {
           delay(500);
           Serial.print(".");
    }
    Serial.println("");
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
}

void loop()
{
  Serial.print("Flame= ");
  Serial.println(digitalRead(flame));
  delay(3000);
}


texts: How to turn the digital pin to analog pin?

texts: I am using a 10 IR sensor array and they use analog pins. I am using a motor shield for the Uno. So I cannot use the Mega. I have only five analog pins I need 8. How can I do it?


texts: Hijack analogue doorbell chime to trigger nodemcu

texts:
I have an oldskool doorbell chime. What i would like to do is whenever there's a voltage flowing through the doorbell also trigger an HTTP call, which will trigger some smart home automations.
I have the following setup to test the button press i.e. current to chime but it the output randomly appears as 'pressed' 'not pressed'. Im not sure how to wire this up.
This is the endgoal:

What i've tried as test case is this:
#include <Arduino.h>
#include <ESP8266WiFi.h>

int button = 16;
int buttonPress = 0;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600); // open the serial port at 9600 bps:

  pinMode(button, INPUT);

  delay(10);

  WiFi.hostname("Doorbell");
  WiFi.begin("WifiSSID", "WifiPassword");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}

void loop()
{
  buttonPress = digitalRead(button);
  if (buttonPress == HIGH)
  {
    Serial.println("Presssed");
  }
  else
  {
    Serial.println("Not Pressed");
  }

  buttonPress = 0;
  delay(1000);
  // put your main code here, to run repeatedly:
}

eventually in the pressed state the Node MCU needs to make a http request. I'll cross that bridge once i get there.
EDIT: The chime is 8V AC


texts:
When I write '13' to the EEPROM and read it straight after it works correctly.

However when I comment out the write part of the code and try to just read the data, the value is no longer 13 as it used to be but reverts back to 255. Whats going on?

I am running a standalone atmega328 on a breadboard with a 16mhz crystal, programmed by a Nano R3.

void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);

//EEPROM.write(1,13);
}

void loop() {
scoreBinary();

}

void scoreBinary(){

int score= EEPROM.read(1);

if(score==13){
digitalWrite(2,HIGH);
}
delay(10000);
}


texts:
A little history: I have two Arduino Uno and I couldn't program them by IDE, I got these errors:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00

So I googled it for a while and I suspect of missing bootloader on atmega micro on the board, as I don't have AVR programmer I programmed both Arduinos with Raspberry Pi and Arduino IDE tool through ICSP pins.

It (burning bootloader) runs perfectly on both Arduino. One of them got fixed and got back to normal, but the other one gave me same error, so I changed their Atmega micro, but same result. Second Arduino (bad one) can't transfer program to AVR even with other one (good one) AVR so both AVRs on the boards are good.
The program (blink LED) run even on the bad Arduino and pin 13 blink.

My questions are:

How could I test the suspected Arduino board? Is the second Atmel micro near usb female port need bootloader too?

  Update 1: I follow this tutorial but my Arduino couldn't go to DFU
  mod by shorting the pins. When I connect those pins led pin 13 not blink and lsusb command show Arduino not Atmel.

  Update 2 : I went through this question and this
  troubleshoot to upload bootloader to Atmel USB device but my
  second Arduino (bad one) didn't respond and gave me this error :

Atmega chip detector.
Written by Nick Gammon.
Version 1.17
Compiled on Jul 13 2015 at 11:14:35 with Arduino IDE 105.
Attempting to enter ICSP programming mode......................................................
Failed to enter programming mode. Double-check wiring!
Programming mode off.

  Is it possible my Atmega16U2 chip is burned?

  Update 3 : I do reach the point that I am pretty sure Atmega16U2 is
  dead and it isn't responding to its ICSP pins and it blocks any USB to AVR connection. I check the wiring and I
  test it on good Arduino and its sequence are correct and it works on good one. Now what can I
  do, as Atmega16U2 is not rechangeable, should I throw bad Arduino away?


texts: ESP8266 12e Arduino IDE outputs garbage values on serial monitor

texts:
I recently started using the ESP8266 12E (Amazon link) and hooked the board up to the Arduino IDE.

When trying to run any of the example sketches, all sketches compile and upload correctly. The blink sketch correctly causes the LED to blink, however, in the serial monitor a varying and large quantity of junk characters appear:

The first thing I investigated was of course the baud rate. Online, documentation for the ESP8266 indicate 115200 as the correct baud rate, but on the bottom of the device, the baud rate is listed as 9600.

The junk characters, of course, appear whether the baud rate is 9600 or 115200. Using trial-and-error, I tried each other option. I've also tried several USB to micro-USB (c) cables. They're the same ones I use to charge my phone - is that the issue?

Am I missing something simple here? I searched each of the other Stack Exchange questions about garbage serial monitor values and they all seemed to indicate that the baud rate was the culprit, or that the CL / NR values needed to be changed. Experimentation with these did not result in removing the characters.


texts:
I have a statement:

if(control > 100 && control < 130)
{

  //count time 30 seconds and open pin1 for 3 seconds.

}

How can I count 30 seconds and open a pin for 3 seconds?


texts:
it has been so long since I tried to connect the esp8266 through Arduino Uno and get it to work my goal is to send data from the Arduino Uno to web site, I have tried everything and a lot of codes but none worked at first I could get a response  but sometimes it does and sometimes it does not I even bought an other one but the new one did not respond at all so I flashed the old one following the instructions in here and I got response the next day I tried to reuse it and it does not respond at all not even when I put the serial on 115200 and both NR&CR and tried AT but nothing showed in return .i found this tutorial
and I tried to get it to work using a mobile app but as usual, it does not work

AT
AT+RST
ATE0
AT+CWMODE=1
AT+CWQAP
AT+CWDHCP=1,1
AT+CWJAP="RemoteXY","12345678"

but i did not get hte name of it wifi in my wifi list
this is the code

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377

// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,2,0,0,0,30,0,8,13,0,
  2,0,70,25,22,11,2,26,31,31,
  79,78,0,79,70,70,0,1,0,10,
  26,12,12,2,31,88,0 };

// this structure defines all the variables of your control interface
struct {

    // input variable
  uint8_t switch_1; // =1 if switch ON and =0 if OFF
  uint8_t button_1; // =1 if button pressed, else =0

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

#define PIN_SWITCH_1 2
#define PIN_BUTTON_1 12

void setup()
{
  RemoteXY_Init ();

  pinMode (PIN_SWITCH_1, OUTPUT);
  pinMode (PIN_BUTTON_1, OUTPUT);

  // TODO you setup code

}

void loop()
{
  RemoteXY_Handler ();

  digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
  digitalWrite(PIN_BUTTON_1, (RemoteXY.button_1==0)?LOW:HIGH);

  // TODO you loop code
  // use the RemoteXY structure for data transfer

}

i wired it like this

one last thing is it gets hot every time so what could be the problem what's wrong with is what should I do


texts:
I have a problem using the PubSubClient. I want to create dynamic mqtt-topics based on a predefined prefix and a suffix and my ESP-macaddress.

My problem is that the PubSubClient requires a cost char* and I cant seem to figure out how to do it dynamically.

Below is my current solution and that is not as convenient as I want. The code below is only pseudocode but that are the crucial parts.

// How I get the mac_address
WiFi.macAddress(mac_array);
for (int i = 0; i < sizeof(mac_array); ++i){
     sprintf(mac_address,"%s%02x",mac_address,mac_array[i]);
}

// Current way, where I hard code the topic_in & topic_out
const char* topic_in = "node/18fe34d77ead/from_node_red";
const char* topic_out = "node/18fe34d77ead/to_node_red";

Below is an example of how I would love to do it but I cant figure out how to do it.

// I would love to be able to do like this
const char* topic_in = "node/"+mac_address+"/from_node_red";

Can any one please help me or point me in the right direction.


texts: Why can you use FTDI with an ATMega328 with no external crystal?

texts:
I have read that serial (UART) communications are unreliable or will not work when using the 8MHz internal oscillator as the clock source.

For example here are two results from a quick google.

http://forum.arduino.cc/index.php?topic=116404.0
"Since the internal RC oscillator is not as well regulated as one using an external resonator or crystal you may have to use a slower baud rate to make sure the bit times fall within spec.  Maybe re-compile your bootloader for 9600 baud."

http://www.technoblogy.com/show?1YO1
"unless you need accurate timing, or are going to use the serial interface (which requires accurate timing), you don't need an external crystal and capacitors, because the ATmega328 has a built-in internal clock"

However, opinion seems to be split as to whether its acceptable/a good idea to use serial on an ATMega328 using the internal resonator. I do not currently have an Arduino board with me for the time being so i cannot test this out in person.

This brings me to my question. Despite the opinions that serial is unreliable, it seems no one has problems uploading code to an ATMega328 via FTDI when using no crystal (at least it hasnt come up in my searches). FTDI uses serial to upload so surely if serial is unreliable with a standalone chip, uploading via FTDI would not be possible?

I'm sure i am missing something but I was hoping that someone could explain this to me.


texts: How to sense mobile signal coming to a room using arduino uno

texts: How to make arduino sense mobile signal coming into a room and display the calling number on an LCD screen


texts: How to detect an read buttons pressure on touchscreen

texts:
I made simple 3 red buttons like this:

#include <SPI.h>

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "URTouch.h"

#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_IRQ  7

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK,

#define t_SCK 3
#define t_CS 4
#define t_MOSI 5
#define t_MISO 6
#define t_IRQ 7

URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);

void setup() {

  tft.begin();
  tft.fillScreen(BLACK);

  tft.fillRoundRect (12,15,30,80,5,RED);//50,100,30,80,5,RED
  tft.fillRoundRect (50,15,30,80,5,RED);
  tft.fillRoundRect (88,15,30,80,5,RED);

  delay(500);
}

And this the part where I need help:

void loop()
{
  int x, y;

  while(ts.dataAvailable())
  {
    ts.read();                //-----------> this is the whole thing
    x = ts.getX();
    y = ts.getY();

  }

What I need is, to know how to detect and read the pressure of the button area, so that I can run different tasks.


texts: I am making a project with 3 arduinos (2 slave, 1 master) and I want to know can I use the mpu6050 since it uses the I2c communication.


texts:
I want to create something similar to an article I read a few months ago about the effects of Dopamine. Dopamine is known as the feel-good neurotransmitter; the brain releases it when we eat food that we crave, contributing to pleasure and satisfaction as part of the reward system. I want to use this reward method for breaking habits and creating new ones. I saw someone on youtube make a Dopamine box, very similar to what I was thinking (I left it down below), but I think it had a few design flaws.
So how it works, the lights will be dimmed (so it’s not annoying) and default red, the screen in the center will read the list of activities you have set for yourself that you want to be completed. When you complete a task, you will flip a switch on the housing side; this will toggle some lights to go from red to green and give you the reward system. Along with the lights turning green, the box will play a sound, similar to when you win a game or get a kill, again triggering the dopamine release.
The LCD will display a message, something like "keep going"  or "Don't quit."
The LED is for the green and red lights mentioned above, and the piezo is for a buzzer to play a sound to congratulate you for finishing a task.
Down below, I left a circuit I made in TinkerCad. I am very new to this, and I would like if someone could look at my connections and tell me if I have connected them correctly.
TinkerCad Link- https://www.tinkercad.com/things/9EYfcPv1XsX


texts:
I’m starting on a project about monitoring the soil in the agriculture field and also to visualise the data remotely. The aim of this project is collect the atmospheric data as well as the soil related parameters and then send them to cloud where they’ll be presented on the dashboard. I decide to use Arduino as my development board and Arduino MKR GMS 1400 would be perfect for this project. However this board is quite expensive. So just wondering that are there any alternative I can use for this project
Thank you


texts: Can not print an element in an specific position in an arduino list

texts:
I have been tying to print an element of a list with the same position as the number that it matches, but it does not seem to work and I can not figure out if I made some mistake, could someone please check it? Would really appreciate it

Here are the list declarations:

int names[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
char *users[10] = {"Josh", "John", "Frederic", "Mikael", "Anthony", "Charles", "Tom", "Chris", "Steve", "Mike" };

And this is what I am using to print the name I need:

if (attempt != FINGERPRINT_OK) return -1;
Serial.println ("Belongs to: ");
if(data.fingerID == names[n]) {
    Serial.print(users[n]);
}

Complete Code:

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);
pinMode (12, OUTPUT);
pinMode (13, OUTPUT);

Adafruit_Fingerprint data = Adafruit_Fingerprint(&mySerial);

int names[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
char *users[10] = {"Josh", "John", "Frederic", "Mikael", "Anthony",
"Charles", "Tom", "Chris", "Steve", "Mike" };

void setup() {
  Serial.begin(9600);
  while (!Serial);
  data.begin(57600);
  if (data.verifyPassword()) {
    Serial.println("Verified connection");
}

  else {
    Serial.println("Unnable to verify connection, try again");
 while (1) { delay(2500); }
}

data.getTemplateCount();
Serial.print("Waiting for one of the:"); Serial.print(data.templateCount);
Serial.println("valid fingerprint");

int getFingerprintIDez();
uint8_t getFingerprintID();

void loop() {
for ( int i = 0; i <= 10; i++) {
 uint8_t attempt = data.getImage();
  switch (attempt) {
   case FINGERPRINT_OK:
   break;
 delay (2500);
}

attempt = data.image2Tz();
  switch (attempt) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
    break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
    return attempt;
  }

 attempt = data.fingerFastSearch();
   if (attempt == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
    digitalWrite (13, HIGH);
    delay(1250 );
    digitalWrite (13, LOW);
  }
   else if (attempt == FINGERPRINT_NOTFOUND) {
   Serial.println("Did not find a match");
   digitalWrite (12, HIGH);
   delay(1250 );
   digitalWrite (12, LOW);
   return attempt;
  }
Serial.print("Found ID #"); Serial.print(data.fingerID);
Serial.print(" with confidence of "); Serial.println(data.confidence);
return data.fingerID;

uint8_t attempt2 = data.getImage();
if (attempt2 != FINGERPRINT_OK) return -1;
 attempt2 = data.image2Tz();
if (attempt2 != FINGERPRINT_OK) return -1;
 attempt2 = data.fingerFastSearch();
if (attempt2 != FINGERPRINT_OK) return -1;
 Serial.println ("Presents: ");
if(data.fingerID == names[n]) {
    Serial.print(users[n]);
}
}
}

I am attempting that when a fingerprint is verified, the position that matches it out of all the stored fingerprints gets stored as n so I can later print the name asigned to that same position. Thanks


texts: Should millis() be stored in a variable once each loop, or called for every reference?

texts:
When comparing the value of millis() numerous times per loop(), are there reasons for/against storing it in a variable once at the top of loop(), v.s.  calling millis() each time?

The most basic example code "Blink Without Delay" is written as such:

void loop() {
  //...
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // Do stuff
  }
}

I don't really she why the example code above bothers storing millis() in a variable "currentMillis" at all. (I realize that in such a simple program, there would be no noticeable difference.)

I imagine that if I use a variable, the longer the duration of loop(), and the further down my use of the "currentMillis" variable, the more deviated the stored value will be.
I'm wondering the other ramifications of either method as well.

Does calling millis() directly hog resources of any sort? If not, I imagine it would be better to not use a variable, so as to get a more accurate time value and save a bit of memory.


texts: Arduino Bluetooth connection with Android

texts: I am wondering why my Arduino program won't start its sketch to connect a bluesmirf to an android device and send data to the android whenever I use an external power supply. The sketch starts whenever i open the serial monitor, but using the power supply, it wont work.


texts: Converting hexadecimal string to floating point value

texts:
I am reading data from an energy meter over modbus protocol and I am getting hex values from there. I want to convert that hex string to floating point value.
For example - 0x416f0000 denotes a value of 14.9375.Reference

Can anyone please help me how to do it on Arduino IDE?


texts: Why am I getting an 'invalid conversion' error on compile?

texts:
I have one of these NodeMCU ESP8266 OLED Arduino Wifi Modules which I am trying to load with SpaceHuhn's deauther software from Github

I am trying to compile the source code using Arduino IDE with the display enabled and have followed the instructions to do so from github repository here.

I initially downloaded the latest software but as I didn't know which display option to enable before compiling, I went for an earlier version, v1.6, which has a video on how you are supposed to install it on YouTube.

After uncommenting line 18 from:

//#define USE_DISPLAY /* <-- uncomment that if you want to use the display */

so that it reads:

#define USE_DISPLAY /* <-- uncomment that if you want to use the display */

and then trying to compile, I get this error:

D:\Documents\Innovateking-EU Nodemcu ESP8266\Deauther\esp8266_deauther-v.1.6\esp8266_deauther\esp8266_deauther.ino: In function 'void setup()':

esp8266_deauther:592:32: error: invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

   display.setFont(Roboto_Mono_8);

In file included from D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master\src/SSD1306Wire.h:34:0,

                 from D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master\src/SSD1306.h:33,

                 from D:\Documents\Innovateking-EU Nodemcu ESP8266\Deauther\esp8266_deauther-v.1.6\esp8266_deauther\esp8266_deauther.ino:28:

    D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master\src/OLEDDisplay.h:243:10: error:   initializing argument 1 of 'void OLEDDisplay::setFont(const uint8_t*)' [-fpermissive]

     void setFont(const uint8_t *fontData);

Multiple libraries were found for "SSD1306.h"
 Used: D:\Documents\Arduino\libraries\esp8266-oled-ssd1306-master
 Not used: C:\Users\cos\AppData\Local\Arduino15\packages\deauther\hardware\esp8266\2.0.0-deauther\libraries\esp8266-oled-ssd1306-4.0.0
exit status 1
invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

The youtube video shows the process working, assuming nothing was edited out....  As far as I can see I have done everything the same.

Has anyone had any experience of loading this on to these boards?  Or know what the problem is?


texts: What is the difference between running code with the scope of the void setup() or void loop() vs. outside their scope?

texts:
Good evening everyone,

I have bene playing around with making my own library, specifically for the controlling Timer1 on the Arduino Mega 2560. I'm sort of new to OOP but I am trying my hand at it here.

I wrote some code to generate a PWM wave with a 100 ms period and a 25% duty cycle, and I have Siglent SDS 1052DL, 50MHz oscilloscope that I'm using that verifies the code is successful. I am using clear-timer-on-compare-match mode and timer interrupts to generate the PWM wave. My code is below:

#include "Timer1.h"

Timer1 timer;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  timer.begin();
}

void loop(){
  // put your main code here, to run repeatedly:
}

I made a Timer1.cpp file and a Timer1.h to go along with this file. They are below.

Timer1.cpp

#include "Arduino.h"
#include "Timer1.h"

float frequency = 10.0;
float period_ms;
float clock_pulse = 16.0;

unsigned long opening_time = 25000;

unsigned int ocr1a;
unsigned int ocr1b;

Timer1::Timer1() { // Object used to control 16-bit timer1

}

void Timer1::begin() {
  CRITICAL_SECTION_START; // Clear I bit
  CLEAR_TCCR1A; // Reset TCCR1A
  CLEAR_TCCR1B; // Reset TCCR1B
  SET_CTC_MODE; // Set to CTC mode
  DISABLE_TIMER1_INTERRUPTS; // Disable OCIE1A/B
  TCCR1B |= (1 << CS12); // 256
  period_ms = (1000.0f / frequency);
  ocr1a = 1000UL * (period_ms / clock_pulse);
  OCR1A = ocr1a;
  TIMSK1 |= (1 << OCIE1A);

  ocr1b = (unsigned int)float(opening_time) / clock_pulse;
  OCR1B = ocr1b;
  TIMSK1 |= (1 << OCIE1B);
  TCNT1 = 0; // Reset counter

  CRITICAL_SECTION_END; // Set I bit
}

ISR(TIMER1_COMPA_vect) {
  digitalWrite(13, HIGH);
}

ISR(TIMER1_COMPB_vect) {
  digitalWrite(13, LOW);
}

Timer1.h

#ifndef TIMER1_H
#define TIMER1_H

// ========== HANDY MACROS ========== //
#define CLEAR_TCCR1A                  TCCR1A = 0
#define CLEAR_TCCR1B                  TCCR1B = 0
#define SET_CTC_MODE                  TCCR1B |= (1 << WGM12)
#define DISABLE_TIMER1_INTERRUPTS     TIMSK1 &= ~((1 << OCIE1B) | (1 << OCIE1A))
#define CLEAR_CLOCK_SELECT_BITS       TCCR1B &= ~((1 << CS12) | (1 << CS11) | (1 << CS10))

#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()
#define CRITICAL_SECTION_END   SREG = _sreg

class Timer1{
  public:
  // Constructor:
  Timer1();
  // Begin:
  void begin();

};

#endif // TIMER1_H

This code works exactly as I would expect. I originally had placed the whole block of code found in the Timer1::begin() method in the Timer1::Timer1() constructor method. When I did this, I was getting a completely different signal (2.04 ms period with about an 80% duty cycle). Is there a simple explanation for what is occurring?


texts:
I am successful putting and retrieving char array into Arduino flash memory using PROGMEM char arrays.

I am building my app using header files with class definition / implementation and would like to keep the strings  in same header file.

If I define another PROGMEM char array neither one can be executed. In other words - these PROGMEM are global arrays as far as Arduino compiler is concerned, they compile but won't show up.

Here is my test code

  lcd.clear();
  lcd.print(*strFlashDebug[0]);  // in CDebug
  lcd.setCursor(0,1);
  lcd.print(*strFlashTrack[0]);  // in CTrack

If I put both definitions in same header file it only works with only one lcd.print enabled, not commented out.

It appears that multiple PROGMEM arrays can be defined and compiled but only one is actually usable.
Any comments are appreciated.
Cheers Vaclav


texts: Assigning value inside structure array outside setup and loop functions

texts:
I'm having some difficulty assigning a value to a variable in a struct array outside the loop and setup functions. Assigning a value to an int or char array works completely fine but this doesn't.

The example code and error message returned after trying to compile are below. Any help is greatly appriciated. Thanks

void setup()
{
}

struct trap_game_detail {
    byte flush_quantity;
    byte flush_interval;
    byte random_min;
    byte random_max;
    byte random_quantity;
} trap_game_details[2];

trap_game_details[0].random_min = 1;

void loop()
{

}

src/sketch.ino:13:5: error: ‘trap_game_details’ does not name a type
     trap_game_details[0].random_min = 1;
     ^
.build/uno/Makefile:166: recipe for target '.build/uno/src/sketch.o' failed


texts: Is it safe to place a capacitor across vin and gnd?

texts:
I have a 3A fan hooked up to an ATX power supply in parallel with a transformer which powers my board through VIN/GND.

The ATX is gated by a relay on its DC side and seems to cause enough of a current drain that it causes the Arduino to reset.

I have place a 470μF capacitor accross the Arduinos VIN and GND pins and it seems to have stopped the problem, but I'm not too experienced using capacitors. Is this an apropriate value? I'm not sure what difference it would make. And is this a wise move as I so think?

Standard?

EDIT:
Here's a very basic sketch..

12V Transformer powers arduino on VIN/GND pins, other pins are 5V, GND and control for relay


texts: Assign an interrupt to any pin of the atmega328 microcontroller

texts:
I need to record the appearance of a signal from the sensor on the PD0 pin. This is the first time in my life that I want to use an interrupt for this.
With your help, I configured the sketch for my pin PD0
#include <avr/interrupt.h>

volatile int value = 0;

void setup()
{
  cli();
  PCICR |= 0b00000100;    // turn on port d
  PCMSK2 |= 0b00000001;    // turn on pins PD0 (PCINT16)
  sei();

  Serial.begin(9600);
}

void loop()
{
  Serial.println(value);
}

ISR(PCINT2_vect)// Port D, PCINT16 - PCINT23
{
  value++;
}

I need to wait and take a certain action when a high signal comes from the sensor. For example, add one to the constant.
I also did not understand when interruptions occur. When the signal changes from bottom to top, when from top to bottom, or no matter how? Can't see if these settings are here? Maybe it is set somehow by default?


texts:
I'm a new to all things electronics and I'm having trouble using a DFRobot Bluno V2 with a DFRobot Relay Shield for Arduino V2.1. For testing purposes I've done the exact same circuit as represented in this diagram:

http://www.dfrobot.com/wiki/index.php/Relay_Shield_for_Arduino_V2.1_(SKU:DFR0144)#Connection_Diagram

But it is not working. If I send HIGH signal to D10 or press the S4 button on the shield, the circuit does not close and the LED doesn't turn on (even though the LED4 next to the relay on the shield lights up). If I do same circuit connecting the LED to D10 directly (ie., without using the relay) it works fine. I've also tested this with the other relays on the shield and the results were the same.

Does anyone know what might be the issue? What am I doing wrong?

Thanks in advance.


texts:
I have an arduino uno which turns on a water pump (12V, 3.6W) once every 10 hours for a few minutes (I've followed this tutorial on how to connect the water pump). To turn on the water pump I used a PN2222A transistor, and connected the base in serial with a 220 ohm resistor to the digital pin 9.
A few minutes after turning on the power on my Arduino UNO the PN2222A transistor burned out (lots of smoke coming out of it).

I also used a 1N4007 diode, cathode connected to the positive pin, and anode to the negative pin of the water pump.

The power supply outputs around 12.6V

Maybe the resistor is too low/weak?

I've created a schematic here, attached it's a snapshot of it.

EDIT1:
Here is a picture on how I connected my transistor. I've removed from the photo:

the input wires (should be top-right of breadboard)
wire to arduino digital pin (should be on h-19 on the breadboard)
water pump from the breadboard (positive pin: c-2, negative pin: h-2)

EDIT2 (a solution that worked for me):

It looks like the input to the arduino (arduino and the pump share the same 12V input, but the arduino's goes through a step down converter to 10V) was a bit loose (to be more specific, the negative pin was loose) and randomly, the arduino would shut down and then the pump would start (maybe because the digital pin becomes HIGH, dont know why though) all while the arduino is shut off. That's when the transistor (PN2222A) burned out. I switched to TIP120 with a 1k resistor as @Jot suggested and looks like when the same problem with the power happens, nothing is burning out :)