texts:
I have been having problems trying to run multi sensor code for my project, this requires four KY-024 Linear magnetic Hall sensors as position sensors that trigger NC independent relays to make a circuit.
I can get the code to run on one independent circuit, one hall switch one relay with no problems.
But when I try the code for 4 hall sensors + relays I get no response from the circuit at this point I am at a loss where to go from here the code compiled with no problems.

int hallswitch = 1;
int val = 0;
int RELAY1 = 6;

void setup() {
  pinMode(hallswitch, INPUT);
  pinMode(RELAY1, OUTPUT);
}

void loop() {
  val = digitalRead(hallswitch);

  if (val == HIGH) {
    digitalWrite(RELAY1, HIGH);
  }
  else {
    digitalWrite(RELAY1, LOW);
  }
}

and

int hallswitch1 = 1;  //Pin for Hall switch
int hallswitch2 = 2;  //Pin for Hall switch
int hallswitch3 = 4;  //Pin for Hall switch
int hallswitch4 = 5;  //Pin for Hall switch

int val = 0;       //Integer for reading Hall statu

int RELAY1 = 6;    // The socket number on the Arduino that the relay1 will go to.
int RELAY2 = 7;    // The socket number on the Arduino that the relay1 will go to.
int RELAY3 = 8;    // The socket number on the Arduino that the relay1 will go to.
int RELAY4 = 9;    // The socket number on the Arduino that the relay1 will go to.

void setup()
{
  pinMode(hallswitch1, INPUT);
  pinMode (RELAY1, OUTPUT);

  pinMode(hallswitch2, INPUT);
  pinMode (RELAY2, OUTPUT);

  pinMode(hallswitch3, INPUT);
  pinMode (RELAY3, OUTPUT);

  pinMode(hallswitch4, INPUT);
  pinMode (RELAY4, OUTPUT);
}

void loop() {
  val = digitalRead(hallswitch1);               //Read Hall pin status
  val = digitalRead(hallswitch2);               //Read Hall pin status
  val = digitalRead(hallswitch3);               //Read Hall pin status
  val = digitalRead(hallswitch4);               //Read Hall pin status

  if (val == HIGH) {                        //If there is a magnet infront of Hall switch...
    digitalWrite(RELAY1, HIGH);             // Turn RELAY1 on:
    digitalWrite(RELAY2, HIGH);
    digitalWrite(RELAY3, HIGH);
    digitalWrite(RELAY4, HIGH);
  }
  else {
    digitalWrite(RELAY1, LOW);               // Turn RELAY1 off:
    digitalWrite(RELAY2, LOW);
    digitalWrite(RELAY3, LOW);
    digitalWrite(RELAY4, LOW);
  }
}


texts: Displayng 2 error messages on a 16x02 display

texts:
I am trying to display on a 16x02 LCD display 2 error codes. The error message is when one or both thermocouple wires get disconnected and the second error message is when the soldering iron temp goes higher than 432 C. I am using MAX6675 module.
The problem is that when I disconnect one thermocouple wire (the + or the -) sometimes the displayed message is "Overheating !!!" instead of "No tc conn !!!".
Is there any way to display the correct error ?
heaterTemp = thermocouple.readCelsius();
  Input = heaterTemp - 100;
   //No TC connection
  if (isnan(Input)) // No TC Connection
  {
    while (true) {
      digitalWrite(relay_pin, LOW);
      digitalWrite(11, LOW);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("NO TC CONN !!!");
      delay(1000);
    }
  }

  //Soldering Iron overtemperature
  if (Input >= 432)
  {
    while (true) {
      digitalWrite(relay_pin, LOW);
      digitalWrite(11, LOW);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("OVERHEATING !!!");
      delay(1000);
    }
  }

Edit: I finally decided to use the same message for both errors - no TC connection and overheating. I used the code below:
heaterTemp = thermocouple.readCelsius();
  Input = 0.779828 * heaterTemp - 10.3427;
  if (isnan(heaterTemp) or Input >= 432) // No TC Connection OR over-temperature
  {
    while (true) {
      digitalWrite(relay_pin, LOW);
      digitalWrite(11, LOW);
      for (int i=0; i<=1; i++){
      lcd.clear();
      lcd.setCursor(0, i);
      lcd.write((byte)0);
      lcd.setCursor(1, i);
      lcd.write((byte)0);
      lcd.setCursor(5, i);
      lcd.print("ERROR!");
      lcd.setCursor(14, i);
      lcd.write((byte)0);
      lcd.setCursor(15, i);
      lcd.write((byte)0);
      delay(1000);
      }
    }
  }

and
byte thermometer[8] = //icon for termometer
{
  B00100,
  B01010,
  B01010,
  B01110,
  B01110,
  B11111,
  B11111,
  B01110
};

The code displays the thermometer symbol at the beginning and at the end of the row and the text (including the symbols) are moving from one to another row.
Now it is sufficiently to display a error message when the thermocouple gets disconnected or when the iron temperature goes above 432 *C.
I have also left the 2 while(true) loops because I need the program to stay in the loop and display the error message until I turn off the power and start again the soldering station.


texts: Why does the Leonardo take 8 seconds to restart?

texts:
My problem is, that my system takes 8 seconds to start the programm after I push the Reset button on my Leonardo.
During that period the L-LED is pulsating.

What could be the problem?


texts:
I'm trying to develop one code in which I'm facing issue with while loop. Once I enter any newString it enter in while loop it count till 10 times, when (n>10)  then it is coming out from the while loop.
Facing issues in this part

while (n < 10)
  {
    while (!ret) {
      if ((time + 15) < millis()) {
        ret = dmd.stepMarquee(-1,0);
        time = millis();
      }
    }
     ret = false;
     n++;
    }

I just want when I enter any newString when loop is running it break while loop and start display newString.

Please help me out with this. Thanks for your help, greatly appreciated.

Here is my full code:

#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 2
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

String inputString = "";
boolean stringComplete = false;
String commandString = "";

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}

void setup()
{
   Serial.begin(9600);
   Serial.println("Arduino Start");
   Timer1.initialize( 5000 );
   Timer1.attachInterrupt( ScanDMD );
   dmd.clearScreen( true );
}

void loop() {

if(stringComplete)
{
  stringComplete = false;
  getCommand();

  if(commandString.equals("STAR"))
  {
   dmd.clearScreen( true );
  }

  else if(commandString.equals("PRSC"))
  {
    String text = getTextToPrint();
    printText(text);
  }
  inputString = "";
}

}

void getCommand()
{
  if(inputString.length()>0)
  {
     commandString = inputString.substring(1,5);
  }
}

String getTextToPrint()
{
  String value = inputString.substring(5,(inputString.length())-2);
  return value;
}

void printText(String text)
{
  char newString[256];
  int sLength = text.length();
  text.toCharArray( newString, sLength+1 );
  dmd.selectFont(System5x7);
  dmd.drawMarquee( newString , sLength , (32*DISPLAYS_ACROSS )-1 ,1);
  unsigned long time;
  boolean ret = false;
  time = millis();
  int n;
  n= 0;
  while (n < 10)
  {
    while (!ret) {
      if ((time + 15) < millis()) {
        ret = dmd.stepMarquee(-1,0);
        time = millis();
      }
    }
     ret = false;
     n++;
    }
}

void serialEvent() {
  while (Serial.available()) {            // get the new byte:
    char inChar = (char)Serial.read();    // add it to the inputString:
    inputString += inChar;                // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}


texts:
I want to make code between to devices , the communication between the I2C master to master , but   in the sometime the one of the connect with other device SPI bus master to slave .
how it work?


texts:
I want to stop the sound of a buzzer after I push the push button. I tried a code, but when the button is not pushed, the buzzer continue to make sound. How can I fixed it?
const int pin_contact= 6;
const int buzzer = 9; //buzzer to arduino pin 9

void setup(){
  pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
  pinMode(pin_contact, INPUT);
  Serial.begin(9600);
}

void loop() {
  tone(buzzer, 200);

  int stare_contact = digitalRead(pin_contact);
  if (stare_contact == HIGH) {
    noTone(buzzer);
  }
}


texts: How to program pressure sensor and motor with motor shield

texts:
I was working on controlling a high power motor with a heavy duty motor controller, and I was able to make my motor spin, but I wasn't able to incorporate a program for my pressure sensor and make it determine the speed of the motor.  I'm pretty sure I connected the parts correctly on my circuit board, so I figure my code must have some mistake, or something missing.
The pressure sensor I'm using:
The motor controller I'm using: http://www.robotshop.com/en/arduino-compatible-mega-motor-shield-1a-5-28v.html#Useful
The code I have:

int motorValue=0;
int sensorValue=0;
int sensorPin=A0;
int EnablePin=8;
int PWMPin2=3;

void setup() {
  // put your setup code here, to run once:
pinMode(EnablePin, OUTPUT);
//pinMode(sensorPin, OUTPUT);
Serial.begin(9600);
pinMode(PWMPin2, OUTPUT);
pinMode(sensorPin, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
sensorValue = analogRead(sensorPin);

//float voltage = sensorValue * (5.0 / 1023.0);

//Serial.println(voltage);

delay(50);

motorValue=map(sensorValue,0,1023,0,255);
//motorValue=sensorValue / 4;
//analogWrite(motorPin,motorValue);
digitalWrite(EnablePin, HIGH);
analogWrite(PWMPin2, motorValue);
}

Edit: The sensor works by reading the voltage.  Here's an actual picture of how I wired it:  I used this wiring to print out the voltage with just the Arduino and it worked, and I'm using it with the same wiring but while having the motor shield on top, so that's why I'm guessing that I must not be programming the sensor right with the motor controller.  I couldn't get the voltage readings when I used this setup with the motor driver shield.


texts: How to establish a connection between an Arduino and a web server via ESP8266

texts:
I'm working on a IOT project where three or more IOT device communicates with a web server. The IoT device will have Arduino UNO which is connected to a ESP8266 so internet access is available. Arduino UNO reads current sensor data and post it to a website that I built and I also want to control a single relay switch from the same website. I am a beginner and most project I find is only single directional communication or making ESP8266 as web server. Please point me to right Direction.

I was able to post sensor data to thingspeak.com. I was also able to control The relay switch from a website but only separately. I was not able to make it work when I combined the two.

Directions:

How to build web APIS to send and receive data to Arduino UNO via esp8266?
How to send data and check the received data in Arduino UNO VIA esp8266?
Can I send and receive data in JSON format Arduino UNO?
How can the Arduino UNO filter required data from the received json?
Is this project possible without Arduino and just by programming the ESP8266 module?

I know basic HTML, Basic CSS, Basic JavaScript, Basic Nodejs, json and a tiny bit of JQuery.


texts: Arduino IDE + Metro + I2C device (Grideye) + Code for Uno = weird results?

texts:
I have been working successfully with the arduino uno and a thermal camera device called grid eye. There is a board available at the popular suppliers of arduino addons.
For the uno, the code looks something like this and works.

// Load Grideye Library
#include <SparkFun_GridEYE_Arduino_Library.h>
uint8_t pixelTable[64];
void setup() {
    grideye.setI2CAddress(104); //This means, that one pin of the device is pulled up
    grideye.begin();
    Serial.begin(115200);
}
void loop() {
// loop through all 64 pixels on the device and map each float value to a number
// between 0 and 15 using the HOT and COLD values we set at the top of the sketch
  for (unsigned char i = 0; i < 64; i++) {
    if (i % 8 == 0) {
      Serial.print("\n");
    }
    pixelTable[i] = grideye.getPixelTemperature(i);
    Serial.print(pixelTable[i]);
    Serial.print(" ");
  }

For the Metro I use Arduino IDE with the Libraries installed and the board selected. But all I get is an Array full of '0'.

Connected, both times, to the designated SDA and SCL pins, as well as the 3.3V and GND Pin.

Any Ideas?


texts: Arduino I2C communication between Raspberry Pi

texts:
We are trying to communicate between multiple Arduino's (in this example a Nano and a Mega) and a Raspberry Pi. The Raspberry pi is defined as master and the Arduino's as slaves. We would also like that the Arduino's communicate between each other. For example: The Mega requests from the Nano and at some point, the Mega also communicates with the Raspberry Pi. This is the short version of what we are trying to accomplish but we ran into the problem that the i2c communication failed between the Nano and Mega upon the request from the Mega to the Nano.

Schematic

Problem

After some time the i2c bus 'fills' up...

Code Nano

(We send RFID data to Mega)

#include <Wire.h>
#include "SPI.h"
#include "MFRC522.h"

#define SS_PIN 10
#define RST_PIN 9
#define SP_PIN 8

MFRC522 rfid(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();

  Wire.begin(0x10);
  Wire.onRequest(requestEvent);
}

void loop() {

}

void requestEvent() {
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;

  // Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  // Serial.println(rfid.PICC_GetTypeName(piccType));

  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
      piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
      piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }

  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
      (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
      String(rfid.uid.uidByte[i], HEX) +
      (i != 3 ? ":" : "");
  }
  strID.toUpperCase();
  //81:AE:1D:29
  Serial.print("Send to Mega: ");
  Serial.println(strID);

  Wire.write(strID.c_str());

  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();

}

Code Mega

#include <Wire.h>

void setup() {
  Wire.begin(0x03);
}

void loop() {
  Wire.requestFrom(0x10, 11);

  String uid = "";

  while (Wire.available()) {
    char c = "";
    c = Wire.read();
    uid += c;
  }

  if (uid.indexOf(':') != 2) {
    return;
  }

  Serial.println(uid);

  delay(500);
}

We would like to communicate between the Arduino's when the Raspberry Pi is master.


texts: 5V pin out, 8 pins and micropython/circuitpython support: does such a board exist?

texts:
For a project, I am looking for a board to connect eight different neopixel-strips to, on eight different data pins. Because of the great length between the board and the first pixels of these strips, I'd like to have a board that operates on 5V instead of 3.3V. Then, the software that I have written to manage the LEDs is made in (micro)python. Finally, for simplicity's sake, I'd like to run this complete project on a single board without too many external components.
So, I have found 5V boards with enough pins, like the Arduino Mega. I have also found boards with enough pins and support for micropython or circuitpython, like the ESP32 or Arduino Zero.
However, I haven't quite found a board that matches all my requirements. The Arduino Mega doesn't support Python (or does it?) and the ESP32 and Arduino Zero operate at 3.3V, not 5V.
Of course, an ESP32 with a level shifter (as shown on https://github.com/Aircoookie/WLED/wiki) would work, but is there perhaps a board out there that fits all my requirements our of the box?
Edit: It seems I misunderstood some things about the hardware - sorry, I'm a software guy, not really a hardware guy :-) I fixed the question above as not to confuse future readers.


texts: Multiple I2C sensors with the same address

texts:
I am trying to find the simplest way to connect multiple (preferably around 10-20) IMU sensors to one controller. There are two constraints: sampling at 60Hz and reasonably simple wiring as I want to put it on clothes.

I am totally new to the Arduino world, please let me know what other details I should provide.

It seems that just having multiple IMUs on the I2C bus would work great, but they usually all come with the same address.

So, the solutions I found so far:

Using several different IMUs from different companies - hard to find 20 of them
Using a multiplexer - requires star-like wiring topology.
Using multiple controllers - inefficient and doesn't seem right.

For now, the solution with a multiplexer seems to me the most reasonable, but is there any other way I am missing? Can I somehow produce IMUs with, say, 16 different addresses and wire them all together to one I2C?

Thanks for your help!


texts: Upload of sketch with avrdude stuck only outside of IDE

texts:
When uploading my sketch to my Genuino Micro with the Arduino IDE, everything works perfectly. This is the command issued:

C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/bin/avrdude
-CC:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/etc/avrdude.conf
-v -patmega32u4 -cavr109 -PCOM10 -b57600 -D
-Uflash:w:C:\Users\<user>\AppData\Local\Temp\arduino_build_31080/KeyboardBase.ino.hex:i

All just working like it should (except that the com-port selected is actually COM6, not COM10).

But, if I try to use that exact same command from the command line, avrdude gets stuck for minutes and the arduino is still executing the sketch I've put on it.

C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/bin/avrdude
-CC:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/etc/avrdude.conf
-v -patmega32u4 -cavr109 -PCOM6 -b57600 -D
-Uflash:w:C:\Users\<user>\AppData\Local\Temp\arduino_build_31080/KeyboardBase.ino.hex:i

avrdude: Version 6.3, compiled on Dec 16 2016 at 13:33:19
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/etc/avrdude.conf"

         Using Port                    : COM6
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .^C

avrdude needs to be run from cmd because I'm building a sketch with partly modified libraries, so it's built and uploaded manually with make.

I already tried running cmd as administrator, using -v -v to get more info, and changing the baud-rate, plugging the Arduino into a different USB port and restarting my machine (the same problem occurred yesterday but I didn't manage to fix it) none of that helped. What else can I try?


texts: Can I use arduino and mobile phone screen to make a touch board?

texts:
I'm new to Arduino, I want to use Arduino and a mobile phone screen to make a simple touch board.

This phone screen I mean, is like this:

Can I connect it to Arduino, and when my fingers touch the screen, Arduino can get the events?


texts:
I have a problem with remaining headers. Can't seem to find the first header "RtcUtility.h". Anyone how to fix? I've provided a picture for you to see.

Error Messages:

  Arduino: 1.8.10 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

  sample_time:6:24: error: RtcUtility.h: No such file or directory

  Multiple libraries were found for "ArduinoOTA.h"
   #include

  Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ArduinoOTA
                          ^

  Multiple libraries were found for "Wire.h"
  compilation terminated.

  Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\Wire
  Multiple libraries were found for "ESP8266WiFi.h"
   Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi
  Multiple libraries were found for "ESP8266mDNS.h"
   Used: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266mDNS
  exit status 1
  RtcUtility.h: No such file or directory

  This report would have more information with
  "Show verbose output during compilation"
  option enabled in File -> Preferences.


texts: how much current does Arduino Nano draw when only using 8 digital pins?

texts:
I want to connect an Arduino Nano to an Intel Minnowboard Max (it's like a Raspberry Pi). I know Arduino can draw up to 500 mA current through the USB connection. Since I already need the USB to communicate the Arduino with the Minnowboard, it would be nice to not power the Arduino separately as well. However, I wouldn't want the current the Arduino draws from the Minnowboard to overheat Minnowboard's 2.5A 12V power supply.
I only have 8 buttons connected to the digital pins of the Arduino Nano. Nano sends the state of the buttons to the Minnowboard via USB (serial). How much current is Arduino drawing in this case?


texts: MEGA 2560: Simple program - One analogWrite turns off the other

texts:
I'm using Windows 10, Arduino 1.8.12 (Windows Store 1.8.33.0)

I have an Arduino MEGA 2560 and a red LED connected to pin 4.

#define RED 4
#define GREEN 2

void setup() {
  analogWrite(GREEN,  0);
  analogWrite(RED,  100);
}

void loop() {

}

This code lights up the red LED.

However, when I write 1 to the GREEN pin analogWrite(GREEN,  1), the red LED goes off. I'm expecting the red LED to stay on.

#define RED 4
#define GREEN 2

void setup() {
  analogWrite(GREEN,  1);
  analogWrite(RED,  100);
}

void loop() {

}

The red LED stays on when both written values are the same, e.g.

  analogWrite(GREEN,  25);
  analogWrite(RED,  25);

I also found that adding some "garbage" code at the beginning fixes the issue. I wasn't able to get the garbage into a simpler form without both pins shutting off.

#define RED 4
#define GREEN 2

void setup() {
  // GARBAGE BEGIN ===
  unsigned long t = millis();
  const unsigned long period = 10;
  float progress = float(t % period)/period;
  float r = progress * 0;
  // GARBAGE END ===

  analogWrite(GREEN,  100 + r);
  analogWrite(RED,  50 + r);
}

void loop() {

}

Update: Thanks all for your comments. Setting the pinMode to output did not fix the issue. However, changing the function declaration to __attribute__((optimize("-O0"))) void setup() { fixed the issue. -O1 also works, but -O2 fails.


texts:
I have a keypad like this:
here is another, closer look at the bottom part.
Basically, I want the LED to power the amount that I pressed.
this is my code:
int LED = 1;
int inputs[4] {
  6,
  4,
  2,
  0
};
int outputs[4] {
  13,
  12,
  10,
  8
};
void outputAllBut(short int);
int numberInputCheck();
int inputCheck();

void setup() {
  for (int i = 0; i < 4; i++) {
    pinMode(outputs[i], OUTPUT);
    pinMode(inputs[i], INPUT_PULLUP);
  }
  pinMode(LED, OUTPUT);
}

void loop() {
  while (true) {
    int x = numberInputCheck();

    if (x == 500) {
      break;
    }

    delay(500);

    for (int i = 0; i < x; i++) {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(300);
    }
  }
}

int numberInputCheck() {
  while (true) {
    for (int i = 0; i < 4; i++) {
      outputAllBut(i);
      for (int m = 0; m < 4; m++) {
        if (digitalRead(inputs[m]) == LOW) {
          switch (i) {
          case 0:
            if (m == 3) {
              return 500;
            } else {
              return m + 7;
            }
          case 1:
            if (m == 3) {
              return 500;
            } else {
              return m + 4;
            }
          case 2:
            if (m == 3) {
              return 500;
            } else {
              return m + 1;
            }
          case 3:
            return 500;
          }
        }
      }
    }
  }
}

void outputAllBut(short int b) {
  for (int i = 0; i < 4; i++) {
    if (i != b) {
      digitalWrite(outputs[i], HIGH);
    }
  }
}

int inputCheck() {
  for (int i = 0; i < 4; i++) {
    if (digitalRead(inputs[i]) == LOW) {
      return i;
    }
  }
  return 5;
}

for reference, the numberInputCheck function is the one that might go wrong here, I want it to wait for an input and return the number that I pressed. i is the rows and m is the columns.
My problem is that whenever I press the keypad at one of the numbers, it will give me a random amount of times that the LED turns on, there doesn't seem to be any pattern.
m+1, m+4 & m+7 is because m is my columns so if I press 0 and the row is 0 then I add 1, same goes with everything else. Can anyone help me?


texts: Gnd pins at the power pin strip VS Gnd pin at the IO pin strip

texts:
I noticed there are two Gnd pins at the lower pin strip, and another on the upper strip.
Is there a difference in their purpose?


texts:
I'm trying to call a function to keep an LED on for a certain amount of time. The function is called when the button is pushed but the LED stays on. I used the same code in the void loop before moving it into a function and it worked.

const int ledPin2 = 2;
const int buttonPin7 = 7;
const unsigned long onTime = 1000;
unsigned long previousMillis = 0;

//
void timer(){
    unsigned long currentMillis = millis();
    digitalWrite(ledPin2, HIGH);

    if (currentMillis - previousMillis >= onTime){
        digitalWrite(ledPin2, LOW);
        previousMillis = millis();
    }
}

void setup(){
    Serial.begin(9600);
    pinMode(ledPin2, OUTPUT);
    pinMode(buttonPin7, INPUT);
}

void loop(){
    int buttonState = digitalRead(buttonPin7);
    if (buttonState == HIGH) timer();
}


texts: Multiple variable shared between threads?

texts:
I got 4 threads running on ESP32 (dual core):

1 thread running on 1st core which is related to the WiFi.
1 thread running on 2nd core which is related to the touchscreen.
1 thread running on 2nd core which is related to the display.
1 thread running on 2nd core which is related to the sensors.

Some of the threads execute almost instantly, while for instance the one handling the sensors can take a few seconds per interaction, and no blocking should occur meanwhile for the rest of the threads.
Anyway, with the growing of the program, a lot of variables started to be involved in data transfers between the cores, and since the whole thing is about to be redone, I have the following questions, to clear the things up for myself, since I found quite a lot of confusing, even contradictory information in examples and explanations on the internet:

Is the "volatile" keyword really sufficient for exchange of data between threads (no ISR)?
Should "volatile" always be between "noInterrupts()" and "interrupts()", even when there is no ISR function?
What approaches should be used when exchanging a lot of variables between the threads (currently about 40 variables, but the number will probably grow)?
Is xQueueSend / xQueueReceive blocking in case it is put all around the threads with different variables?


texts: Help with LCD's menu and seeing values continuously

texts:
I want to see the voltage data using void volt();, when I go to the "Item2SubItem3" within void menuChanged. Now I can only see the data at that time: how can I refresh the value every second?

void setup()
{
    // setup()...
}

void loop()
{
    //loop()...
}

// DC Voltometer
float vPow = 4.7;
float r1 = 100000;
float r2 = 10000;

void volt()
{
    lcd.clear();
    float v = (analogRead(0) * vPow) / 1024.0;
    float v2 = v / (r2 / (r1 + r2));
    lcd.setCursor(0, 0);
    lcd.print("DC VOLTOMETER");
    lcd.setCursor(0, 1);
    lcd.print(v2);
    delay(1000);
}

void menuChanged(MenuChangeEvent changed)
{
    MenuItem newMenuItem = changed.to; // get the destination menu
    lcd.setCursor(0, 1);            // set start position for lcd
                                 // printing to the second row

    if (newMenuItem.getName() == menu.getRoot())
    {
        lcd.print("Main Menu       ");
    }
    else if (newMenuItem.getName() == "Item1")
    {
        lcd.print("Item1           ");
    }
    else if (newMenuItem.getName() == "Item1SubItem1")
    {
        lcd.print("Item1SubItem1");
    }
    else if (newMenuItem.getName() == "Item1SubItem2")
    {
        lcd.print("Item1SubItem2   ");
    }
    else if (newMenuItem.getName() == "Item2")
    {
        lcd.print("Item2           ");
    }
    else if (newMenuItem.getName() == "Item2SubItem1")
    {
        lcd.print("Item2SubItem1   ");
    }
    else if (newMenuItem.getName() == "Item2SubItem2")
    {
        lcd.print("Item2SubItem2   ");
    }
    else if (newMenuItem.getName() == "Item2SubItem3")
    {
        lcd.print("Item2SubItem3   ");
        delay(2000);
        volt();
    }
    else if (newMenuItem.getName() == "Item3")
    {
        lcd.print("Item3           ");
    }
    else if (newMenuItem.getName() == "Item4")
    {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Item4           ");
    }
}


texts: Does Linux have software protection on USB? Or has the magic smoke escaped?

texts:
I'm making a GUI in Python that will control an Arduino via serial monitor. I have 6 input pins grounded and I'm taking 5V from the board (powered from USB) whilst serial monitoring and everything's going beautifully.
I'm so impressed by all these flickering 0's and 1's that I drop my flying lead straight onto the tiny cap behind the USB connector on the UNO. Everything is definitely not going beautifully now.  My serial data is frozen mid-string.
I try to connect again with my serial monitor software:

Error: Could not open device /dev/ttyUSB0

Power off and on my PC and the Arduino, same result. So, I connect another board a nano this time.
The Arduino Web Editor recognizes that I have connected a Nano, but when I try to upload my code the Arduino Web Editor says this:

avrdude: ser_open(): can't open device "/dev/ttyUSB0": Permission denied

So, I put this in to terminal:
sudo chmod a+rw /dev/ttyACM0
chmod: cannot access '/dev/ttyACM0': No such file or directory
sudo chmod a+rw /dev/ttyusb0
chmod: cannot access '/dev/ttyusb0': No such file or directory

Thought I might have fried my USB but it's still accepting flash drives being plugged in, and I have connected to both front and back USBs with the same results. And I have power-cycled my PC.
So, not sure if I fried my Arduino, (but having 2 Arduinos with the same fault seems unlikely, especially as one was not attached when I dropped the flying lead).
Magic smoke escaped from my PC USB ports, but again it seems unlikely that front and back would be dead whilst allowing USB sticks to communicate.
Is there some kind of software fusing preventing communication that needs to be/can be reset? Or could something have become corrupted maybe?
I'm on Ubuntu 20. If anyone knows of a command I can give that will bring ttyusb0 back to life, that would be great.


texts:
I would like to ask if it is possible and how to connect the following module
http://www.ebay.com/itm/TOP-Mini-W5100-LAN-Ethernet-Shield-Network-Module-board-for-Arduino-Best-NEW-/251981053942?pt=LH_DefaultDomain_0&hash=item3aab3dbff6

to the arduino micro

I found some pin layouts but only for Leonardo or Ethernet shield, Uno etc.

Also I've choosen this model because it can be programmed directly in arduino using Sockets API


texts:
I am considering switching from Arduino Pro Mini 5V 16MHz to Arduino Pro Mini 3.3V 8Mhz for some project because I would like to run it with a 4.5V input power.

Will the switch from 16 to 8Mhz double the cycle time of my loop() function ?

Edit -- adding precision:
My loop function is simple: it's reading a couple of sensors with analogRead and setting a few pins to HIGH or LOW. It does not use delay().

Thanks.


texts: Need to set an output pin without it going LOW during initalization

texts:
For a control system I am using a relay module that controls a larger relay for high-current electrical stuff, as part of a battery protection circuit for my solar plant.  This module switches 120 VAC for the larger one.  The larger one is set up to latch the power off until a button is pressed manually.

I have several Adafruit relays, (single, dual, quad) and they all seem to be active-LOW.  I am using one of them for this project.

My problem is that I can't seem to prevent my Arduino Nano code from briefly setting the output pin LOW in setup, setting in motion the cascade involving latching the power off.

If at all possible with this hardware, I would like to prevent the need to manually reset the latch when uploading code changes.

Here is how I am initializing that pin in my setup code:

pinMode(12,OUTPUT); digitalWrite(12,HIGH);

All in one line.  The LOW pulse is just long enough to trigger the other relay.

I know I can probably find parts like an inverter chip or maybe a different relay, but really want this working yesterday.

So my question is:  Is there any way to prevent it from pulling it LOW during initialization?  Or, is there a different approach I should take in relation to this relay output?

Thanks in advance


texts: I just received an ESP8266 wifi module and I am trying to add the board. However I am having an issue. All websites/tutorials say to use http://arduino.esp8266.com/stable/package_esp8266com_index.json, however nothing is there. Can it be found somewhere else?


texts:
I have recently started working with the Arduino Pro Mini 5v/16Mhz and an AT 09 BLE module for an IoT project. I am controlling the BLE module using Software Serial and am leaving the hardware serial for for my laptop. I am using an app called "Serial Bluetooth Terminal" on Android to send/receive messages. The BLE module is able to receive messages and the "AT" command is also working. But when I try to get the BLE module to send a message, I get no response in the app. Any idea why this is happening and how can I resolve it?
My connections are:

Laptop -> Arduino UNO, MB-102(USB to breadboard power adapter)
Arduino UNO(without IC) Rx -> Pro mini Tx0
Arduino UNO(without IC) Tx -> Pro mini Rx1
Arduino UNO(without IC) RESET -> Pro mini Rst
MB-102 5V -> Pro Mini Pin RAW
MB-102 GND -> Pro Mini Pin GND
Pro Mini Pin 2 -> AT 09 TXD
Pro Mini Pin 3 -> AT 09 RXD
Pro Mini Pin VCC -> AT 09 VCC
Pro Mini Pin GND -> AT 09 GND

This is my code:
#include<SoftwareSerial.h>

SoftwareSerial ble(2, 3);

int statePin = 4;
char c;
void setup()
{
  Serial.begin(9600);
  ble.begin(9600);
  ble.print("AT\r\n");
  delay(100);
  while(!ble.available())
    Serial.print(".");
  while(ble.available())
  {
    Serial.print(char(ble.read()));
  }
}

void loop()
{
  while(ble.available() > 0)
  {
    c = char(ble.read());
    delay(10);
    Serial.print(c);
    ble.print(c);
  }
}

This is the first time I am posting here so please tell me if I missed out on any information.


texts: How to convert char[] to int with fail\success control?

texts:
this is more like C question, but i failed to google this.

i expect a command parameter in char[], but there may be no argument passed at all, so i need to try to parse this char[] to int and if there is garbage instead of a number, notify user.

i also need to be able to parse negative (with -sign char) numbers from char[].

how can i do this? thanks.


texts:
maybe this is a dumb question, but is there a way to test for wrong wifi password,

I know you can do WL_CONNECT to check if the password works, but is there a command for checking if the password is wrong? not just by waiting.


texts: Including Arduino library in a Makefile for Due

texts: I'm currently using a Makefile for the Arduino Due I've found on Github (with some modifications). It's useful to me cause it allows me to add a static library for cryptographic functions I need and I can't do it using the IDE. Now I need to include the WiFi library from Arduino but I don't know how. I've tried to put the path to the source (/usr/share/arduino/libraries/WiFi/src) but it gives me warnings saying that some classes are undefined. Does anyone know how to include that library?


texts: Where are these capacitors on the arduino schematic?

texts:
My arduino has these two capacitors

But I can't find any 47uf capacitors on the schematic. Is this not the value but instead a code? Where are these in the schematic?


texts: AC ceiling fan speed control using arduino Uno R3

texts: How can I control an AC ceiling fan speed using Arduino Uno R3? I cannot understand the key behind controlling AC voltage using Arduino (though I know how to on/off ac appliances using arduino and relays).


texts:
I'm writing code for Arduino that I plan to distribute. But I worry about piracy (the .HEX can extracted from the board and reuploaded to another).

With that in mind, I am storing data to the EEPROM.

Since I am storing data to the EEPROM, can the data be extracted in some way?


texts:
I am attempting to program an Arduino to interface with a DAC, specifically the AD7390 made by Analog Devices.

I have tried using the SPI library as a means of realising the interface but am confused by the PIN layout of the DAC. It provides me with SCK, SDI, CLR and LD pins.

The LD (Load Strobe) PIN is used to transfer buffers from the chip's on-board shift register to its DAC register.

The CLR PIN is used to forcibly clear the DAC register.

The documentation claims that the device is SPI compatible but, using these PINs with the Arduino Mega2560 as a micro-controller, only partially works and I am concerned that the circuit requirements of the SPI library are not being satisfied. In SPI documentation, a SS (slave select) PIN is universally mentioned but is not present with my device.

As I have managed to get the CLR PIN working, consistently and as expected, I wonder if a manual approach - i.e. using shiftIn() instead of the SPI library - is the way to go.

Any suggestions or advice would be appreciated.


texts: log STK500v2 commands while flashing a Mega

texts:
My final goal is to replicate the process with which the PC programs the arduino.
I have gone through the commands.h file and made a couple of attempts to get the logic right. But no success at flashing the arduino.
Is there any way to view the Hex commands that are written to the arduino from the PC? Something like verbose but list every hex command.
My idea is that I will just replicate the same commands and try uploading hex files from SD card.


texts: Trying to Pulse an LED a number of times outside of the main loop

texts:
I'm trying to call a class function that pulses an LED "x" number of times. I dont want to use a delay, which is making it tough. If I use a while loop, the LED just stays on. I attach an interrupt in the begin() - the location of the LED is pin 13

I call the following in my sketch like so:

robot.lights.pulse(0, 2000, 10000, 500); //in milliseconds

My goal is to pulse an LED "x" number of time at a rate I specify.

This is the code inside my class:

void StatusLights::begin(int locations[]){
    for(int i=0;i<NUM_OF_LIGHTS;i++){
        this->locations[i]=locations[i];
        pinMode(locations[i], OUTPUT);
    }

    ledState = LOW;
    previousMillis = 0;
    attachInterrupt(0, pulse_ISR, RISING);

};

void StatusLights::pulse(int location, int interval, int count, int speed){

    int value = 0;
    previousMillis = 0;
    // while(pulsecnt<count) {
        long currentMillis = millis();

        if (currentMillis - previousMillis >= interval) {
            previousMillis = currentMillis;
            value = 128+127*cos(2*PI/interval*(speed-currentMillis));
            analogWrite(locations[location], value);
        };
    // };
    // digitalWrite(locations[location], LOW);
};

void pulse_ISR() {
    pulsecnt++;
};

This is my first time using interrupts to do this - I'm really trying to avoid delays since i need other things to happen synchronously.

Thanks!


texts:
So I recently followed a tutorial on youtube and I've assembled the car and connected all the wires.

What I've done:
Car

Now in the video, when the guy connects all the wires, the wheels constantly turn while in mine they're completely still. Is this a problem? Is it an indicator of some connection issue or something else?

For context, here is the schematic:


texts: SPI.transfer(buffer, size) does not send data from buffer

texts:
I am having trouble getting SPI.transfer(buffer, size) to work as expected.

Here is the code:

// inslude the SPI library:
#include <SPI.h>

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;

uint16_t SPI_message = 0xABCD;

void setup() {
  // set the slaveSelectPin as an output:
  pinMode(slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();

}

void loop() {

  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
  SPI.transfer(0xEF);
  SPI.transfer(&SPI_message, 2);
  SPI.endTransaction();

  delayMicroseconds(300);

}

Here is the output of logic analyzer:

As can be seen the call for SPI.Transfer(0xEF) works as expected. However SPI.transfer(&SPI_message,2) sends 0x0000 instead of 0xABCD on the bus.

What am I doing wrong?


texts: Grounding Arduino UNO with external voltage source

texts:
I was experimenting with external power supplies and noticed that the only way the Arduino can communicate with an externally powered sensor (through SPI) is when the GND pin under power AND the GND pin under AREF on the UNO is connected to the external ground?
From what I understand, both these pins are connected to the boards mutual ground (i.e. they are already internally connected)?
In the attached image both the orange and yellow wires were required and would not work individually.
I feel that either this shouldn't be the case or I am simply missing something and would appreciate an explanation.
Thanks!


texts: How do I change fuse bits - not communicating?

texts:
Currently I'm working on a project using an ATmega 2560 microcontroller card with a 10 MHz crystal. My main goal is to use the Arduino IDE to upload sketches to this chip to run my bread board circuit. In the beginning I had planned to use Atmel Studio to upload Arduino Sketches, but I decided to go with the more direct route. I am using two programmers, the Atmel ICE, and the Atmel AVR ISP MKii.

Anyway, here is my issue. I tried to use the Arduino IDE and the MKii to burn the bootloader to the chip. However, it did not work. It uploaded, but I was at that point no longer able to communicate with the device. When I switched to Atmel Studio, and used the ICE programmer, my chip could not be read and recognized (whereas before it could). I can't even program it. (I had bought two.)

I then figured I would try and read the fuse bits on the other programmer and burn the bootloader using Atmel Studio (since the Arduino IDE has no information on this), and I looked up the proper bits to change and then burned the bootloader. It worked fine, and I then changed the fuse bits which resulted in an error and now I again could talk to the device.

I am guessing that something is going wrong with the suggested fuse bits, but I do not know how to change them or how to fix this. The original fuse bits that I read from the device are listed below (before I messed it up).

I checked my wiring a billion times and it is all perfect. I just need suggestions to fix this mess, thanks.

BODLEVEL = DISABLED
OCDEN = [ ]
JTAGEN = [X]
SPIEN = [X]
WDTON = [ ]
EESAVE = [ ]
BOOTSZ = 4096W_1F000
BOOTRST = [X]
CKDIV8 = [ ]
CKOUT = [ ]
SUT_CKSEL = INTRCOSC_6CK_0MS
EXTENDED = 0xFF (valid)
HIGH = 0x98 (valid)
LOW = 0xC2 (valid)
LB = NO_LOCK
BLB0 = NO_LOCK
BLB1 = NO_LOCK

LOCKBIT = 0xFF (valid)

Detected device
Device name       ATmega2560
Device signature  0x1E9801


texts: How to calculating requirements of power supply for a project

texts:
I am starting with electronics and been working with Arduino for some time now. I did some basic LED and servo motor project and was hoping to jump into making an obstacle-avoidance car. I used 4 AA batteries to make it, but the voltage was too low, as the motors were not moving. Then I knew about the volt requirements and all that. I also tried with a 9v alkaline battery, but it didn't help much.
Here are the electrical parts I used:

Arduino
Ultrasonic sensor
4 toy motor
1 hobby servo motor
Motor driver shield L293D
Battery

These are the operating voltages that I know of:

Arduino = 7 to 12 v
Hobby servo motor =  3.0V~ 7.2V
Toy motor = 3v ~ 12v dc; has a No load current 40 - 80 mA

Because AA batteries are of 1.5v and are in series, it has 6v, and I am assuming that was the reason it was not working as expected. What I am confused about is, how do I choose a battery or power supply to be specific.
Please forgive me for asking such a noob question. Since 1 Arduino + 4 toy motor  + 1 hobby servo motor = 7v + 4 x 12v + 7v = 62 v, but I checked and I couldn't find battery that is above 15v. I surely don't understand how to pick a power supply. Could you please help me out on how to calculate and choose the right battery/power supply? Also, what to look for if for example, I want to run it for a minimum of 10 minutes?


texts: ESP8266 - One server sending data to multiple clients

texts:
I have a few arduinos with ESPs, one of which is set up to measure temperature, and I'd like to have it send commands to other connected arduinos to perform various functions (open/close valves etc.)

In other words, the only communication I need is for one server to hopefully broadcast to a few clients. I don't really need to discern which client is which.

I am struggling to make sense of some of the documentation, and this is new to me.

For starters, I'm just trying to get any communication at all functional before I do the next parts.

My server device is set up as a soft access point and a WiFiServer.

My server ESP code looks a little something like this.

#include <ESP8266WiFi.h>

const byte ON = 2;
const byte OFF = 1;
int message;

WiFiServer server(80);

void setup()
{
  Serial.begin(9600);
  WiFi.softAP("access", "point");
  server.begin();
}

void loop()
{
    server.write(ON);
    delay(1000);
    server.write(OFF);
    delay(1000);
  }
}

My client code looks a little something like this:

#include <ESP8266WiFi.h>

const byte ON = 2;
const byte OFF = 1;

byte ip[] = {192, 168, 4, 1};
WiFiClient client;

int message;

void setup() {
  Serial.begin(9600);
  // connect to wifi.
  WiFi.mode(WIFI_STA);
  WiFi.begin("access", "point");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  //Now connect to server object
  if (client.connect(ip, 80) == 1) {
    Serial.println("Connected");
  } else {
    Serial.println("Not Connected");
  }
  delay(10000);

}

void loop() {
  if (client.connected()) {
    Serial.println("Waiting for Data");
    while(!client.available()){}
    String message = client.read();
    Serial.println(message);
  }
}

The client code does connect to the server, and get stuck at the "Waiting for Data" line, never getting out of the while (!client.available) loop, so it clearly isn't receiving anything.

I'm sure I must look super dumb here, can someone help me understand the proper way to do what I want to do? Stuff I have seen online is primarily client -> server communication, do I HAVE to ping the server with something in order to receive something back?

Any help is appreciated. This is for a big project and I hope that I can make it all work. Thank you all very much!


texts: Recently, I bought a "ThingPulse ESP2866 Wifi Color Display Kit". I bought the kit before reading the reviews and finally read them the other day. Some of the reviews seem fake but a couple of them say that the Wemos D1 mini pro is being used to "steal credit cards" and other information. The bad reviews claimed that when they plugged the wemos into a power source, a wifi network named "ESP_xxxxxx" appears and thats how their data is stolen. I plugged the Wemos that came in my kit to a power source and a wifi network starting with "ESP..." appeard. I was wondering if this is a valid concern or if its just conspiracy. I am not very informed on cybersecurity and data security so I thought this would be the best place to ask. Please let me know if you'd like anymore information.  Thank you!


texts: Save Leading Zero HEX into String RFID RC522 Arduino

texts:
I'm using RC522 to read RFID card. All is until if the HEX leading by 0 then i can't save it into String. But if i print it to Serial all is well. Here is my code:

#include <SPI.h>
#include <MFRC522.h>
#include <stdlib.h>

#define RST_PIN         9
#define SS_PIN          10

String inStringHex = "";

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
}

void loop() {
  // Look for new cards
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
  {
    //Serial.print("Card UID:");
    for (byte i = 0; i < 4; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
      Serial.print(mfrc522.uid.uidByte[i], HEX);
      inStringHex += String(mfrc522.uid.uidByte[i], HEX);
    }

    Serial.println();
    Serial.println(F("Hex normal"));
    Serial.print(inStringHex);
    Serial.println();
    Serial.println();

    inStringHex = "";
    delay(5000);
  }
}

Here is what displayed in serial monitor:

What i want is the String under "Hex normal" would be "04292e5a" not "4292e5a"

Please anyone help me.
Thank You.


texts:
I'am trying to apply USSD operation with variable codes, for example this piece of code return my account balance:

             gsm.SimpleWriteln("AT+CUSD=1,\"*100#\"");

i want to change "*100#" to variable so gsm.SimpleWrite uses what the variable contains. I want to find how to make it work like this:

             gsm.SimpleWriteln("AT+CUSD=1,\"Variable\"");

EDIT: here is my code to give you a better view. it return balance in serial monitor.

#include "SIM900.h"

  void setup()
    {
   Serial.begin(9600);
    Serial.println("GSM Shield testing.");
       if (gsm.begin(9600))
            Serial.println("\nstatus=READY");
      else Serial.println("\nstatus=IDLE");

         gsm.SimpleWriteln("AT+CUSD=1,\"*100#\"");
      delay(10000);
             char msg[200];
             gsm.read(msg, 200);
            Serial.print("resp: ");
            Serial.println(msg);
 }
    void loop()
     {

    }


texts: How to run my buzzer for few more seconds after switching off

texts: This is a basic level lazer alarm project. When anyone crosed or kept their hands on the lazer. buzzer starts working but when they took their hand from lazer light buzzer stops. But i want even after taking hands my buzzer should work for few (15-30) seconds .so please help me by giving idea..


texts: Arduinos using I2C reading integers wrong

texts:
I have two Arduino unos, and I am using I2C to have them communicate with each other. The A4, A5, and GND of each Arduino is connected to the other. These are my functions:

On the sending Arduino:

void playNote(int pitch, int len, int location){
  Serial.println(String(String(location) + ":" + String(pitch) + "," + String(len) + "\n"));
  Wire.beginTransmission(location);
  Wire.write(pitch);
  Wire.write(len);
  Wire.endTransmission();
}

On the receiving Arduino:

void receiveEvent(int howMany){
  int pitch = Wire.read();
  int len = Wire.read();
  Serial.println("Pitch: " + String(pitch) + ", Length: " + String(len));
  playNote(pitch,len);
}

pitch always sends fine. When I send len as 150, it works and is received as 150. However, when len is sent as 300, it is received as 44. I cannot figure out why this is. Any help is appreciated.


texts: Using an Arduino as the processor for a computer-mouse-like speed detector

texts:
I'm looking at making a pretty cheap and easy odometer, eventually for an electric car or similar vehicle.

My idea is to implement a big computer mouse, and track the speed with that: a computer mouse takes photos of the surface it is on, and finds the difference between sequential images in both the X and Y directions.

What I am wanting to do is to attach a downwards-facing camera; something like this, to the bottom of the vehicle, and use an Arduino Nano to do the image processing to achieve a result similar to a computer mouse.

I was wondering whether anyone knows of an libraries/documentation on anything similar, or if anyone has any pointers on reasons why this would not work, or ways it would work.

Thanks all.


texts: Can I design Arduino Mega 2560 circuit without adding ATMega 16?

texts:
I want to make Arduino Mega 2560 board.
As the reference files are given on Arduino Site, I don't want to add USB communication on the board.
So can I remove part of ATMega 16?
Will it cause any kind of problem in working of board?
And if It will fine to remove ATMega 16 part, How much part of schematic to be change?


texts: Storing data on AT24C02 EEPROM chips with Arduino

texts:
I have recently come across some  8-pin 128-byte EEPROM chips. I've seen those USB EEPROM chip programmer units, but I was wondering if there is any way I could manually store data on the chip with my Arduino.

I don't have any application for the chips yet, but I would just like to see if I can read / write data on the chips.

Here's the data sheet for the chips.


texts:
I'am getting a little PWM signal when my potentiometer is at zero and OCR2B always reads zero on the serial monitor.  My LED has low forward voltage but I still get a little PWM on the pin when I prob it. I use timer 1 and it works good. I have a picture of the scope.

#include "RTClib.h"
RTC_DS3231 rtc;

#include <ResponsiveAnalogRead.h>
ResponsiveAnalogRead analog0(A0, true, .001);

unsigned int nowHour;

int analogOutPin3 = 3;
int sensorValueTimer2Pin3;

long z;

int analogOutPin9 = 9;
int analogOutPin10 = 10;

void setup() {
  Serial.begin(9600);
  //===============mode 5 pin 3,11==================//
  TCCR2A |= (1 << COM2A1);
  TCCR2A |= (1 << COM2B1);
  TCCR2A |= (1 << WGM21);
  TCCR2A |= (1 << WGM20);
  TCCR2B |= (1 << WGM22);
  TCCR2B |= (1 << CS22);
  OCR2A = 249;   //1KHz frequency
  TCNT2 = 0;
  //====================mode 5 pin 3,11==============//

  pinMode(3, OUTPUT);

  rtc.adjust(DateTime(2014, 1, 21, 7, 0, 0));
}

void loop() {
  DateTime now = rtc.now();
  nowHour = now.hour();
  analogWrite(9, LOW);
  analogWrite(10, LOW);
  analog0.update();
  sensorValueTimer2Pin3 = ((analog0.getValue() * 249L) / 1024);
  if (nowHour >= 7 && nowHour <= 21) {
    z = sensorValueTimer2Pin3;
    OCR2B = z;
    Serial.println(OCR2B);
  }
}


texts: When it says the Uno has logic level at 5 V is that also true of a bareduino/breadboard Arduino?

texts:
I want to hook up ESP8266, which has a 3.3v logic level to my bare-bones Arduino (basically a minimal interface for the ATmega382P IC).

I can power my circuit at 3.3 V without a 5 V regulator so will the voltage of the logic level also be 3.3 V?

I don't think there is a tiny boost converter in the IC... but I'm uncertain.


texts: Flash size in boards.txt ATmega 328p 32u4

texts:
The ATmega328p and ATmega32u4 microcontroller have 32Kb of flash memory (as datasheet). Bootloader for each microcontroleer has different size (about 512 byte for 328p and 4kb for 32u4).

Why in boards.txt the "upload.maximum_size" parameters is 32256 for 328p and 28672 for 32u4?

I we have to consider bootloader size, the "upload.maximum_size" parameter for 328p must be about 31.5k and not 32k. And, if we do not have to consider bootloader size, as the default boards.txt configuration (above) for 328p, the "upload.maximum_size" parameter for 32u4 must be 32k not 28k. Correct?

Thank you


texts: attiny85 in sleep mode failing to wake properly

texts:
For my attiny85, I'm having trouble getting it to sleep and wake up cleanly.

I have a sleep mode with a watchdog timer that wakes every 8 seconds, or when interrupted. And then when that has repeated 4 times, a second sleep mode that doesn't wake unless interrupted. Interruptions are via a button press. But this waking up isn't happening they way I'd like.

I'm unsure how the ISR() is meant to used instead of my main loop.

#include <OneButton.h>

#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>    // Power management
#include <avr/wdt.h>      // Watchdog timer

ISR (PCINT0_vect)
 {

 }  // end of PCINT0_vect

// watchdog interrupt
ISR (WDT_vect)
{
   wdt_disable();  // disable watchdog
}  // end of WDT_vect

void setup ()
  {
     pinMode(0, OUTPUT);
  button.attachDoubleClick(doubleClick);
  button.attachPress(held);

  button.setClickTicks(250); //300
  button.setPressTicks(500); //800

   DDRB =  0b00000011;          // set PB1 (= OCR1A) to be an output
   setFrequency(38000);

  resetWatchdog ();  // do this first in case WDT fires

  // pin change interrupt (example for D4)
  PCMSK  = bit (PCINT2);  // want pin D2 / pin 7
  GIFR  |= bit (PCIF);    // clear any outstanding interrupts
  GIMSK |= bit (PCIE);    // enable pin change interrupts
  }  // end of setup

void loop ()
  {
    button.tick();

    sleepTimer++;

    if (sleepTimer > 240000)
    {
      goToSleepA ();
    }
    if (inactiveTick > 3) //
    {
     goToSleepB ();
    }
  }

////////////////////////////////////////////////////////////////
// Button click settings
//////////////////////////////////////////////////////////////

void doubleClick()

{

  inactiveTick = 0;

      four();
      delay(interPulsedelay);

  //checker light
   for(int a =0; a < 6;)
  {
    digitalWrite(0, HIGH);
  delay(50);
  digitalWrite(0,LOW);
  delay(50);
  a++;
  }

  clickFound = true;
  sleepTimer = 0;
}

void held()
{
  inactiveTick = 0;

      nine();
      delay(interPulsedelay);

  //checker light
  for(int a =0; a < 3;)
  {
  digitalWrite(0, HIGH);
  delay(100);
  digitalWrite(0,LOW);
  delay(100);
  a++;
  }

  clickFound = true;
  sleepTimer = 0;
}

////////////////////////////////////////////////////////////////
// sleeping functions
//////////////////////////////////////////////////////////////

///http://www.gammon.com.au/forum/?id=11497

void resetWatchdog ()
  {
  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset, clear existing interrupt
  WDTCR = bit (WDCE) | bit (WDE) | bit (WDIF);
  // set interrupt mode and an interval (WDE must be changed from 1 to 0 here)
  WDTCR = bit (WDIE) | bit (WDP3) | bit (WDP0);    // set WDIE, and 8 seconds delay
  // pat the dog
  wdt_reset();
  }  // end of resetWatchdog

void goToSleepA ()
  {

  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
  noInterrupts ();       // timed sequence coming up
  resetWatchdog ();      // get watchdog ready
  sleep_enable ();       // ready to sleep
  interrupts ();         // interrupts are required now
  sleep_cpu ();          // sleep
  sleep_disable ();      // precaution
  power_all_enable ();   // power everything back on
  inactiveTick++;
  }  // end of goToSleep

void goToSleepB ()
  {

    inactiveTick = 0;
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
  sleep_enable();
  sleep_cpu();
  sleep_disable();
  power_all_enable();    // power everything back on

  }  // end of goToSleep

That's the vitals of the sleeping code.

I'd be very grateful if anyone could shed a little light on the matter.


texts: ESP8266 + Arduino Uno: Can't send AT Commands

texts:
I'm trying to get the ESP8266 up and running without a FTDI chip, just my Arduino Uno. But it seems really difficult. What I did:

attach the ESPs VCC directly to Arduino Uno 3.3V; RX->TX; TX->RX

Result: surprisingly worked for 2 mins, however the AT commands returned ERROR sometimes. (baud rate: 9600)

attach the ESPs VCC to 3.3V 500mA power supply; RX->TX; TX->RX

Result: AT commands don't work anymore, nothing is displayed in the serial monitor, not even my input; red LED constantly on.

attach the ESPs VCC to 3.3V 500mA power supply; TX->TX; RX->RX

Result: blue LED constantly on, no response, same as before

change back RX/TX connection, experimenting with baud rate (300 - 115200)

Result: blue LED flashes on start, flashes when something is sent (no matter what the baud rate is), however still no output at all.

Suddenly, I was also getting this error while uploading:

  ser_recv(): programmer is not responding

Detaching the TX connection solved the problem. Btw, I am also using a voltage divider between TX of the Arduino and RX of the ESP.

Afterwards, the blue LED was on constantly again, even though I haven't changed the wiring... (really weird)

To me it looks like the Arduino Serial monitor isn't sending anything, because I don't even see my input. However, the Arduino can output stuff, therefore I assume a connection between Arduino and PC is existing. Maybe it has to do with the connection between TX -> RX, but I see no shorts, just an ordinary voltage divider (100 Ohm and 200 Ohm resistors).

As you might see, I spent a lot of time trying to figure this out. I'm kind of stuck now, as I'm not sure what else to try. If you have any ideas, tips or advice please leave an answer.

Sorry for my English, it's not my native language. If you don't understand something, feel free to ask.

Hope you can help me!


texts:
For a few days now, I have been connecting to my board which is hooked up to my router through a clutter of wires, over Wi-Fi. To spare my family from the risk of tripping, or hogging the extension cords all to myself, I'm looking for a way to establish an ssh connection directly from my computer (either via a USB Ethernet or a Thunderbolt Ethernet adapter).
My question is what address will I be looking for? Is it something like arduinoname.local?


texts:
I have a sensor giving me values (ints) which I want to keep, and send to a computer via the WiFi shield when requested via HTTP. I have the HTTP thing working, however, I do not know how to have a String or whatever able to store what is basically an array of ints, when I do not know any maximum size.

I have read that using Strings on Arduino is not recommended because how RAM works and such things, so I translated all my String uses to C-style arrays (as it was recommended), this solved my memory issues, however, C-style strings are not resizable.

While browsing the forums, I found that for similar problems the recommended way of handling things would be to create an array of max size instead of dynamically growing the array, but I do not know the maximum size in this case.

Here are the requirements

A way of storing each values (in order) so they can be sent later after an HTTP request (but they can get requested multiple times so I can't delete them then),
Whatever storage way is fine by me (Strings, arrays of ints, ...), as long as it works.
A request to the data should take ~100ms (I don't think this will cause issues, but I'll mention it just in case).

I thought about printing the values to the SD card, since there I have far enough memory, but for some reason I can't get the WiFi and the SD card to work together (as soon as I init the SD library, the WiFi library doesn't work anymore - I asked an other question about this here).

PS.
I'm quite new to C++ and Arduino, but I'm not too bad at Java.

What would be the best (or at least a working one) way of achieving this ?


texts:
So I'm trying to read a bit of data via SWD. I've tried two chips as target - LPC1110 and STM32F030F4 (the first of them I used for other schematic, but I've reset the flash to make sure the pins are not configured improperly).

I use Arduino as a host. I wire D3 to SWCLK and D4 to SWDIO (with pull-up to 3.3V line). I fail miserably with both chips - i.e. when I expect some ACK be read - it only shows HIGH state on the line all the time.

Here is my code. Could anyone have a look and tell where I went wrong:

int swdck = 3;
int swdio = 4;

void setup() {
  pinMode(swdck, OUTPUT);
  digitalWrite(swdck, HIGH);
  pinMode(swdio, INPUT);
  digitalWrite(swdio, HIGH);
  Serial.begin(9600);
}

// write some bits from X (least significant first) to SWD
void clockOut(int x, int bits) {
  pinMode(swdio, OUTPUT);
  while (bits > 0) {
    digitalWrite(swdck, LOW);
    digitalWrite(swdio, (x & 1) ? HIGH : LOW);
    delay(1);
    digitalWrite(swdck, HIGH);
    delay(1);
    bits--;
    x >>= 1;
  }
  pinMode(swdio, INPUT);
  digitalWrite(swdio, HIGH);
}

// read some bits from SWD, least significant first
int clockIn(int bits) {
  pinMode(swdio, INPUT);
  digitalWrite(swdio, HIGH);
  int i, res;
  res = 0;
  for (i = 0; i < bits; i++) {
    digitalWrite(swdck, LOW);
    delay(1);
    if (digitalRead(swdio) == HIGH) {
      res += (1 << i);
    }
    digitalWrite(swdck, HIGH);
    delay(1);
  }
  return res;
}

void loop() {
  int x;
  // unlock sequence though it probably is not needed
  clockIn(26); clockIn(26); // more than 50 clocks
  clockOut(0xE79E, 16); // command to switch to SWD
  clockIn(26); clockIn(26);

  clockOut(0x25, 7); // 0b0100101 - request to read Debug-port-0, i.e. ID
  x = clockIn(5); // there should be ACK bits somewhere... but I get 0x1111
  clockIn(26); clockIn(26); // perform more readings for case anything is returned
  Serial.println(x);
  delay(1000);
}


texts:
I am a beginner trying to upload the SimpleExample328.ino sketch on my Arduino Uno. When I verify my sketch however, I run into the error:

  'AttachPinChangeInterrupt' was not declared in this scope.

I would assume the header file PinChangeInt.h is not in the correct location; currently the PinChangeInt folder (that contains PinChangeInt.h) is placed in the Arduino IDE libraries folder, which I believe is the correct location.

Did I place the header file in the wrong location or does this error result from another cause? Thanks :)


texts: ATTiny85 Serial communication with Bluetooth Module

texts:
For a simple project I would like to use a ATTiny85 connected to a HC-06 Bluetooth Module so it can talk to my Android phone.
I wrote a code for my Arduino Uno and worked as expected. When I changed the code to use on my ATTiny85 I got an error saying that 'Serial' was not declared in this scope and assumed that the ATTiny does not support Hardware Serial.
I need to read a String when received and sleep the MCU when not receiving. I went to use SoftwareSerial and was not able to get a String, just the first char.
I approached it in some was, like defining a char string[10]; as global and string[i] = mySerial.read(); i++; inside the loop, but it keeps not working. Whether it is the sleep, or my work to read data, I couldn't make it work.
Can someone provide a way to put a ATTiny85 to sleep, wake up to receive a String through Serial and sleep til the next data through Serial, please?

To sleep I'm using

void sleep() {
  GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
  PCMSK |= _BV(PCINT3);                   // Use PB3 as interrupt pin
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
  sei();                                  // Enable interrupts
  sleep_cpu();                            // sleep

  // woke up
  cli();                                  // Disable interrupts
  PCMSK &= ~_BV(PCINT3);                  // Turn off PB3 as interrupt pin
  sleep_disable();                        // Clear Sleep Enable bit

  sei();                                  // Enable interrupts
}

ISR(PCINT3_vect) {

}

And my loop is something like

char inputString[10];
int i = 0;

void loop() {
  sleep();

  if (serial.available() > 0) {
    char inputChar = serial.read();
    if (inputChar == '2') {    //Char to break
      //Do something and reset i
    } else {
      inputString[i] = inputChar;
    }
    i++;
  }
}

Thanks to all.


texts: Unable to use Keyboard library with Arduino UNO even after changing the firmware

texts:
So I'm trying to use my UNO as an HID device. I followed this tutorial, flashed the firmware and got the UNO to be detected as an HID device.

However, I am still getting the error

  'Keyboard' not found. Does your sketch include the line '#include '?

Here's the code -

/*
Copyright (c) 2014 NicoHood
 See the readme for credit to other people.

 Keyboard example
 Press a button to write some text to your pc.
 See official documentation for more infos
 */

// include HID library
#include <HID.h>

const int pinLed = 13;
const int pinButton = 8;

void setup() {
  pinMode(pinLed, OUTPUT);
  pinMode(pinButton, INPUT_PULLUP);

  // Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
  // This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
  Serial.begin(115200);

  // Sends a clean report to the host. This is important because
  // the 16u2 of the Uno/Mega is not turned off while programming
  // so you want to start with a clean report to avoid strange bugs after reset.
  Keyboard.begin();
}

void loop() {
  if (!digitalRead(pinButton)) {
    digitalWrite(pinLed, HIGH);

    // Same use as the official library, pretty much self explaining
    Keyboard.println("This message was sent with my Arduino.");
    Serial.println("Serial port is still working and not glitching out");

    // simple debounce
    delay(300);
    digitalWrite(pinLed, LOW);
  }
}

/*
Definitions:

 KEY_LEFT_CTRL
 KEY_LEFT_SHIFT
 KEY_LEFT_ALT
 KEY_LEFT_GUI
 KEY_RIGHT_CTRL
 KEY_RIGHT_SHIFT
 KEY_RIGHT_ALT
 KEY_RIGHT_GUI

 KEY_UP_ARROW
 KEY_DOWN_ARROW
 KEY_LEFT_ARROW
 KEY_RIGHT_ARROW
 KEY_BACKSPACE
 KEY_TAB
 KEY_RETURN
 KEY_ESC
 KEY_INSERT
 KEY_DELETE
 KEY_PAGE_UP
 KEY_PAGE_DOWN
 KEY_HOME
 KEY_END
 KEY_CAPS_LOCK
 KEY_F1
 KEY_F2
 KEY_F3
 KEY_F4
 KEY_F5
 KEY_F6
 KEY_F7
 KEY_F8
 KEY_F9
 KEY_F10
 KEY_F11
 KEY_F12

 KEY_PRINT
 KEY_SCROLL_LOCK
 KEY_PAUSE
 */

Can anyone point out what I'm doing wrong here?


texts: Arduino Serial.write sending more than 64 bytes

texts:
I am using an Arduino Due to collect a large amount of data from an encoder (about 1kb). Afterwards I need to send the collected data to a C# application I wrote over the serial port. I serialized my tx data into a byte buffer and simply used this code to transmit:

void sendEncoderData()
{
  byte buffer[1024];

  /*** some code that populates buffer ***/

  int bytesToSend = 1024;
  Serial.write(buffer, bytesToSend);
}

When I run the code, nothing seems to get received by the C# application. In fact, I never see the Tx LED light up. However, if I change bytesToSend to a value smaller than 64 bytes everything works. Is this a limitation of Serial.write() or is it something else? What are ways I can work around this limitation?

More information： sendEncoderData() is called by an interrupt service routine. However prior to the call, I made sure to 'detachInterrupt()` on all pins including the pin associated with said ISR.


texts: Unable to connect and configure ESP8266 wifi module with Ardunio Mega

texts:
I try to connect Ardunio Mega with ESP8266 wifi module. Wiring diagram mentioned below:

I am using Ardunio IDE - For AT command test I was open COM monitor and selected 115200 baud rate and set to Both NL & CR.

But no response from ESP8266 wifi module. Response like "System read Vendor". I have changed different baud rate. But no use of it.

I don't know what I am missing out.

Please help on this.

Thanks,
Shanmuga Raja


texts: Connecting multiple TFT panels to Arduino Uno via SPI?

texts:
Is it possible to connect more than one TFT screen (like this one or similar: https://www.adafruit.com/products/1651) to an Arduino Uno?

I'm wanting to connect and control two color screens at once; note the touch functionality of the one linked above isn't really necessary, I just like the size and overall build. They have a version that works like a shield and sits on top of the Arduino, which would work I suppose if I bought another unit for the other screen. The breakout board version is more flexible but I don't know of a way to control two screens that require that many pins.

Any suggestions?
Thanks


texts:
I am using GPRS Shield for Arduino Uno with SIM900 module on it. I am able to communicate with the module just fine (using AT commands), but whenever I try to use a command which involves sim card (like AT+CCID) I get a message saying ERROR and that's it (while AT+CCID=? returns OK as it should).

So I wanted to ask can it be that I am missing out on some parameter on SIM900 module that would allow using sim card? And is it possible somehow to do a hard reset on all module's parameters (in the documentation a command ATZ is mentioned, but it doesn't seem to reset all parameters)?

Thanks in advance!


texts:
I'm trying to flash a Wemos D1 mini ESP8266 board with the blink sketch, but get an error. The built in LED turns off when flashing starts.

Sketch uses 247872 bytes (23%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28000 bytes (34%) of dynamic memory, leaving 53920 bytes for local variables. Maximum is 81920 bytes.
warning: serialport_set_baudrate: baud rate 921600 may not work
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

I tried changing the programming speed to most of the other options.

If I open the serial monitor and set the baud rate to 74880, I get the following message repeatedly.

Fatal exception (0):
epc1=0x400cd530, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Is the board dead, or is there a way of reflashing it without using the serial port?


texts: Stepper motor controlled with joystick wont spin anti-clockwise

texts:
Im trying to get my Stepper-motor to spin clockwise when joystick is pulled to one side and anti-clockwise when pulled to the other side. Problem is the motor only spins clockwise in both cases. Here is the code, hope it is not too messy. i was hoping putting stepper.step(-1); instead of stepper.step(1); would help but no.
Using ULN2003 Stepper motor driver board. When i try with other codes it can spin anticlockwise, so im guessing its something wrong with my code but i have been stuck at this for days and i would appreciate some help with it.
Thanks!

#include <Stepper.h>
int step_in1=A2; //Defining Drivers pins to Arduino board
int step_in2=A3;
int step_in3=A4;
int step_in4=A5;
int STEPS=32;
bool direction=true; //direction, false is clockwise, true is counterclockwise
Stepper stepper(STEPS,step_in1,step_in2,step_in3,step_in4);
int joystick_y=A0;
int joystick_x=A1; // joystick's x-value is the one controlling servo-motor
int joystick_sw=2; //joystick's button
void setup()

{
pinMode(step_in1,OUTPUT);
pinMode(step_in2,OUTPUT);
pinMode(step_in3,OUTPUT);
pinMode(step_in4,OUTPUT);
pinMode(joystick_y,INPUT);
pinMode(joystick_x,INPUT);
pinMode(joystick_sw,INPUT);
Serial.begin(9600);
stepper.setSpeed(40);
stepper.step(100); //testing if the motor spins clockwise, then anti-clockwise, however it only spins clockwise still
delay(100);
stepper.step(-100);
}

 void loop()
 {

   int joystick_xvarde=(analogRead(joystick_x));
   int joystick_yvarde=(analogRead(joystick_y));
   if ((joystick_xvarde>500) && (joystick_xvarde <525))
   {
     digitalWrite(step_in1,LOW);
     digitalWrite(step_in2,LOW);
     digitalWrite(step_in3,LOW);
     digitalWrite(step_in4,LOW);
   }
     while(joystick_xvarde >= 525)
      {
        int speed_=map(joystick_xvarde,525,1023,5,500);
        stepper.setSpeed(speed_);
        stepper.step(1);
        joystick_xvarde=analogRead(joystick_x);
        Serial.println("a"); //prints "a" if it reaches the while loop, which it does
        Serial.print(speed_); //prints speed ~ 430a
      }

      while(joystick_xvarde <= 500)
      {
          int speed_=map(joystick_xvarde,500,0,5,500);
          stepper.setSpeed(speed_);
          stepper.step(-1);
          joystick_xvarde=analogRead(joystick_x);
          Serial.println("b"); //prints "b" if it reaches the while loop, which it does
          Serial.print(speed_); //prints speed ~ 430b
      }
 }

Here is an example code i found in the Arduino IDE and copied straight of, which says it should first rotate clockwise, delay, then anti-clockwise. However it still just spins clockwise in both cases. Could i be something wrong with the motor driver board itself?

#include <Stepper.h>
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}


texts:
My intention was to overload a function to handle optional parameters. My code looks like

void functionA(const char *errorMsg) {
  functionA('0', errorMsg);
}

void functionA(char errorCode, const char *errorMsg) {
    ...
}

The line functionA('0',... generates the error

invalid conversion from 'char' to 'const char*'

How do I fix that?


texts:
I am trying to make pins 13, 12, 10 and 9 to switch between high and low. That is, when pin 13 is high, pin 12 should be low, then pin 10 should be high and pin 9 should be low.

Code:

 unsigned char driver[4] ={13, 12, 10, 9};
 String mystring = "";
 void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   for(int i = 0; i < 4; i++){
     pinMode(driver[i], OUTPUT);
   }
 }

 void backward(){
   digitalWrite(driver[0], HIGH);
   digitalWrite(driver[1], LOW);
   digitalWrite(driver[2], HIGH);
   digitalWrite(driver[3], LOW);
 }

 void forward(){
   digitalWrite(driver[0], LOW);
   digitalWrite(driver[1], HIGH);
   digitalWrite(driver[2], LOW);
   digitalWrite(driver[3], HIGH);
 }

 void STOP(){
   digitalWrite(driver[0], LOW);
   digitalWrite(driver[1], LOW);
   digitalWrite(driver[2], LOW);
   digitalWrite(driver[3], LOW);
 }

 void loop() {
   // put your main code here, to run repeatedly:
   while(Serial.available()){
     delay(10);
     char mychar = Serial.read();
     if(mychar == '\0')
       break;
     mystring += mychar;
   }

   if(mystring == "F" || mystring == "f"){
     forward();
     mystring = "";
     Serial.println("moving forward!");
   }

   else if(mystring == "B" || mystring == "b"){
     backward();
     mystring = "";
     Serial.println("moving backward!");
   }

   else if(mystring == "S" || mystring == "s"){
     STOP();
     mystring = "";
     Serial.println("stopped!");
   }

   else
     mystring = "";
   }

When I test it, there is no switching, that is when moving backward, pin 13 is high throughout, pin 12 is low throughout, pin 10 is high throughout, and pin 9 is low throughout


texts: How to do I2C on Arduino with SDA and SCL pin already used

texts:
i have a Arduino screwshield from sparkfun that I purchased: https://www.sparkfun.com/products/9729 which I used to put between my arduino uno and my 2.8" TFT LCD touch shield so that I am able to use the unused pins. I have to make an I2C connection between 2 Arduino Unos which I understand will require the A4 and A5 pins however the TFT currently uses both pins. also, my tft screen is from here: https://www.sgbotic.com/index.php?dispatch=products.view&product_id=2756

The schematics of my tft are: http://www.sgbotic.com/products/datasheets/development/02756-schematic.jpg .

I am wondering if I can just use the A4 and A5 pins using the screw shield anyway since according to the schematics, the A4 pin is connected to the LCD_RST or is the pin necessary for displaying images taken from the SD card?
If that isn't the way, how should I go about doing it, does anyone know?


texts: send images from Arduino Uno to raspberry pi

texts: I am a new to work with ov7670 camera module and Arduino . please let me know whether it could be possible to send images captured from ov7670 module with Arduino Uno to Raspberry pi??


texts: Is this a good function for I2C receive?

texts:
I'm trying to fix my I2C code:

Is the following function correct because it has multiple returns. I don't know if that would work.

uint8_t I2C_rx(uint8_t ack_rx)
{
    uint8_t i;
    if (ack_rx)
    {
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA); // sending ACK
        while (!(TWCR & (1<<TWINT)));
        return TWDR;
    }
    else
    {
        TWCR = (1<<TWINT)|(1<<TWEN);           // sending NACK
        while (!(TWCR & (1<<TWINT)));
        return TWDR;
    }
}


texts: Can't get values of max232 with loopback

texts:
I didn't find answers which solves my problem with the max232 yet.
I connected it like this to my Arduino uno, so my Arduino provides the +5V VCC and the ground:
max232 connection

The only thing what is differences are that I do a loopback at the RS232 side and I use 1µF for every capacitor even for the bypass one. I did a loopback so I can see if the max232 works. I don't get anything out of it when I send some data to it.
I measure +8.7V on pin2 and -8.15V on pin 6.

My Arduino code:

/*
  Software serial multiple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.print(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

What did I do wrong or is my max232 broken?

EDIT

I think the serial monitor (same baudrate) doesn't write to the ports so I rewrite some code.

loop code:

int i = 0;
void loop() // run over and over
{
  if(i == 10)
    i = 0;

  mySerial.write(i);
  Serial.print(mySerial.read());
  i++;
  delay(3000);
}

In serial monitor I get strange values back for a cascade counter.

Values:
-1 45 49 52 53 52 57 53 ...

These numbers aren't ascii code for ectual numbers I think.

EDIT 2

Now the loopback works thanks to the answer below.
Now I replaced the loopback with the module FUM DCF-U.
The loop code has changed to this:

void loop() // run over and over
{
  if(Serial.available())
    Serial.println(Serial.read());
}

The problem is that the result is '000000000000000000000000000000000...' in a fast rate and not every second.

The module gets its 3.3V and is connected to the same GND as the MAX232.

Pin connections:

Arduino - MAX232

11 - 11

0 - 12

MAX232 - FUM DCF-U

14 - 3

13 - 4

Thanks in advance


texts: double type sensor data is not displayed on bluetooth terminal app on phone

texts:
Hi I am working on a project in which I am supposed to tell if a person is running/standing/walking and going upstairs/downstairs or he is on straight road. The person will carry a arduino uno module to which gps,bluetooth and altitude sensor is attached. Also I am trying to send my phone his speed and current altitude he is experiencing using HC-05 bluetooth module. I am sure that there is no problem with altitude sensor. Also I must note that my gps module(GY_NE06MV2) is not acting proper when it comes to speed of the person. I believe this is because I experimented in my house and not outside. The problem is that I cannot see speed and altitude data on bluetooth terminal app"ArduTooth" on my phone. It is just like a blank space which should have been my data. I am presenting my code which is not very long and I hope you could help me get through this.
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

TinyGPSPlus gps; //gps object to be used
SoftwareSerial BTserial(10, 11); //bluetooth serial connection
SoftwareSerial gps_serial(4,3); //gps serial connection
Adafruit_BME280 bme; //altitude measuring sensor object

#define SEALEVELPRESSURE_HPA (1011) //sea level pressure in Turkey/Eskisehir

double speed = 0; //speed of a moving body
double current_altitude = 0;
double previous_altitude = 0;

void setup() {
Serial.begin(115200); // serial connection to computer
BTserial.begin(9600);
gps_serial.begin(9600);
bme.begin(0x76);

delay(3000);

previous_altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);

}

void loop() {
//data from gps device is fed to gps object
while (gps_serial.available() > 0){
    gps.encode(gps_serial.read());
}

if(gps.speed.isValid()){
speed = gps.speed.kmph();
BTserial.write(speed); // this is where the problem-1 is, this data is not shown on mobile phone
bluetooth terminal application
BTserial.write(",");

  if(speed <= 5 && speed > 0.5){
    BTserial.write("walking");
    BTserial.write(",");
  }
  if(speed <= 0.5){
    BTserial.write("standing");
    BTserial.write(",");
  }
  if(speed > 5){
    BTserial.write("running");
    BTserial.write(",");
  }

  }else{
    BTserial.write("m.s.n.n"); //stands for "moving status not known"
    BTserial.write(",");
  }

current_altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
BTserial.write(current_altitude); //this is where problem-2 is, this data also is not displayed
on phone
BTserial.write(",");
//this part determines either the body goes upstairs or downstairs or he is on straight road
if(current_altitude - previous_altitude >= 0.7){
  BTserial.write("going ups.");
  previous_altitude = current_altitude;
}
if(previous_altitude - current_altitude >= 0.7){
  BTserial.write("going downs.");
  previous_altitude = current_altitude;
}
if((current_altitude - previous_altitude <= 0.3) || (previous_altitude - current_altitude <=
0.3)){
  BTserial.write("on s.r");
  previous_altitude = current_altitude;
}
BTserial.write(";");

delay(1000);

}

I must note that purpose of BTserial.write(",");  is that every seperate entry sent to phone via bluetooth must be seperated by ",".


texts: SparkFun Monster Moto Shield current sensing issue

texts:
I am using a SparkFun Monster Moto Shield (PDF) for driving two DC motors. The shield is working fine and I am able to drive the motor in both directions. However, the current sensing is continuously showing "zero" in the serial monitor.

I am confused why the shield is not measuring any current. I want to measure normal current of 750 mA and stall current of 6 A but I'm getting zero value continuously. If anyone can help me I shall be very thankful.


texts:
I'm working on a project, where I will have 2 red light beams, where one will be constantly turned on while the other will be turned on and off continuously with frequency about 100 hz.
I need to detect, on which side is the blinking beam and show it on the output (something such as if the blinking beam is on the left, turn green LED on; if it's on the right side, turn on the red LED). Each beam is big as 3mm circle.

I bought 3pcs (in case if I burn 2 of them :D) of Toshiba TCD1304 sensors(datasheet), which have 3684 elements in a row. I want to connect the sensor with Arduino, but I really don't know how I would even start this project. I've found some schematics, but it's either for some other model or is for different kind of a project(reading different colors over the field). Either way, none of them is useful for me.

It will look something like that at the end (the blue circle will be also red, but it's striped to show, it's the blinking one).


texts: Programming Other Atmel chips using Arduino

texts: Is it possible to burn Arduino code on any other third party Atmel products using an another Arduino ? And if its possible then how ?


texts: Arduino Project - Social distance detector

texts: I am trying to make a social distance detector for a project of mine. There are many projects online about this, but none of them are the right ones. I'm trying to make a thing that attaches to a lanyard. My original plan was when a PIR sensor detected a human, it would trigger the ultrasonic sensor into measuring the distance between the lanyard and the human. The problem is, the PIR sensor was always displaying "high", and after doing some research, a PIR sensor can be only stationary. I am wondering if there are other easy and cheap options other than PIR sensors that can detect humans accurately? Thanks!


texts: Not able to build program with arduino program under clion

texts:
I'm pretty new to arduino and I just downloaded clion and installed the arduino plugin so I have an IDE that I'm used to. Here is my code:
#include <Arduino.h>

// Time between a switch indicating not full and the time a valve is opened
#define SWITCH_DELAY 5000

#define PIN_SWITCH 2
#define PIN_GREEN 3
#define PIN_YELLOW 4

#define INT16 int
#define UINT16 unsigned int
#define UINT32 unsigned long

DelayChecker    degassingChecker(PIN_SWITCH, PIN_GREEN);

void setup() {
    pinMode(PIN_SWITCH, INPUT);
    pinMode(PIN_GREEN, OUTPUT);
    pinMode(PIN_YELLOW, OUTPUT);

    Serial.begin(9600);
    Serial.print("UINT16: " + sizeof(UINT16));
    Serial.print("UINT32: " + sizeof(UINT32));
}

void loop() {
    UINT32 now = millis();

    degassingChecker.check(now);
}

public class DelayChecker {
    private:
        UINT32 delayExpires = 0;
        UINT16 switchId = 0;
        UINT16 solenoidId = 0;
        bool solenoidOn = false;

    public:
        DelayChecker(const unsigned int sw, const unsigned int sol) {
            switchId = sw;
            solenoidId = sol;
        }

        void check(const UINT32 now) {
            if (delayExpires == 0) {
                INT16 switchState = digitalRead(switchId);
                if (switchState == LOW) {
                    delayExpires = millis() + SWITCH_DELAY;
                    digitalWrite(PIN_YELLOW, HIGH);
                }
            }
            else {
                if (now >= delayExpires) {
                    INT16 switchState = digitalRead(switchId);
                    if (switchState == LOW) {
                        if (!solenoidOn) {
                            digitalWrite(solenoidId, HIGH);
                            solenoidOn = true;
                        }
                    }
                    else {
                        if (solenoidOn) {
                            digitalWrite(solenoidId, LOW);
                            solenoidOn = false;
                        }
                    }
                }
            }
        }
};

I hit the run button and get the following.
====================[ Build | untitled1 | Debug ]===============================
/opt/clion/bin/cmake/linux/bin/cmake --build /home/thomas/CLionProjects/untitled1/cmake-build-debug --target untitled1 -- -j 12
[  7%] Building C object CMakeFiles/uno_CORE.dir/opt/arduino-1.8.13/hardware/arduino/avr/cores/arduino/wiring_pulse.c.obj
[  7%] Building CXX object CMakeFiles/uno_CORE.dir/opt/arduino-1.8.13/hardware/arduino/avr/cores/arduino/new.cpp.obj
[ 10%] Building C object CMakeFiles/uno_CORE.dir/opt/arduino-1.8.13/hardware/arduino/avr/cores/arduino/wiring_shift.c.obj
/opt/arduino-1.8.13/hardware/arduino/avr/cores/arduino/new.cpp:29:46: error: expected initializer before 'noexcept'
 void * operator new(size_t size, void * ptr) noexcept {
                                              ^~~~~~~~
gmake[3]: *** [CMakeFiles/uno_CORE.dir/build.make:317: CMakeFiles/uno_CORE.dir/opt/arduino-1.8.13/hardware/arduino/avr/cores/arduino/new.cpp.obj] Error 1
gmake[3]: *** Waiting for unfinished jobs....
gmake[2]: *** [CMakeFiles/Makefile2:99: CMakeFiles/uno_CORE.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:133: CMakeFiles/untitled1.dir/rule] Error 2
gmake: *** [Makefile:151: untitled1] Error 2

It looks like an error in the libraries. Has anyone seen anything like this?


texts: Read analog signal over the SPI bus using MCP3201 ADC and Arduino Uno

texts:
It is possible to use the SPI bus when the Vref of MCP3201 ADC is 2.5V?
On the setup i just finished, I used two linear regulators: 5V -> 3.3V to power the MCP602 op-amps and MCP3201 ADC, and another one 5v -> 2.5V for the Vref.
Everyone recommends to connect the Vref from MCP3201 to Arduino's 5V but this does not apply in my case.

The green connector is connected to GND and ADC's Dout where the measured voltage fluctuates from 0.180V when i touch the sensor and his shield, to 0.6V when i'm not touching those parts.
I have no ideea if this is a normal behaviour but everything looks fine to me.
Voltage measured at the output of A4 ( MCP3201 +IN ) is 0.85V and the current Iref is 1mA(through the yellow jumper) as they recommend.

Sorry if these details are a bit off-topic but i think they are relevant to the ADC role in this setup.


texts: How to reduce serial speed on Arduino bootloader (optiboot) and on the IDE?

texts:
I'm debugging a couple of RS232-to-TTL converter boards that I'm trying to use to program my Arduinos and one thing I would like to try would be to reduce the upload serial speed from 115200 to 19200.

How do I do that?

I imagine that there's a setting that can be easily changed on the Arduino IDE preferences. But where is it? But then the bootloader speed would have to match that? How do I change the serial upload speed on optiboot, too?


texts: Built-in LED turns on when I touch the input port

texts:
I'm a beginner. I bought a new Arduino and I uploaded the basic example button code.

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

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

But the problem is that when I touch port 2 the output is getting so I changed the port number 2 to 3 even though without any supply the output is getting on.

Give me some suggestion.


texts:
I dont know what to do?

Sketch uses 3712 bytes (12%) of program storage space. Maximum is 30720 bytes.

Global variables use 210 bytes (10%) of dynamic memory, leaving 1838 bytes for local variables. Maximum is 2048 bytes.

Program:

String texto;
int flag;
void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(7, OUTPUT);//luz stop
pinMode(8, OUTPUT);//faros
}
void loop() {
while (Serial.available())//
{
delay (10);
if (Serial.available() > 0) //verifica que este disponible el puerto serie y verifica que haya algun
caracter
{
char c = Serial.read(); //guara cualquier caracter que haya llegado por el puerto serie
texto += c; //concatenamos
}
} ///Sentencias de control///
if (texto == "1") //compara el contenido de la avariable "texto" con el numero 1
{
digitalWrite(7,LOW); //Apaga la luz stop
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
if (texto == "3") //compara el contenido de la avariable "texto" con el numero 3
{
digitalWrite(7,LOW); //Apaga la luz stop
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
}
if (texto == "2") //compara el contenido de la avariable "texto" con el numero 2
{
digitalWrite(7,LOW); //Apaga la luz stop
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
}
if (texto == "4") //compara el contenido de la avariable "texto" con el numero 4
{
digitalWrite(7,LOW); //Apaga la luz stop
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
if (texto == "5") //Compara el contenido de la avariable "texto" con el numero 5
{
digitalWrite(7,HIGH); //Enciende la luz stop
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
if (texto == "6") //Compara el contenido de la avariable "texto" con el numero 6
{
if (flag==1)
{digitalWrite(8, LOW);
flag=0;
}
else if (flag==0)
{digitalWrite(8, HIGH);
flag=1;
}
}
texto = "";
}


texts:
Hello I am trying to send temperature data via bluetooth using the HC-06 module. Since TXD and RXD only allow 3.3V I have divided the circuit into two like the below image.
Is this method correct? or is there a better way to connect both two?

Any help is appreciated.