texts:
I'm working in a project and part of this project is sending a .wav file from an Arduino to other device (for example anther Arduino).

I already am able to send a .txt file from an SD which was included in the Ethernet Shield to other Arduino SD card, but it doesn't work when I try to send a .wav file.

Any idea ?

void loop() {
if(digitalRead(push1) == LOW){
    writeanddeletSDcard();
      Serial.println("i will send now");
      Udp.beginPacket(destIp, port);
     Udp.write(a);
      Udp.endPacket();
      Serial.println("Sending UDP message");}}

void writeanddeletSDcard(){
    SD.remove("S13.txt");
   myFile = SD.open("S13.txt", FILE_WRITE); // boolean
   data = myFile.size();
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.println("i will Write now ");
    delay(2000);
    Serial.println(data);
    myFile.println("HELLO WORLD");
    myFile.close();

    // close the file:
  }
else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");}

// ---------------- here end of Writing an a massege on the SD Card
  // re-open the file for reading:
  myFile = SD.open("S2.WAV");
  if (myFile) {
    Serial.println("inside the file there's");

c= 0 ;
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      a[c] = myFile.read();
      c++;
    }
    Serial.println(c);

   // close the file:
    myFile.close();
  } else {
   // if the file didn't open, print an error:
    Serial.println("error opening test.txt");}}


texts:
I've recently made a custom library. Then, I've imported the library into the IDE via the add .zip library. Once I tried to compile the code, I've realised that I made a small typo. Once I changed the error and then retried to compile the code, the error still appeirs and I'm quite sure that I've changed it.

So my guess is that the library is not updating. I've tried to go to manage library and then seeing if there is an other version of the library. There wasn't any.

So is there an easy fix to this solution that doesn't involve updating or downgrading the IDE?


texts:
I don't know whether this is possible or not but is there any way that I can run something similar to Android on a normal TFT. I want to make complex graphics but can't program those complex programs using the Adafruit TFT library.
Arduino Mega 2560 with Elegoo TFT 2.8"


texts: I'm planning to connect GPS to IMU, Is't possible ? I tried my best to find an article that can help solving my curiosity.  How can i connect GPS and MPU to arduino uno?


texts:
I use Arduino Uno with an Accelerometer ADXL345-gy-291 (the full name of the ship) i did hook it up like this

Note I'm using SPI Communication, that was the right one to use in my case.
when I plug in my Arduino here what does my serial monitor give me

as you can see, it sends back fixed values no matter the movement of the ship is.
the code I use is :

#include <SparkFun_ADXL345.h>
ADXL345 adxl = ADXL345(10);

void setup(){

  Serial.begin(9600);
  Serial.println("SparkFun ADXL345 Accelerometer Hook Up Guide Example");
  Serial.println();
  adxl.powerOn();
  adxl.setRangeSetting(16);
  adxl.setSpiBit(0);
  adxl.setActivityXYZ(1, 0, 0);
  adxl.setActivityThreshold(75);
  adxl.setInactivityXYZ(1, 0, 0);
  adxl.setInactivityThreshold(75);
  adxl.setTimeInactivity(10);
  adxl.setTapDetectionOnXYZ(0, 0, 1);
  adxl.setTapThreshold(50);
  adxl.setTapDuration(15);
  adxl.setDoubleTapLatency(80);
  adxl.setDoubleTapWindow(200);
  adxl.setFreeFallThreshold(7);
  adxl.setFreeFallDuration(30);
  adxl.InactivityINT(1);
  adxl.ActivityINT(1);
  adxl.FreeFallINT(1);
  adxl.doubleTapINT(1);
  adxl.singleTapINT(1);
}
void loop(){
  int x,y,z;
  adxl.readAccel(&x, &y, &z);
  Serial.print(x);
  Serial.print(", ");
  Serial.print(y);
  Serial.print(", ");
  Serial.println(z);
  ADXL_ISR();
}
void ADXL_ISR() {
  byte interrupts = adxl.getInterruptSource();

  if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){
    Serial.println("*** FREE FALL ***");
  }

  if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){
    Serial.println("*** INACTIVITY ***");
  }

  if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
    Serial.println("*** ACTIVITY ***");
  }

  if(adxl.triggered(interrupts, ADXL345_DOUBLE_TAP)){
    Serial.println("*** DOUBLE TAP ***");
  }

  if(adxl.triggered(interrupts, ADXL345_SINGLE_TAP)){
    Serial.println("*** TAP ***");
  }
}

so I wonder what was the mistake I made there?


texts: Arduino Nano no output on any controllable pins except for RX and TX pins

texts:
I have 2 Arduino Nanos which don't output anything on any controllable pins except for RX and TX pins. I used an LED which I have tested works on the 3.3v/GND and 5.0v/GND. When I try to control the RX and TX pins (1 and 2) the LED lights up on the board and the external LED I am using to test. I am using the example "Blink" program to test it, and I've tried it on both nanos. I've tested pins 26 (serial), 5 (digital) and 15 (digital) and none output anything. Why isn't it working?

    /*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// Pin 11 has the LED on Teensy 2.0
// Pin 6  has the LED on Teensy++ 2.0
// Pin 13 has the LED on Teensy 3.0
// give it a name:
int led = 26;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}


texts: nodemcu esp8266 does not boot up when 5V pin is connected as a VIN source

texts:
Whenever I boot up the esp8266 or flash code via usb ,I have to remove vin pin otherwise it does not boot up.

If I remove vin pin then flash and boot up happens and then i am able connect vin with 5 V relay.(using VIN to power up relay) .

I dont understand what it has to do with VIN pin.please suggest.

I am using below pins for eight devices

//relay pin setup for funct
int relayOne = 5;
int relayTwo = 4;
int relayThree = 0;
int relayFour = 2;
int relayFive = 14;
int relaySix = 12;
int relaySeven = 13;
int relayEight = 15;


texts: I want to pour 500ml of Water in jar with Arduino water flow controller?

texts:
I want to pour 500ML of water with Arduino water flow controller with maximum accuracy.
How will I get the maximum accuracy with this sensor?
Could someone can give suggestion for accuracy or any other sensor that i can use?


texts: I just bought a TFT screen is it still possible to use the serial port 1 and 0?

texts: so I have a question regarding the TFT touch screen... I would like to use the serial ports 1 and 0 (on my UNO) to transmit data to my mega... however it take up those ports. on the back of it, it shows what each prong should occupy. However, nothing is noted to be required for those ports. is it possible to clip those prongs off and still have the screen be usable or are they important to keep?


texts:
I was just playing around a bit and ran into a strange problem. LED 3, 5, 6, 9 and 10 are on, as intended. For some reason LED 0 and 1 are on as well. Can someone explain why this is happening?

int ledPins[] = {3, 5, 6, 9, 10};
int pinCount = sizeof(ledPins);

void setup(){
  for (int i = 0; i < pinCount; i++){
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop(){
   for (int i = 0; i < pinCount; i++){
     digitalWrite(ledPins[i], 1);
   }
}


texts: Seeking to measure back EMF of an electric motor via Arduino

texts:
Is it possible to measure the back EMF of a motor, using just the Arduino and no sensors?

Or what type of sensor do I need? One that measures current?


texts: Does receiving data with SPI stop the main loop?

texts:
I have a loop of code running on a Mega 2560 that is running at a certain speed, which I get from an Arduino Uno. I have tried to talk with I2C but when I receive the data from I2C, the whole code stops and then resumes when the communication ends. Does this also happen with SPI or can I be transmitting and receiving with SPI inside my main loop?

This is my code. I have to make my own PWM, because the analogWrite function isn't precise enough. When I send data to the Arduino, and since this is in the main loop, the motors stop. I have 4 of these blocks running.

digitalWrite(backLeft, HIGH); //Back left motor driver code
delayMicroseconds(backLeftSpeed);
digitalWrite(backLeft, LOW);
delayMicroseconds(backLeftSpeed);


texts:
I am trying to make an operating hours counter with arduino, i started with a basic script to make the arduino work as a stop watch, This is my script:

unsigned long start=0, finish=0, elapsed=0;

 void setup() {
 Serial.begin(9600);
 Serial.println("Clock START");
 }
 void displayResult(unsigned long elapsed){
   float h,m,s,ms;
   unsigned long over;
   h=int(elapsed/3600000);
   over=elapsed%3600000;
   m=int(over/60000);
   over=over%60000;
   s=int(over/1000);
   ms=over%1000;
   Serial.print("Elapsed time: ");
   Serial.print(h,0);
   Serial.print("h ");
   Serial.print(m,0);
   Serial.print("m ");
   Serial.print(s,0);
   Serial.print("s ");
   Serial.print(ms,0);
   Serial.println("ms");
   Serial.println();
 }

 void loop() {
   start = millis();
   delay(200);
   Serial.println("Start");
   Serial.println("doing Operations and stuff");
   delay(800);
   finish=millis();
   elapsed=finish-start;
   Serial.println("Ended !!!");
   displayResult(elapsed);

 }

Unfortuantly the arduino compiler blocks at the Uploading part, i tried compiling it at first without uploading, it gave me no warning errors. I tried compiling other scripts they worked, it only blocks for this stop watch code.
Thank you for your help


texts: how to count blinking LED flashes using arduino uno boards and LDR?

texts:
i want to know code for counting the flashes of LEDs and display no. of flashes in particular time given.by using LDR.
basically i tried it with interrupts but i'm not getting it,so please help in this regard.


texts:
I have fetched the RFID tag value using an RFID reader and it is now in my Arduino's serial monitor. I have to send it to an Android app. I need help on how to do this.

I don't want to use Bluetooth.


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

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


texts: How to use potentiometer data from slave to master Arduino?

texts: I'm trying to make a game where i can use one Arduino as a controller (the controller is a potentiometer) and the other Arduino sending the signals to the computer. Im trying to figure out communication with two Arduino's so i would like to use two instead of one although using one would be logical and easier. Ive tried looking into I2C but cant seem to figure it out.


texts: Wiring and Connecting WS2801 to NodeMCU ESP8266

texts:
After hours of searching for a solution and try many ways of wiring, I must asking here for Help:

I'm using a ESP8266 (ESP-12E) with a WS2801 - 4 Wire LED Strip and using this Pinout-Diagram to connect WS2801 wires to NodeMCU.

https://alexbloggt.com/wp-content/uploads/2015/10/nodemcu_pinout_700.png

Here is my Wiring:

LED     ESP
====   =====
5V --> Vin
GND --> GND
CK --> GPIO2 (D4)
SI --> GPIO3 (RX)

I have found this sample Program which should turn on and off all LEDs one after each other for 100ms. But it happens nothing after compiling and uploading it to NodeMCU board using Arduino IDE. Any help is highly appreciated.

//This program was taken from the FirstLight.ino supplies with the FastLED library
// It has been modified for use with a NodeMCU for use in a tutorial by NQMakerSupplies.com.au
// Hosted at theMakers.org.
//
// Special thanks to the people behind FastLED.io and all the contributors :)

#define FASTLED_ESP8266_NODEMCU_PIN_ORDER   // map output pins to what they are called on the NodeMCU
#include "FastLED.h"

///////////////////////////////////////////////////////////////////////////////////////////
//
// Move a white dot along the strip of leds.  This program simply shows how to configure the leds,
// and then how to turn a single pixel white and then off, moving down the line of pixels.
//

// How many leds are in the strip?
#define NUM_LEDS 10

// Data pin that led data will be written out over
#define DATA_PIN 3

// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define CLOCK_PIN 2

// This is an array of leds.  One item for each led in your strip.
CRGB leds[NUM_LEDS];

// This function sets up the ledsand tells the controller about them
void setup() {
    // sanity check delay - allows reprogramming if accidently blowing power w/leds
   delay(2000);
   FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
}

// This function runs over and over, and is where you do the magic to light
// your leds.
void loop() {
   // Move a single white led
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = CRGB::White;
      // Show the leds (only one of which is set to white, from above)
      FastLED.show();
      // Wait a little bit
      delay(100);
      // Turn our current led back to black for the next loop around
      leds[whiteLed] = CRGB::Black;
   }
}


texts: Which Arduino is the most suitable for my project?

texts:
I've started to prototype something using an Arduino Mega and Yún Shield.

It's simple. It reads an ADC at 50Hz and sends data to a server through a socket. But because of that combination, I need to use Bridge to send data through the socket. It's very slow.

Should I change the Arduino Mega for a Leonardo or a Due to get better performance?

Here is my code, maybe I did something wrong.

Arduino code:

#include <Bridge.h>
#include <Process.h>
#include <Time.h>
#include <TimeLib.h>
#include <stdlib.h>

boolean interruptFlag = 0;
int HD = A0;
int HG = A1;
int CD = A2;
int CG = A3;
int ECG = A5;
String analogSignals = "";
static char outstr[15];
int count = 0;
float x = 0.0;

void setup() {
  // Bridge startup.
  Bridge.begin();
  // Initialize Bridge values.
  Bridge.put("data", "");
  noInterrupts(); // Stop interrupts.
  TCCR1A = 0; // Set entire TCCR1A register to 0.
  TCCR1B = 0; // Same for TCCR1B.
  TCNT1  = 0; // Initialize counter value to 0.
  // Set compare match register for 50Hz increments.
  OCR1A = 39999; // = 16000000 / (8 * 50) - 1 (must be <65536)
  // Turn on CTC mode.
  TCCR1B |= (1 << WGM12);
  // Set CS12, CS11 and CS10 bits for 64 prescaler.
  TCCR1B |= (0 << CS12) | (1 << CS11) | (1 << CS10);
  // Enable timer compare interrupt.
  TIMSK1 |= (1 << OCIE1A);
  interrupts(); // Allow interrupts.
  // Launch Python script.
  /*Process p;
  p.begin("python");
  p.addParameter("/root/test/send.py");
  p.run();*/
}

ISR(TIMER1_COMPA_vect) {
  if (!interruptFlag) {
    interruptFlag = 1;
  }
}

void loop() {
  if (interruptFlag) {
    writeAnalogSignals();
    interruptFlag = 0;
  }
}

void writeAnalogSignals() {
  String HDReading = convertToVoltage(analogRead(HD));
  String HGReading = convertToVoltage(analogRead(HG));
  String CDReading = convertToVoltage(analogRead(CD));
  String CGReading = convertToVoltage(analogRead(CG));
  String ECGReading = convertToVoltage(analogRead(ECG));
  if (analogSignals.length() == 0) {
    analogSignals =  String(x, 2) + ";" + HDReading + ";" + HGReading + ";" + CDReading + ";" + CGReading + ";0.0;0.0;" + ECGReading;
  } else {
    analogSignals += "|" + String(x, 2) + ";" + HDReading + ";" + HGReading + ";" + CDReading + ";" + CGReading + ";0.0;0.0;" + ECGReading;
  }
  x += 0.02;
  count += 1;
  if (count >= 50) {
    Bridge.put("data", analogSignals);
    analogSignals = "";
    count = 0;
  }
}
// Convert the analog reading to voltage.
String convertToVoltage(int analogSignal) {
  dtostrf(analogSignal * (5.0 / 1023),8, 6, outstr);
  return outstr;
}

Python code:

import socket
import sys
import getopt
import time

def main(argv):
    try:
        sys.path.insert(0, '/usr/lib/python2.7/bridge/')
        from bridgeclient import BridgeClient as bridgeclient
        # Create a UDP socket.
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        server_address = ('192.168.1.100', 9050)
        bridge = bridgeclient()
        previous = ""

        # Send data
        while 1:
            data = bridge.get("data")
            if data != previous:
                sent = sock.sendto(data, server_address)
                previous = data
            time.sleep(0.5)

    finally:
        sock.close()


texts:
At the moment I'm trying to learn microcontrollers with Arduino, and have a problem with the timer.

Arduino works at 16MHz clock, and the best prescaler is 1024, which means the timer increments the value every 64 us. Timer 3 is a 16 bit timer, which gives us a maximum time of 64*65535= 4194240, ca. 4s

But what if I want to do a job every 8 seconds? Any idea?

Here's my code:

TCCR3A = 0;
TCCR3B = 0;
TCCR3B |= (1<<WGM32); //CTC
TCCR3B |= (1 << CS32);
TCCR3B |= (1 << CS30);// 1024 prescaler
TIMSK3 |= (1<<OCIE3A);
sei();


texts: My Arduino smokes every time I connect an AC/DC wall adapter to it. Can someone help me to fix it?

texts: I copied the schematic below and when I ran the code from my laptop, it worked well but every time I unplug it to my laptop and connect an ac dc wall adapter, my Arduino smokes. Why does it smoke and how to fix it so that I can connect an AC/DC wall adapter to power my Arduino? EDIT from the comments: My AC/DC adapter has 19.5V DC out.


texts: WatchDog on Arduino Nano - does not recover

texts:
I'm trying to add a watchdog on an Arduino Nano, for my code, and I'm following exactly code in this manual, but after the amount of time for not resetting the watchdog- it resets but does not reboot.

At last paragraph- it says that :"

  However, I could not find something similar in Optiboot bootloader (If
  I'm wrong, correct me please!), used by Arduino UNO and other new
  boards. It seems that they sacrificed this check for size. So, it is
  possible that watchdog timer will be enabled after reset, so -  if you
  set it's value too low, your board may never come out of bootloader
  stage. So, to be always on the safe side, set watchdog to longer
  periods (2S and more).

So I've tried for 8s, but still same result.

What is wrong ?

  EDIT1:

#include <avr/wdt.h>
int k=1;
void setup() {
  Serial.begin(9600);
  wdt_enable(WDTO_8S);
}
void loop() {
  //do stuff here
  k++;
  wdt_reset();
  Serial.println(1000 * k);
  delay(1000 * k);

}


texts: Fio Keyboard program out of control, how to reset?

texts:
My question involves a Sparkfun Fio v3, similar to the Arduino Fio.

I had a student who was testing his understanding of the Keyboard library.  He uploaded a sketch that continuously sends output, emulating a keyboard, saying "Hello!If you're reading this, then you did things right!" (I don't have his code, unfortunately, so I can't post it.)

So, now, whenever I connect it via the USB, I can't upload a new sketch because the Serial channel is clogged with this output.  (Error Message: "avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00" and so on)

I've tried putting the cursor inside the header comment in 'Blink', so that the new characters that are being spammed to my code are all inside a comment, and this makes it possible to compile, but it won't sync and upload.  I've tried burning a new bootloader, and this fails as well (Message: "Error while burning bootloader.").

It seems to me that the only way to get this device back is to reset the memory without connecting to a computer, but I can't find any way to do this.

Is there any way to rescue this device?


texts: how to make this work auto on off led with fading

texts:
I'm working on a project with Arduino to make LED timer with fading feature. After doing some research finally I wrote some code but it's not working until now
P.S i don't have any knowledge in coding at all T_T

Edit: Adding more details about the issue;
when trying to check upload this error is always shown.

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

\SunRisetimer.ino: In function 'void loop()':

SunRisetimer:55: error: 'startOff' was not declared in this scope

     startOff();
\SunRisetimer.ino: In function 'void startOn()':

SunRisetimer:89: error: variable or field 'startOff' declared void

 void startOff

SunRisetimer:91: error: expected '}' before ';' token

analogWrite(uled, 1);

SunRisetimer:116: error: expected '}' at end of input

 }
exit status 1
'startOff' was not declared in this scope

Code:

#include <DS3231.h> //Include the clock library

// Changable Vars
int fadeTimeOn = 30; // How long the light will fade to max
int fadeTimeOff = 30; // How long the light will fade to min
int setHourOn = 9; // Set hours to wake (military time)
int setMinOn = 15; // Set minute to wake
int setHourOff = 9; //set off h
int setMinOff = 30; //
int uled = 9; // Set pinout with with PWM

// Set up Vars
DS3231  rtc(SDA, SCL);
Time t;
void start();

void setup()
{
  pinMode(uled, OUTPUT);
  Serial.begin(9600); // Match to serial monitor
  rtc.begin();
}

void loop()
{
  t = rtc.getTime(); // Make a time class called 't'

  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");

  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());

  if (t.hour == setHourOn && t.min == setMinOn) // Check if it's time to wake up!
  {
    startOn();
  }

  // Wait one second before repeating
  delay (1000);

 if (t.hour == setHourOff && t.min == setMinOff) // Check if it's time to off!
  {
    startOff();
  }

  // Wait one second before repeating
  delay (1000);
}

void startOn()
{
  // Fix for SB LED
  analogWrite(uled, 1);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 2);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 3);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 4);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 4);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 5);
  delay((fadeTimeOn * 60000)/50);

for (int i = 6 ; i <= 255; i++)
    {
    analogWrite(uled, i);
    delay(((fadeTimeOn * 60000)/306));
    Serial.print(" mil sec ");
    Serial.print(((fadeTimeOn * 60000)/306));
    Serial.print(" PWM " );
    Serial.print(i);
    {
}

void startOff
{
  analogWrite(uled, 1);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 5);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 4);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 3);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 2);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 1);
  delay((fadeTimeOff * 60000)/50);

  // Fade script
  for (int i = 6 ; i <= 255; i++)
  {
    analogWrite(uled, i);
    delay(((fadeTimeOff * 60000)/306));
    Serial.print(" mil sec ");
    Serial.print(((fadeTimeOff * 60000)/306));
    Serial.print(" PWM " );
    Serial.print(i);

  }

}


texts: How to ground a arduino with an external power-source?

texts:
I have magnet hooked up to my arduino with a Darlington Transistor, like this:

The powersource is a 12V adapter

I'm pretty new to electronics but i'm told that the transistor won't work unless the ground on the arduino is the same as the ground on the external source. How do I do this in practice? Should I run a wire from the ardunio-ground to the negative pole on the powersource? How do I tell which one is the negative one?


texts: Master and Slave Code using 2 Arduino. 1 for PC and 1 for Sensor

texts:
I'm trying my gesture sensor to act as a keyboard. I'm using 2 Arduinos to communicate; 1 is connected to the PC (Arduino Pro Micro) and 1 is connected to the sensor (Arduino pro mini)
Can you tell me why my code isn't working? (I don't have any sort of knowledge in coding, just making this because of a school project.)
My sensor is APDS9960 Gesture Sensor and I'm using HC05.
And this is my code:
MASTER CODE
#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins
#define APDS9960_INT    2 // Needs to be an interrupt pin

// Constants

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;

void setup() {
  // Set interrupt pin as input
  pinMode(APDS9960_INT, INPUT);

  // Initialize Serial port
  Serial.begin(9600);
  Serial.println();
  Serial.println(F("--------------------------------"));
  Serial.println(F("SparkFun APDS-9960 - GestureTest"));
  Serial.println(F("--------------------------------"));

  // Initialize interrupt service routine
  attachInterrupt(0, interruptRoutine, FALLING);

  // Initialize APDS-9960 (configure I2C and initial values)
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9960 init!"));
  }

  // Start running the APDS-9960 gesture sensor engine
  if ( apds.enableGestureSensor(true) ) {
    Serial.println(F("Gesture sensor is now running"));
  } else {
    Serial.println(F("Something went wrong during gesture sensor init!"));
  }
}

void loop() {
  if ( isr_flag == 1 ) {
    detachInterrupt(0);
    handleGesture();
    isr_flag = 0;
    attachInterrupt(0, interruptRoutine, FALLING);
  }
}

void interruptRoutine() {
  isr_flag = 1;
}

void handleGesture() {
  if ( apds.isGestureAvailable() ) {
    switch ( apds.readGesture() ) {
    case DIR_UP:
      Serial.println("UP");
      Serial.print('1');
      break;
    case DIR_DOWN:
      Serial.println("DOWN");
      Serial.print('2');
      break;
    case DIR_LEFT:
      Serial.println("LEFT");
      Serial.print('3');
      break;
    case DIR_RIGHT:
      Serial.println("RIGHT");
      Serial.print('4');
      break;
    case DIR_NEAR:
      Serial.println("NEAR");
      Serial.print('5');
      break;
    case DIR_FAR:
      Serial.println("FAR");
      Serial.print('6');
      break;
      default:
      Serial.println("NONE");
    }

SLAVE CODE
#include <Keyboard.h>

#define INT_PIN 4

int state = 0;

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

void loop() {
  if (Serial.available() > 0) { // Checks whether data is comming from the serial port
    state = Serial.read(); // Reads the data from the serial port
    Serial.write(state);
  }

  if (state == '1') {
    Keyboard.press("KEY_F5");
    delay(100);
    Keyboard.releaseAll();
    Serial.println("Ok");
  }

  if (state == '2') {
    Keyboard.press("KEY_ESC");
    delay(100);
    Keyboard.releaseAll();
    Serial.println("Ok");
  }

  if (state == '3') {
    Keyboard.press("KEY_LEFT_ARROW");
    delay(100);
    Keyboard.releaseAll();
    Serial.println("Ok");
  }

  if (state == '4') {
    Keyboard.press("KEY_RIGHT_ARROW");
    delay(100);
    Keyboard.releaseAll();
    Serial.println("Ok");
  }
}

This is what i wan to do.

The Problem is my code doesnt seem to work and i dont know why. It doesnt do anything. My Pro mini connected to sensor showing that in serial monitor it is working but the slave doesnt show anything and i think because theyre not communicating with each. Can someone point out what my mistake on my code?


texts:
Hi i have made this code
its so simple its should receive data from the computer and send it back via the serial but the problem is he do not what it is suppose to do
when its run its keep sending -1 to the computer
and if i send something to the arduini  like  55   i receive and answer 53
i have no idea were is the problem in this code

long number = 0;

void setup() {
  Serial.begin(9600);
}
   void loop() {
   number = Serial.read();
   delay(1000);
   Serial.println(number);
}


texts:
How do you obtain the real and imaginary parts of a signal using FFT in arduino?
I could not find a particular tutorial with code for this purpose in the internet.


texts: Can I load programs through the RS232 pins?

texts:
Can I upload new programs onto a MEGA2560 through a serial port connected to pins 2&3?  (through the correct RS232<->TTL level shifters)

I know the 16U2 chip acts as a USB->serial converter and it also asserting the reset which starts the bootloader running on the 2650. Does it do anything else?

As long as I can time the reset correctly, is there anything else preventing reprogramming directly through the RX/TX pins?

And if I do this, will the application program still be able to use the serial channel?


texts: ESP8266 ESP-07 does not respond to commands

texts:
I just bought an ESP8266 ESP-07 V1.0 Serial Wifi Transceiver. Similiar to this: https://www.ebay.com/itm/ESP8266-Serial-Wifi-Transceiver-Module-for-Arduino-ESP-07-V1-0-New-/331868488091

I have connect the RX and TX pins to the RX and TX pin of the Arduino (RX to TX and TX to RX), VCC is connected to 3.3V and GND is connected to Arduino ground.
I have used the following code and writing commands to the module using the serial monitor:

#include <SoftwareSerial.h>

int RX_PIN = 3;
int TX_PIN = 4;

SoftwareSerial mySerial(RX_PIN, TX_PIN); // RX, TX

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

    while (!Serial){
    ;
  }

    while (!mySerial){
    ;
  }
  Serial.println("Ready");
}
void loop()
{
    // listen for communication from the ESP8266 and then write it to the serial monitor
    if ( mySerial.available() )   {  Serial.write( mySerial.read() );  }

    // listen for user input and send it to the ESP8266
    if ( Serial.available() )       {  mySerial.write( Serial.read() );  }
}

Whatever I type (for example AT+GMR) in the serial monitor at 9600 baud I don't get any response. What could be the reason? Both NL and CR is added to the command.

When pressing reset on the ESP-module I get this in the Serial monitoring:

Thanks for any help!


texts: Programming 5 inch TFT Display + Arduino Mega with Touch Shield (w/SSD1963)

texts:
I am newbie on Arduino and TFT Screens. But I am a semi-professional on programming and I decided to develop a device that can be controlled by Arduino via capacitive touch screen (there will be 2 buttons on the screen and while one of them will increase the current of a device, other will decrease). To do that, I've bought a complete solution (Arduino Mega + 5" TFT LCD + Arduino Shiled but without Resistive touch screen - this one), instead of resistive touch screen, I've bought this one and I've bought a separate PSU.

At the end, I have an Arduino Mega, 5 inch TFT Display, 5 inch Multi Touch Screen Panel with Controller GSL1680F (assembled to the Display) and Arduino Shield which is produced for this system. But I don't know how to communicate these three devices with each other. I know that, Arduino has built-in storage for the codes, and both TFT Display and Shield have micro-sd storage slots for placing codes. E.g. I don't know what is the aim of micro-sd storage slot on the shield.

As a result, is there any code samples / tutorials / video that I can follow to develop with this system? Thanks.


texts: How to use RTC memory in NodeMCU to count awakes from deep sleep?

texts:
Problem: I need to retry at least 3 times (before giving up) to reconnect my NodeMCU if it doesn't get connected to Wifi, through deep sleep cycles in order to save batteries. I thought to use RTC memory to save a counter, but it doesn't work because content of RTC RAM is unpredicatble at first power up.

Following is a NOT WORKING code, but it gives the idea of what I need to achieve. The problem is: the kounter variable is persistent through cycles, but its very first value is unpredicatble.

#define DONEPIN 5
uint32_t kounter;

void setup() {
    digitalWrite(DONEPIN, HIGH);
    //WiFi setup functions...
    // .....
    if (WiFi.status() != WL_CONNECTED) {
        ESP.rtcUserMemoryRead(0, &kounter, sizeof(kounter));
        kounter++
        if (kounter > 3) {
            digitalWrite(DONEPIN, LOW);
        }
        ESP.rtcUserMemoryWrite(0, &kounter, sizeof(kounter));
        ESP.deepSleep(60e6);
    }
}


texts:
I followed Great Scott's video on YouTube for uploading to an ATtiny85. When I tried I got the following error messages:

Arduino: 1.6.7 (Windows Vista), Board: "ATtiny85 (internal 8 MHz clock)"
Board attiny-master:attiny:attiny85-20 doesn't define a 'build.board' >preference. Auto-set to: ATTINY_ATTINY85-20
Board attiny-master:attiny:attiny45-8 doesn't define a 'build.board' >preference. Auto-set to: ATTINY_ATTINY45-8
Board attiny-master:attiny:attiny85-8 doesn't define a 'build.board' >preference. Auto-set to: ATTINY_ATTINY85-8
Board attiny-master:attiny:attiny44 doesn't define a 'build.board' >preference. Auto-set to: ATTINY_ATTINY44

etc. etc. ...

exec: "-w": executable file not found in %PATH%
Error compiling.`
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

When I unplug  my ATtiny85 and restart Arduino, I have no problems uploading, though I get about 8 error messages saying something like:

Board attiny-master:attiny:attiny84 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY84


texts: I have been experimenting with Arduino for a couple of months, and, riding on the back of my 16 years as a high school science teacher (I am now back at university as a student), I can see a few potential improvements for existing science experiments in the high school teaching lab. My question is this: can I make packages based on Arduino and legally sell them to schools for a small profit? Since I’m no longer a teacher, I wouldn’t be using them myself, so I’d have to at least recoup my costs.


texts:
I have a audio interface + mixer that takes input from my microphone (mic level balanced) and my instrument (line level stereo). I want to build an arduino controlled mute button for those, so that I can use my keyboard to toggle the inputs on and off (can't do that via software because they are mixed beforehand).

The idea is that I can build some sort of device to stay between the inputs and the mixer and is attached to my pc via USB.

I know I can use serial communication for the software, but what kind of relays should I get? I don't want any additional noise in the system.


texts:
I'm attempting to transmit very simple data across some NRF24l01 modules for testing purposes, and I've been following a YouTube guide.

Here is my code:

Trasmitter:

#include "RF24.h"
#include <SPI.h>

RF24 Radio (7, 8);
byte address[][6] = {"0"};
struct package{
   int on = 1;
};

typedef struct package Package;
Package data;

void setup() {
  Serial.begin(9600);
  delay(1000);
  Radio.begin();
  Radio.setChannel(118);
  Radio.setPALevel(RF24_PA_LOW);
  Radio.setDataRate(RF24_250KBPS);
  Radio.openWritingPipe(address[0]);
  delay(1000);
}

void loop() {
  Radio.write(&data, sizeof(data));

  Serial.println("Data sent:");
  Serial.println(data.on);
  delay(1000);
  }
}

Receiver:

 #include "RF24.h"
 #include <SPI.h>

 RF24 Radio (7, 8);
 byte address[][6] = {"0"};
 struct package{
    int on = 1;
 };

 typedef struct package Package;
 Package data;

 void setup() {
   Serial.begin(9600);
   pinMode(2, OUTPUT);
   delay(1000);
   Radio.begin();
   Radio.setChannel(118);
   Radio.setPALevel(RF24_PA_LOW);
   Radio.setDataRate(RF24_250KBPS);
   Radio.openReadingPipe(1, address[0]);
   Radio.startListening();
   delay(1000);
 }

 void loop() {
   while(Radio.available()){
     Radio.read(&data, sizeof(data));
     if(data.on == 1){
       digitalWrite(2, HIGH);
     }
     else if(data.on == 0){
       digitalWrite(2, HIGH);
     }
     else{
       digitalWrite(2, LOW);
     }
     Serial.println(data.on);
   }
   while(!Radio.available()){
     Serial.println("Error");
   }
   delay(1000);
 }

When I run the code on each respective unit, I receive only zeros on the receiver. Since I don't see where data.on could get set to zero in my code, I'm assuming there is a communication issue somehow between the two modules, even though Radio.available() is functioning properly.

Am I missing something obvious?


texts: Timer2 Compare Interrupt not working as expected

texts:
To get this out of the way first: I have already looked at "Timer2 does not work as it should" and "Timer2 “Clear OC2B on Compare Match” not working as expected in CTC mode" but have not found the answers there very useful.

Now on to my problem:

I'm trying to use the Timer2 in CTC mode to have an interrupt every 500us. For this, I have the following code:

#include "TimerTwo.h"

TimerTwo Timer2;

ISR(TIMER2_COMPA_vect) { //ISR on Compare Match A
  Timer2.isrCallback();
}

void TimerTwo::initialize() {
  cli();
  TCCR2A = 0;// set entire TCCR2A register to 0
  TCCR2B = 0;// same for TCCR2B
  TCNT2  = 0;//initialize counter value to 0

  // set compare match register for 2khz increments
  OCR2A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256)

  // turn on CTC mode
  TCCR2A |= _BV(WGM21);

  // Set CS22 bit for 64 prescaler
  TCCR2B |=  _BV(CS22);

  // enable timer compare interrupt
  TIMSK2 |= _BV(OCIE2A);
  sei();
}

void TimerTwo::attachInterrupt(void (*isr)()) {
  TIMSK2 |= _BV(OCIE2A);
  isrCallback = isr;
}

void TimerTwo::detachInterrupt() {
  TIMSK2 &= ~_BV(OCIE2A);
  isrCallback = nullptr;
}

and

#ifndef TIMERTWO_H
#define TIMERTWO_H

#include <Arduino.h>

class TimerTwo
{
  public: //methods
    void initialize();
    void attachInterrupt(void (*isr)());
    void detachInterrupt();
    void (*isrCallback)();
};

extern TimerTwo Timer2;

#endif

It was inspired by the TimerOne library.

However, when I measure the period at the output pin (which I have attached inside some other code) I only get a period of 1ms. Even if I set ORC2A to 63, this fact doesn't change.

I have the constructor of this called inside my setup() so the registers should not be overwritten by the wiring.c.

I have also looked at the datasheet of the ATmega328p and checked that all registers are set correctly.

Thanks in advance for your help. If you need any further information, let me know.


texts: incompatible types in assignment of 'const String' to 'char [32] using server.arg

texts:
I am trying to create a class and getting getting the error
incompatible types in assignment of 'const String' to 'char [32]

when I declare
char inString[32];

and try to set it as
inString = server.arg("x");

I tried
inString = server.arg(sizeof("x"));

and got the same error.
full code:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

const char* ssid = "myssid";
const char* password =  "password";

char inString[32];

void webpage() {
  server.send(200, "text/html", "<form  name='frm'  method='post'><input type='text' name='x'   ><input type='submit' value='Submit'>   </form>");
}
void response(){
  if(server.hasArg("x") && (server.arg("x").length()>0)){ // TODO check that it's not longer than 31 characters
    Serial.print("User entered:\t");
    Serial.println(server.arg("x"));
    inString = server.arg("x");
    server.send(200, "text/html", "
Successful
Home");
  } else {
    server.send(400, "text/html", "
HTTP Error 400

Bad request. Please enter a value.
");
  }
}

void setup() {

    Serial.begin(115200);
    WiFi.begin(ssid, password);  //Connect to the WiFi network

    while (WiFi.status() != WL_CONNECTED) {  //Wait for connection

        delay(500);
        Serial.println("Waiting to connect...");

    }

    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //Print the local IP

    //server.on("/body", handleBody); //Associate the handler function to the path
    server.on("/",HTTP_GET, webpage);
    server.on("/",HTTP_POST,response);

    server.begin(); //Start the server
    Serial.println("Server listening");

}

void loop() {

    server.handleClient(); //Handling of incoming requests

}

how to I match my datatypes when using server.arg?
The other post I find related to a pointer which I am not using.


texts: Arduino Nano v3: is it possible to PCM + AltSoftSerial?

texts:
I wonder is it possible to change PCM.h 's lib use of 16-bit timer1 to another 8-bit?
Now I'm getting

libraries\AltSoftSerial\AltSoftSerial.cpp.o (symbol from plugin): In function `AltSoftSerial::read()':

(.text+0x0): multiple definition of `__vector_11'

libraries\PCM\PCM.c.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

when compiling

#include <PCM.h>
#include <AltSoftSerial.h>

An attempt to avoid XY problem: make AltSoftSerial work alongside with PCM-alike library on Arduino Nano v3 without SD.

I'm poorly familiar with timers and interrupts, so I'll be very grateful for any advice and suggestion!


texts:
I've been working on this for 4+ hours, and have gotten nowhere.

I have an array of weather conditions, and a number is sent over serial port to indicate which member of the array to print to the LCD.

I'm guessing the problem is in how I'm defining the array. These are my current 2 guesses for how to define it:

String weatherConditions[49] = { "tornado","hurricane","tropical storm","sev tstorms","tstorms","mix rain-snow","mix rain-sleet","mix snow-sleet","freez drizzle","drizzle","freez rain","showers","showers","snow flur","lt snow show","blowing snow","snow","hail","sleet","dust","foggy","haze","smoky","blustery","windy","cold","cloudy","mostly cloud","mostly cloud","part cloud","part cloud","clear","sunny","fair","fair","mix rain-hail","hot","isol tstorms","scat tstorms","scat tstorms","scat showers","heavy snow","scat snowshow","heavy snow","part cloudy","tshowers","snow showers","isol tshowers","not available" };

or:

char weatherConditions[49][16] = { "tornado","hurricane","tropical storm","sev tstorms","tstorms","mix rain-snow","mix rain-sleet","mix snow-sleet","freez drizzle","drizzle","freez rain","showers","showers","snow flur","lt snow show","blowing snow","snow","hail","sleet","dust","foggy","haze","smoky","blustery","windy","cold","cloudy","mostly cloud","mostly cloud","part cloud","part cloud","clear","sunny","fair","fair","mix rain-hail","hot","isol tstorms","scat tstorms","scat tstorms","scat showers","heavy snow","scat snowshow","heavy snow","part cloudy","tshowers","snow showers","isol tshowers","not available" };

I've tried many other ways of defining the array (including "char* weatherConditions"), but I'm sure most of them were just ignorant guesses.

Later in the code I have this to display a member of the array:

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(weatherTodayHigh);lcd.print("/");lcd.print(weatherTodayLow);lcd.print(" ");lcd.print(weatherConditions[weatherCurrentConditionsCode]);
lcd.setCursor(0, 1);
lcd.print(weatherTomorrowHigh);lcd.print("/");lcd.print(weatherTomorrowLow);lcd.print(" ");lcd.print(weatherConditions[weatherTomorrowConditionsCode);
break;

Everything I try ends up causing nothing to be printed on the 1602 LCD display (I have 15 other scrollable "screens" that are displaying just fine on the LCD). The earlier text on this screen (the highs and lows for today and tomorrow) is displaying fine, but after that, where the weather condition text is supposed to be shown, there is nothing.

I'm able to easily display the same weather condition text on the serial monitor (for that I was using "String weatherConditions[49] = {..." and then "Serial.println(weatherConditions[currentValue]);").

How can I get members of a text array to be printed on the LCD?


texts: receiving sms by arduino with wavecome to control the led with sms

texts:
how to code the arduino program for turning on / off thhe led if we use wavecome modem fastrack on the arduino, please help me i'am in a trouble about this. Please
i dont understand about how to control the led , such if i send message on the wavecome whats connect to the arduino and the led would be on, anyone can help me ? so sorry if my english language is bad


texts:
I am having an issue that I can't seem to get my head wrapped around.  What I am trying to accomplish is to have a minutes worth of sensor data in an array (reading every 5 seconds) so I'll have 12 values in this after one minute.

I want to keep the array to 12 values so I need to keep moving all the values in it down one index per new value hitting index [0] to make sure that each reading has a lifetime of 60 seconds on the array.  Here is my code so far:

void add_readings_to_averages() {
  // At this point, I am moving values down the array to make room at the beginning.
  for (int a = 11; a >= 0; a--) {
    Serial.print("The value at temperature_c_minute_avg[");
    Serial.print(a);
    Serial.print("] is ");
    Serial.print(temperature_c_minute_avg[a]);
    Serial.println();
    if (a == 11) {
      Serial.println("At 12 so need to overwrite this value");
    }

    if (a <= 10) {
      Serial.print("a is ");
      Serial.println(a);
      temperature_c_minute_avg[a] = temperature_c_minute_avg[a + 1];  // This moves each entry down one index in the array creating an empty space at index[0]
    }

    if (a == 0) {
      temperature_c_minute_avg[a] = temperature_c;
    }
  }

I've loaded my array at the time of initialization with some dummy data so I could see what was going on.  First run displays as you would expect.

The value at temperature_c_minute_avg[11] is 120.00
At 12 so need to overwrite this value
The value at temperature_c_minute_avg[10] is 110.00
a is 10
The value at temperature_c_minute_avg[9] is 100.00
a is 9
The value at temperature_c_minute_avg[8] is 90.00
a is 8
The value at temperature_c_minute_avg[7] is 80.00
a is 7
The value at temperature_c_minute_avg[6] is 70.00
a is 6
The value at temperature_c_minute_avg[5] is 60.00
a is 5
The value at temperature_c_minute_avg[4] is 50.00
a is 4
The value at temperature_c_minute_avg[3] is 40.00
a is 3
The value at temperature_c_minute_avg[2] is 30.00
a is 2
The value at temperature_c_minute_avg[1] is 20.00
a is 1
The value at temperature_c_minute_avg[0] is 10.00
a is 0
2018/11/2 11:4:39  -  Running for a total of 0 hours 0 minutes and 7         seconds

But the second time through the loop() my array is trashed.

The value at temperature_c_minute_avg[11] is 120.00
At 12 so need to overwrite this value
The value at temperature_c_minute_avg[10] is 120.00
a is 10
The value at temperature_c_minute_avg[9] is 120.00
a is 9
The value at temperature_c_minute_avg[8] is 120.00
a is 8
The value at temperature_c_minute_avg[7] is 120.00
a is 7
The value at temperature_c_minute_avg[6] is 120.00
a is 6
The value at temperature_c_minute_avg[5] is 120.00
a is 5
The value at temperature_c_minute_avg[4] is 120.00
a is 4
The value at temperature_c_minute_avg[3] is 120.00
a is 3
The value at temperature_c_minute_avg[2] is 120.00
a is 2
The value at temperature_c_minute_avg[1] is 120.00
a is 1
The value at temperature_c_minute_avg[0] is 0.00
a is 0
2018/11/2 11:4:44  -  Running for a total of 0 hours 0 minutes and 12     seconds

The entire array was overwritten with the last value and the new value was not added.  The array itself is setup as a global variable.  The initialization at the top.

float temperature_c_minute_avg[12] = {10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,100.0,110.0,120.0};

What am I missing here?  Been staring at this for some time, but this is the first time I've tried to use an Arduino array so I can totally believe the issue is PBKAC! :)


texts: Failed to display string on oled (SPI) from SD module

texts:
i am working on a project in which data from sd card is displayed on the oled screen both using SPI communication, but it is not displaying anything.

i commented out the sd part and then oled works fine.

i got to know that problem orgnates from "SD.begin(4)".

please help me..

#include <Wire.h>
#include "U8glib.h"
#include <SD.h>
static U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9, 8);
String text;

File myFile;
void setup() {
 Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("a.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
   myFile.print("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("a.txt", FILE_READ);
  if (myFile) {
    Serial.println("a.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      text = myFile.readString();
      delay(100);
      //Serial.println(text);

    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
Serial.println(text);
//u8g.setFont(u8g_font_unifont);
//u8g.drawStr(0,22,b);

}

void loop() {
  digitalWrite(4,HIGH);
  digitalWrite(10,LOW);
  u8g.firstPage();
  do {
    draw();
  } while( u8g.nextPage() );

}

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here
  u8g.setFont(u8g_font_unifont);
 u8g.setPrintPos(0,20);
  u8g.print(text);
} ```


texts: What are the correct pins for TWAI (CAN) on ESP32?

texts:
compared to the microchip's PICs:
pic16f's does not have an onboard CAN peripheral. so you need an SPI - CAN controller (like MCP2515).
some PIC18f's have an onboard CAN controller, and only need a CAN transceiver. In these cases there are exclusive TX and RX pins to be used.
Are there specific pins to be used as a CAN bus on esp32?
peripherals like adc, i2c and others need to use specific pins. Does this happen with CAN too?
I'm using the following configuration:
2 ESP32 devboard boards - arduino on PlatformIO
Pin 5 as TX and pin 4 as RX (already in the CAN library),
2 Sn65hvd230 transceiver modules
I looked for information about it in the documentation, but I couldn't find it.
I appreciate any help.


texts:
I have 4 gyro sensors that communicate to arduino uno using I2C and then arduino uno sends the data to arduino mega.
I was wondering if I could use i2c for this purpose or if I should look for other methods.
gyro sensor used in the project:
https://www.pololu.com/product/2129/resources


texts:
I have the following V regulator, that has an enable pin that i'd like to control via an arduino:  https://www.pololu.com/product/2582

I tried using a relay (ELEGOO Relay Module 4 Channel DC 5V with Optocoupler for Arduino) with the following pins:

Relay pin1: 0v of 24v battery

Relay pin2: enable pin of pololu v regulator

I then enabled the above relay via an arduino digital out pin.

However it seemed to have no effect, the regulator never shut off.
If i manually join the two relay pins, pin1 and pin2 the regulator does shut off though ..  A and B in picture.

Any ideas why the relay is not working via the arduino?  or should it work? am i doing something wrong?  I am not too familiar with pull up or pull downs..

I have since disconnected everything and put it away, i am just looking for theory help, confirmation it should wotk.   I managed to get the relay working for leds at the time .. would the fact that current flows in the other direction for this pull down relay setup, be my issue and that i should swap around wires A and B?

(As a workaround i used a relay to switch on or enable the 24v Vin line out from the battery instead, that seemed to work okay..)


texts: detachInterrupt(0) in arduino not working ? after giving continuous ground to INT0 wakeupnow function should execute once not again and again

texts:
#include <avr/sleep.h>

int wakePin = 2;                 // pin used for waking up
int led=13;
int flag=0;

void wakeUpNow()
{
  // execute code here after wake-up before returning to the loop() function
  // timers and code using timers (serial.print and more...) will not work here.
  // we don't really need to execute any special functions here, since we
  // just want the thing to wake up
  int count=10;
  while(count!=0)
  {
    delay(1000);
    count--;
    Serial.println(count);
    delay(1000);
  }
}

void setup()
{
  Serial.begin(9600);
  pinMode(wakePin, INPUT_PULLUP);  // wakePin is pin no. 2
  pinMode(led, OUTPUT);          //   led is pin no. 13
  attachInterrupt(0, wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW
}

void sleepNow()
{
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
    sleep_enable();                        // enables the sleep bit in the mcucr register
                      delay(500);
                      Serial.println("Rajat");
                      delay(500);
    attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
                      delay(500);
                      Serial.println("Rajat");
                      delay(500);
    sleep_mode();     // here the device is actually put to sleep...!!
      // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
                      delay(500);
                      Serial.println("Rajat2");
                      delay(500);
    detachInterrupt(0);      // disables interrupt 0 on pin 2 so the wakeUpNow code will not be executed during normal running time.
    sleep_disable();         // first thing after waking from sleep: disable sleep...
                      delay(500);
                      Serial.println("Rajat3");
                      delay(500);
       detachInterrupt(0);      // disables interrupt 0 on pin 2 so the wakeUpNow code will not be executed during normal running time.

}

void loop()
{
      digitalWrite(led, HIGH);
      delay(1000);
      digitalWrite(led, LOW);
      delay(1000);
    /* delay(500);
      Serial.println("jam");
      delay(500);  */
      if (flag==0)
      {
      sleepNow();     // sleep function called here
      flag=1;
      }
}

After Last Rajat I give ground to INT0.

Output in serial monitor :

Rajat
Rajat
9
8
7
6
5
4
3
2
1
0
9
8
7
6
5
4
3
2
1
0
9
8
7
6
5
4
3
2
1
0
9
8
7
6
5
4
3
2
1
0
9
8
7
6
5
4
3
2
1
0
9
8
7
6
5
4
3
2
1
0
9
8
7
6
5
4
3
2
1
0
9
8
7
6
5
4
3
2
& so on..!


texts: ESP8266 not able to communicate over serial connection with arduino UNO

texts:
This is the code I uploaded in Arduino UNO:

#include<SoftwareSerial.h>
SoftwareSerial ESP(2,3); // RX, TX
//ESP RX-->3(UNO) TX-->2(UNO)

void setup() {
// Open serial communications and wait for port to open:

    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }

    Serial.println("Goodnight moon!");

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

}

void loop() {
    if (ESP.available()) {
        char inData = ESP.read();
        Serial.println("Got reponse from ESP8266: ");
        Serial.write(inData);
    }

    ESP.write("AT\r\n"); //Normally ESP responds to AT command with "OK"
}

But ESP is not able to receive the AT command properly...sometimes it recieves A, sometime T. It then responds with garbage value. Though we are able to give command to ESP through Serial Monitor and it responds pretty well. But when trying to communicate through code, the communication is not OK.


texts: Led issue with arduino controled by raspberry pi/python

texts:
I'm having an issue with my project. My project is 8 leds and a potentiometer on an arduino being read and controlled by a raspberry pi running python.

when I'm using a potentiometer the signal is received by my raspberry pi with python which then tells a set of leds to either turn on or off. However my leds flash on my low threshold when they shouldn't, the leds on my higher threshold work as expected and stay on till my pot is out of that range. How can I fix this?

Here is my script!

from nanpy import Arduino
from nanpy import serial_manager
from time import sleep

serial_manager.connect('/dev/ttyUSB0')

POT = 0
LED1 = 13
LED2 = 12
LED3 = 11
LED4 = 10
LED5 = 9
LED6 = 8
LED7 = 7
LED8 = 6

Arduino.pinMode(POT, Arduino.INPUT)
Arduino.pinMode(13, Arduino.OUTPUT)
Arduino.pinMode(12, Arduino.OUTPUT)
Arduino.pinMode(11, Arduino.OUTPUT)
Arduino.pinMode(10, Arduino.OUTPUT)
Arduino.pinMode(9, Arduino.OUTPUT)
Arduino.pinMode(8, Arduino.OUTPUT)
Arduino.pinMode(7, Arduino.OUTPUT)
Arduino.pinMode(6, Arduino.OUTPUT)

print "starting"
while True:
    pot = Arduino.analogRead(POT)
#this is the section that is blinking when it should stay solid
   if pot < 450:
        Arduino.digitalWrite(LED1, Arduino.HIGH)
        Arduino.digitalWrite(LED2, Arduino.HIGH)
        Arduino.digitalWrite(LED3, Arduino.HIGH)
        Arduino.digitalWrite(LED4, Arduino.HIGH)
        Arduino.digitalWrite(LED5, Arduino.LOW)
        Arduino.digitalWrite(LED6, Arduino.LOW)
        Arduino.digitalWrite(LED7, Arduino.LOW)
        Arduino.digitalWrite(LED8, Arduino.LOW)
        sleep(.5)
# end of section
   if pot < 650 > 450:
        Arduino.digitalWrite(LED1, Arduino.LOW)
        Arduino.digitalWrite(LED2, Arduino.LOW)
        Arduino.digitalWrite(LED3, Arduino.LOW)
        Arduino.digitalWrite(LED4, Arduino.LOW)
        Arduino.digitalWrite(LED5, Arduino.LOW)
        Arduino.digitalWrite(LED6, Arduino.LOW)
        Arduino.digitalWrite(LED7, Arduino.LOW)
        Arduino.digitalWrite(LED8, Arduino.LOW)
        sleep(.1)
    if pot > 650:
        Arduino.digitalWrite(LED1, Arduino.LOW)
        Arduino.digitalWrite(LED2, Arduino.LOW)
        Arduino.digitalWrite(LED3, Arduino.LOW)
        Arduino.digitalWrite(LED4, Arduino.LOW)
        Arduino.digitalWrite(LED5, Arduino.HIGH)
        Arduino.digitalWrite(LED6, Arduino.HIGH)
        Arduino.digitalWrite(LED7, Arduino.HIGH)
        Arduino.digitalWrite(LED8, Arduino.HIGH)
        sleep(.5)
    print pot


texts: Using a potentiometer to control number of lit pixels on an NeoPixel strip

texts:
I'm working on controlling an Adafruit NeoPixel strip with an Arduino and a potentiometer. Specifically, I'm trying to use the potentiometer to control how many pixels are lit up on the strip. As I turn the potentiometer "up" (i.e., increasing the value), the number of lit-up pixels increases.

However, if I try to turn the potentiometer the other way and decrease the number of lit-up pixels, then the strip will stay at whatever the last value was.

I have a method below that's called during the 'void loop()' method that read in the potentiometer data:

void readAndSendPotentiometerDataIfChanged(void) {
 //Read data from analog pin 2, and scale it
 int newPotentiometerValue = analogRead(A2) / 5.68;
  if (newPotentiometerValue != lastPotentiometerValue) {
      Serial.print("POT. value");
      Serial.print(newPotentiometerValue);
      lastPotentiometerValue = newPotentiometerValue;

      /* The value of "colorVal" is determined by a switch, and seems to be
         working properly */
      if (colorVal == "RED") {
        //If the value is 0, we want to clear the pixel values to white
        if (lastPotentiometerValue == 0) {
          clearPixels();
        } else {
          colorWipe(strip.Color(255, 0, 0)); // Red
        }
      } else if (colorVal == "BLUE") {
        if (lastPotentiometerValue == 0) {
          clearPixels();
        } else {
          colorWipe(strip.Color(0, 0, 255)); // Blue
        }
      }
   }
}

The method below will clear out all 180 pixels on my strip to no color (clear).

void clearPixels() {
   uint16_t clearColor = (127, 127, 127);
   strip.setPixelColor(180, clearColor);
   strip.show();
}

Here's where the pixels on the strip get set...I'm sure the problem is in the for loop below, but I haven't been able to come up with a better way to set the pixels on the strip and then turn them on:

void colorWipe(uint32_t c) {

  /* Use the value of 'lastPotentiometerValue' to determine how many pixels
   on the strip should be lit up */
  for(uint16_t i=0; i<lastPotentiometerValue; i++) {
    strip.setPixelColor(i, c);
    delay(0.5);
  }
   strip.show();
}

Anyone have a pointer to how I could refactor my code so that the potentiometer works in both directions, and will light up or turn off the pixels on the strip as appropriate? Thank you!

EDIT Based on Ignacio's answer, I changed my colorWipe method to this:

void colorWipe(uint32_t c) {

  for (uint16_t i = lastPotentiometerValue; lastPotentiometerValue<180; i++){
      uint16_t clearColor = (127, 127, 127);
      strip.setPixelColor(i, clearColor);
  }

  for(uint16_t i=0; i<lastPotentiometerValue; i++) {
    strip.setPixelColor(i, c);
    delay(0.5);
  }

   strip.show();
}

However, now no strips are lit up.

EDIT 2

The condition was wrong; below is the code that works:

void colorWipe(uint32_t c) {

  for(uint16_t i = lastPotentiometerValue; i<180; i++){
      uint16_t clearColor = (0, 0, 0);
      strip.setPixelColor(i, clearColor);
  }

  for(uint16_t i=0; i<lastPotentiometerValue; i++) {
    strip.setPixelColor(i, c);
    delay(0.5);
  }

   strip.show();
}


texts: Arduino: pins still active after entering sleep mode

texts:
I'm writing an Arduino sketch to control a display with my Arduino Nano. I have wired it up as explained here, but used pin 3-7 instead of pin 2-6 listed in the example. The reason I did so is that I also added a push-button on interrupt 0 (= digital pin 2). I'm calling the sleep mode with a method, as explained in the section "Example" here. The Arduino seems to sleep, turning off all LEDs but the on/off one. The problem I have now is that the LCD display is sometimes still enabled (but only sometimes, not always). Why is it behaving like this? And how can I switch off everything possible to save as much energy as possible?

Here is my code piece:

int buttonPin = 2;

void setup()
{
  pinMode(buttonPin , INPUT);
  digitalWrite(buttonPin , HIGH);
  ...
}

void loop() {
  ...
  if(counter == 100) {
    enterSleep();            // Enter sleep method!
  }
  delay(1000);
}

void enterSleep()
{
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  attachInterrupt(digitalPinToInterrupt(2), wakeUpNow, LOW);
  sleep_mode();

  /* The program will continue from here. */
  /* First thing to do is disable sleep. */
  sleep_disable();
  detachInterrupt(digitalPinToInterrupt(2));
}

void wakeUpNow() {
  // execute code here after wake-up before returning to the loop() function
  // timers and code using timers (serial.print and more...) will not work here.
  // we don't really need to execute any special functions here, since we
  // just want the thing to wake up
}


texts: Cannot instantiate SLIPSerial object used in OSC/SLIPSerial classes for Arduino

texts:
Hey I'm trying to test out the CMAT/OSC library for Arduino and just want to get up and running sending SLIP encoded OSC messages. I've been able to observe the typical Serial monitor when sending OSC Messages that way, but I cannot seem to get the example code to compile:

    #include <SLIPEncodedSerial.h>
    #include <OSCData.h>
    #include <OSCBundle.h>
    #include <OSCBoards.h>
    #include <OSCTiming.h>
    #include <OSCMessage.h>
    #include <OSCMatch.h>
    #include <SLIPEncodedUSBSerial.h>

    SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
    // SLIPEncodedSerial SLIPSerial(Serial);

    void setup() {
      //begin SLIPSerial just like Serial
      SLIPSerial.begin(9600);   // set this as high as you can reliably run on your platform
    }

    void loop(){
      //the message wants an OSC address as first argument
      OSCMessage msg("/address");
      msg.add("Hello World\n");
    ;

      SLIPSerial.beginPacket();
      msg.send(SLIPSerial); // send the bytes to the SLIP stream
      SLIPSerial.endPacket(); // mark the end of the OSC Packet
      msg.empty(); // free space occupied by message
      delay(20);
    }

Furthermore this is the output error I see:
error: 'SLIPEncodedUSBSerial' does not name a type; did you mean 'SLIPEncodedUSBSerial_h'?
   10 | SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
      | ^~~~~~~~~~~~~~~~~~~~
      | SLIPEncodedUSBSerial_h
exit status 1
'SLIPEncodedUSBSerial' does not name a type; did you mean 'SLIPEncodedUSBSerial_h'?

Could someone lend some clarity on what "thisBoardsSerialUSB" and "Serial" are in this context? I thought that the SLIPEncodedSerial / SLIPEncodedUSBSerial constructors simply take a reference. This might be trivial, but I am not sure how to properly instantiate these classes within the Arduino IDE.
Cheers!


texts:
I can't compare for the condition Error "sensors not int type" translate to int type does not work. Please tell me the solution to this problem
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define ONE_WIRE_BUS 2
#define Rele 5

OneWire oneWire(ONE_WIRE_BUS);
LiquidCrystal_I2C lcd(0x27,16,2);
DallasTemperature sensors(&oneWire);

int tmp;
int PotenciometrPin = A0;
int val;

void setup(void)
{
 pinMode(Rele, OUTPUT);
 digitalWrite(Rele, HIGH);

 lcd.init();
 lcd.backlight();
}

void loop(void)
{
 lcd.setCursor(0, 0);
 sensors.requestTemperatures();
 val = analogRead(PotenciometrPin);
 lcd.print("Ustonovit`: ");
 val = map(val, 0, 1023, 0, 100);
 lcd.print(val);
 int(sensor);
 // if(val = sensors){ <-- THIS PROBLEM
 //digitalWrite(Rele, LOW);
 // }
 lcd.setCursor(0, 1);
 lcd.print("Fakt: ");
 lcd.print(sensors.getTempCByIndex(0));
 delay(1000);
}


texts: What is the format specifier for string in arduino

texts:
I have a string formattedDate.
When I am trying to give sprintf(payload,"{\"timestamp\":\"%s\",\"temperature\":%f,\"humidity\":%f}",formattedDate,t,h);
Its not printing the date and time.


texts:
I'm taking a course on Arduino Uno programming and on today's talk I heard that the const data is optimized by Arduino, so that it occupies less space than the actual data type (namely, a const int occupies less than an int).

If instead of int I use const uint8_t, const uint16_t etc. is the optimization still applied, or does using the 8 and 16 bit ints represent bad practice?


texts: Computer to Arduino to hardware, controlling on / off state of hardware via user input on computer

texts:
First time coding for Arduino. I'm working on code to operate an electronic valve switch. We have a laptop connected to an Arduino Mega, and that Arduino is hooked up to the valve (hardware) on Pin 53.

I was trying to work off of the "blink" example originally, but that gives no basis for user prompted control. Basically I want to have the computer ask me if I should turn it on or off, type in my response (I was using "HIGH" for on and "LOW" for off, as in voltage control), and have that activate or deactivate the hardware.

My main problem right now stems from how best to ask for that input. I've been trying to work with the Messenger.h library thus far. I'm definitely getting hung up on how to define the pin, or what the simplest method for user input would be. (HIGH or LOW? 0 or 1? Something else?)

Code is below. Thanks!

#include <Messenger.h>

Messenger message = Messenger();

// Variable definitions. Switchinput is what the user commands, current state is whether the air is flowing or not.
boolean currentstate;
boolean switchinput;
String pin53; // Something is up on this line?? How to define this pin??

// FUNCTION DEFINITIONS
// Startup fxn
void start()
{
  Serial.print("LOW = off, HIGH = on. Switch is ");
  Serial.println(currentstate);
  Serial.print("Enter LOW to turn on or HIGH to turn off: ");
  switchinput = Serial.read();
}

// Go off to on
void offtoon()
{
    digitalWrite(pin53,HIGH);
    currentstate = switchinput;
}

// Go on to off
void ontooff()
{
    digitalWrite(pin53,LOW);
    currentstate = switchinput;
}

// Stay same -- already off
void staysameoff()
{
  if ((currentstate = switchinput) && (switchinput = LOW))
  {
      void start();
  }
}

// Stay same -- already on
void staysameon()
{
  if ((currentstate = switchinput) && (switchinput = HIGH))
  {
    void start();
  }
}

// Running actual code
void setup()
{
  // initialize digital pin 53 as an output.
  pinMode(pin53, OUTPUT);

  // Sets default state to switch being off (Off = LOW, On = HIGH)
  String currentstate = LOW;
}

void loop()
{
   if ((currentstate != switchinput) && (switchinput = HIGH))
  {
      void offtoon();
  }

  if ((currentstate != switchinput) && (switchinput = LOW))
  {
      void ontooff();
  }

  if ((currentstate = switchinput) && (switchinput = LOW))
  {
      void staysameoff();
  }

  if ((currentstate = switchinput) && (switchinput = HIGH))
  {
      void samestayon();
  }
}


texts: How can I pause a stepper motor with a ultrasonic sensor?

texts:
I'm trying to use a stepper motor to stay stationary and rotate about 90 degrees, when the ultrasonic sensor detects something in front of it, and stay at that position until the ultrasonic sensor does not detect anything in front of it any more, to which the motor will rotate back to it's original position.

I'm using an Arduino Uno, a Longruner 5X Geared Stepper Motor 28byj 48 Uln2003 5v Stepper Motor with a  Uln2003 Driver Board.

#include <Stepper.h>

const int stepsPerRevolution = 200;

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

// defines pins numbers
const int trigPin = 7;
const int echoPin = 6;

// defines variables
long duration;
int distance;

void setup() {

   pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
   pinMode(echoPin, INPUT); // Sets the echoPin as an Input
   Serial.begin(9600); // Starts the serial communication
   myStepper.setSpeed(60);
    // initialize the serial port:  (again??)
   Serial.begin(9600);
}

void loop() {
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
   duration = pulseIn(echoPin, HIGH);

// Calculating the distance
   distance= duration*0.034/2;

// Prints the distance on the Serial Monitor
   Serial.print("Distance: ");
   Serial.println(distance);

   if (distance < 10) {
       myStepper.step(-stepsPerRevolution);
       delay(1000);
       if (distance > 10) {
           myStepper.step(stepsPerRevolution);
           delay(10000);
       }
   }
}

Here's my code. I can't really figure out how to stop/pause the stepper motor once it rotates. Any ideas? (I'm a beginner, so apologies for any beginner mistakes).


texts: anyone heard of MCUDEV_TFT1.44 display? I can't figure out how to connect it to Arduino

texts:
I bought this tft display on Aliexpress:
https://www.aliexpress.com/item/1005001579367288.html?spm=a2g0s.9042311.0.0.72164c4doyqAub
it says "MCUDEV_TFT1.44" below the display.

I can't find online how to connect it to Arduino.
The pins are as follows:
BLK RS RST CS SC DI GND VCC
on Aliexpress it says "Drive IC: ST7735" but I googled ST7735 displays and they have different pins.
Anyone has any idea?
Thanks!


texts:
I have an Arduino mega that is being used to control relays and ultrasonic sensors.  The relays that I am using is a 4 DPDT Signal Relay Module Model: D-256 Series and the other is a 4 channel Single pole Relay for Arduino. I am only using 3 channels of each relay. At any given time I only output to 2 channels from each relay at a time. I tested the relay to ensure they worked with the Arduino and they ran fine.

Once I connected the Ultrasonic sensors to the board as well, the board would not power and the voltage regulator got extremely hot. I would assume the total current draw was too high from the outputs and VCC of the Arduino.

I think that if I take my 9V battery and run it through a voltage regulator 7805 then I can run the VCC power of the relays with the battery instead of the VCC from the Arduino. This would result in me only running a VCC to the 4 ultrasonic sensors, the triggers for the ultrasonics from the Arduino, and the output signals fora maximum of 2 channels per relay board resulting in 4 relays. Most of the time it is only 2 relays.

Would I be able to power the relay boards VCC with the 9V running through a 5v regulator instead of the arduino so that I can reduce the current running through the Arduino?


texts:
I'm trying to perform a simple analogRead() and print out the result, as below:

void getVoltMeter() {

  readValue = analogRead(A2);
  readByte = readValue/4;
  Serial.println(readValue);
  Serial.println(readByte);

}

But the output is:

023
255

The voltage input is 5V, so I would expect it to read:

1023
255

Why is the first digit being cut off?


texts:
I am testing a set-up using the TinkerKit shield for Arduino Uno, and a few TinkerKit inputs and outputs. I have an issue with the code provided on the TinkerKit website for the potentiometer component:

#include <TinkerKit.h>

// creating the object 'pot' that belongs to the 'TKPotentiometer' class
TKPotentiometer pot(I0);

// creating the object 'led' that belongs to the 'TKLed' class
TKLed led(O0);

int brightnessVal = 0;  // value read from the pot

void setup() {
  // initialize serial communications at 9600 bps
  Serial.begin(9600);
}

void loop() {
  // read the potentiometer's value:
  brightnessVal = pot.read();

  // set the led brightness
  led.brightness(brightnessVal);

  // print the results to the serial monitor:
  Serial.print("brightness = " );
  Serial.println(brightnessVal);

  // wait 10 milliseconds before the next loop
  delay(10);
}

I get an error message when compiling:

Class TKPotentiometer has no member named 'read'

According to this webpage, though, read should be a member of the class. Why am I receiving this message?


texts: Arduino R/C compatible transmitter and reciever

texts:
I want to make a RC buggy or something down those lines (using Legos of course) and I'm confused while looking what transmitter/receiver to use. Would like a simple classic remote and any compatible receiver for the Arduino.
Found such a remote: http://www.hobbypartz.com/79p-th9x-r9b-9channel-radio.html
But this seems way overkill for what I want to do. Any links or suggestions would be appreciated. Hope the question isn't too broad for stack exchange.


texts:
I have been programming for quite a while now but I am new to Arduino and AVR Programming. The main question I have about programming these Micro-controllers is are there major differences in designing code in Object Orientated Classes vs the more traditional inline programming I have seen in many examples?

In other words in the world of Arduino/AVR Controllers are there any savings with Memory and Performance utilizing classes or visa versa?

Say for example we have a Class:

class SomeClass(){

private:
   int x;
   int y;

public:
   void foo();
   void bar();
}

SomeClass thisClass;
thisClass.foo();
thisClass.bar();

Would there be any performance or memory gains designing the program in a more inline fashion like:

int x;
int y;

void foo(){ /*** Do something ***/};
void bar(){ /*** Do more stuff ***/};

I tried doing some searches on Stack Exchange and Google but couldn't find quite the answer I am looking for the closest thing I was able to find was this Stack Exchange Question.

The reason I am asking about this is I have a project that needs to be as light as possible and I am not clear how I should be designing my program in this environment.

Edit

Thank you for the answers, this has shed light on things. There is one thing that I am not quite clear about.

Say you have a class that you are designing that utilizes the u8glib as follows:

class UserInterface{
private:
   U8GLIB_ST7920_128X64 Display;

public:
   UserInterface();
}

How would you get around using "Dynamic Memory" like:

UserInterface::UserInterface(){
   UserInterface::Display = U8GLIB_ST7920_128X64(LCD_E_PIN, LCD_RW_PIN, LCD_RS_PIN, U8G_PIN_NONE);
}


texts: Web Page doesn't load when data is being received from Xbee

texts:
I have an Arduino Mega I am using as a simple web server. Right now the web page is two simple lines of text. There is an XBee radio attached to the unit to receive data from another unit. However, when the server unit is receiving data the web page will not start up. There's a switch on the shield to switch it into Micro for the radio, or USB. If I reset, or power on, the server unit with the switch in USB mode it loads fine; then once the web page loads I can flip it on Micro and it will refresh fine even while receiving data. However, if I try to power on the unit, or reset the unit, with the switch on Micro it will not load the web page. Any ideas on why this is happening?

Schematic:

Server Unit: Ethernet shield with HanRun HR911105A 13/15 ethernet jac placed on Mega ADK. There is a Wireless Proto Shield with XBee Pro 538 radio placed on the ethernet shield.

Remote Unit: There is a Wireless Proto Shield with XBee Pro 538 radio placed on the Mega ADK.

setup():

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

    // start the Ethernet connection and the server:
    Ethernet.begin(mac, ip);//, gateway, mask);
    server.begin();
}

loop():

void loop() {
    // Listen for incoming clients
    client = server.available();
    if (client) {
        boolean currentLineIsBlank = true;
        while (client.connected()) {
        if (client.available()) {
            char c = client.read();

            // if you've gotten to the end of the line (received a newline
            // character) and the line is blank, the http request has ended,
            // so you can send a reply
            if (c == '\n' && currentLineIsBlank) {

                // Send a standard http response header
                client.println("HTTP/1.1 200 OK");
                client.println("Content-Type: text/html");
                client.println("Connection: close");  // the connection will be closed after completion of the response
                client.println("Refresh: 5");  // refresh the page automatically every 5 sec
                client.println();
                client.println("<!DOCTYPE HTML>");
                client.println("");

                client.println("
");
                client.println("");
                client.println("");
                client.println("My WebPage");
                client.println("
");
                client.println("Web Server and Radio Receiver ");
                client.println("
");
                client.println("version November 30, 2016");
                client.println("
");
                client.println("");
                client.println("");
                client.println("");

                break;

            }
            if (c == '\n') {
                // you're starting a new line
                currentLineIsBlank = true;
            } else if (c != '\r') {
                // you've gotten a character on the current line
                currentLineIsBlank = false;
            }
        }
    }
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}


texts: Want to create bluetooth audio control (volume up/down, play, pause, etc.) for smartphone

texts:
I want to create a bluetooth remote audio control to control smartphone audio, essentially identical in function to this type of equipment:

https://www.amazon.com/FAVOLCANO-Bluetooth-Button-Smartphone-Samsung/dp/B01C5E95XG/ref=pd_lpo_147_bs_t_1?ie=UTF8&refRID=1GRBCPDRMD9YPYPGK73Y

This device is simply a bluebooth remote control which allows you to play or pause audio, skip forward or backward and change media volume on the smart phone.

All of the Arduino tutorials I see are about either using the iPhone to control a bluebooth device, or about using bluetooth to control an arduino, neither of which are what I want to do.

Can you point me in the right direction?


texts:
I am working on a project where the ESP 8266 sends a very long string about 3000 chas over http as client. Likewise sensor data are determined. The loop repeats itself every 250ms. Now I noticed that my server gets the data of the ESP often slower. In rare cases it takes up to a minute until the server receives something.
How do these delays occur and why are they not constantly the same?
Does the length of the string have something to do with it or how much does it affect the delay?
Are calculation and sensors processed only after sending?
The ESP works with this function.
String http_GET(String value){
  String payload = "non_Message";
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
    //WiFiClient client;
    HTTPClient http;  //Declare an object of class HTTPClient
    String send_data = "http://" + web_conect + value;
    //http.begin(client, send_data);
    http.begin(send_data);
    //http.begin("http://" + address + ":" + port + "/" + path +"?" + param + "=" + value);  //Specify request destination
    int httpCode = http.GET();                                  //Send the request

    if (httpCode > 0) { //Check the returning code

      payload = http.getString();   //Get the request response payload
      Serial.println(payload);             //Print the response payload
      cut_time_date(payload);

    }

    http.end();   //Close connection

  }
  return payload;
}


texts: expected primary-expression before ',' token ...problem

texts:
this the problem---expected primary-expression before ',' token

#define motor

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

void loop()
{
  digitalWrite(motor,HIGH);
  // put your main code here, to run repeatedly:

}


texts: Rc car controller using the RC-switch library

texts:
simulate this circuit – Schematic created using CircuitLab

(Newbie in arduino)
Hi so i have a project which involves creating an rc car which uses the 433Mhz rf module and an arduino nano with a servo motor and an ultrasonic parking sensor.

I'm having problems with the code both on the transmitter and receiver,
Here is the code for the transmitter.

 #include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
// Assigning controller buttons to Digital Pins
 const int forward = 8;
 const int reverse = 9;
 const int rightTurn = 10;
 const int leftTurn = 11;

 int Fwd = 0
 int Bwd = 0
 int Lt  = 0
 int Rt  = 0

void setup () {
  pinMode (forward, INPUT);
  pinMode (reverse, INPUT);
  pinMode (rightTurn, INPUT);
  pinMode (leftTurn, INPUT);
  mySwitch.enableTransmit(7);
  Serial.begin (9600);         // Debugging only
  Serial.println ("Transmitting");
}

void loop () {
  Fwd = digitalRead(forward);
  Bwd = digitalRead(reverse);
  Rt  = digitalRead(rightTurn);
  Lt  = digitalRead(leftTurn);

  if (Fwd == HIGH) {
    mySwitch.send('1');
    Serial.println ("Forward");
    delay(100);
  }

  if (Bwd == HIGH) {
    mySwitch.send('2');
    Serial.println ("Reverse");
    delay(100);
  }

  if (Rt == HIGH) {
    mySwitch.send('3');
    Serial.println ("Left Turn");
    delay(100);
  }

  if (Lt == HIGH) {
    mySwitch.send('4');
    Serial.println ("Right Turn");
    delay(100);
  }
}

And here's the code for the receiver

#include <RCSwitch.h>
#include <Servo.h>

const int IN1 = 3;
const int IN2 = 4;
const int trigPin = 5;
const int echoPin = 6;
int distance = 0;

RCSwitch mySwitch = RCSwitch();
Servo myservo;

void setup () {
  mySwitch.enableReceive(2);
  myservo.attach(7);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin (9600);    // Debugging only
  Serial.println ("Receiver Ready");
}

void loop () {
 if (mySwitch.available()) {

    int value = mySwitch.getReceivedValue();

      if(value == '1') {
        forward ();
        Serial.println (" = forward");
      }

      if(value == '2'){
        backward ();
        Serial.println (" = backward");
      }

      if(value == '3') {
        left ();
        Serial.println (" = left");
      }

      if(value == '4') {
        right ();
        Serial.println (" = right");
      }
      Serial.print(" ");
    }

}

void forward () {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
}
long duration;
int value = mySwitch.getReceivedValue();
void backward () {
  if ((distance > 10)&& (value == '2'))
  {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, LOW);
  }
  else if ((distance < 10)&& (value == '2'))
  {
  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  }
  delayMicroseconds(10);
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance= duration*0.034/2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance); //distance is the returned integer,
}

void right () {
  myservo.write(0);
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
}

void left () {
  myservo.write(90);
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
}

The problem is when i run the code the buttons start getting pressed even if I'm not pressing them and even when i disconnect them from the arduino. and also the receiver cant receive any data.
Please help


texts: What is the datatype of the pinMode function?

texts:
I just tried it, but the Arduino IDE crashed, I hope its not related.
I want to declare a datatype like this:

int a = pinMode(pin, OUTPUT);

or something like that, but I'm not sure what datatype the pinMode function uses. I looked on the pinMode documentation page, of the Arduino website, and I see basic usage, but not a more clear definition of the source code for that function.


texts: I am making my blinds automatic, but I don't want to use a delay

texts:
I am trying to make it so I can pull the time so that they open at 8 am and close at 10 pm. The loop is already set up to open and close the blinds completely.
#include <CheapStepper.h>

CheapStepper stepper;

boolean moveClockwise = true;
int motorPostion = 10;
boolean up = true;
boolean down = false;

void setup() {
  Serial.begin (9600);
  Serial.println ("Ready to start moving");
}

void loop() {

    for (int i = 1; i < 16384; i++)
      {
      stepper.step (moveClockwise);
      Serial.println (i);
      int nStep = stepper.getStep();

      if (nStep%4096==0) {
        Serial.println ("Moved full rotation Clockwise");
        }
     }

    for (int i = 16384; i > 0; i--)
      {
      stepper.step (!moveClockwise);
      Serial.println (i);
      int nStep = stepper.getStep();

      if (nStep%4096==0) {
        Serial.println ("Moved full rotation Counter Clockwise");
      }
    }
  }


texts:
I've been trying on and off to try and get my nrf24l01's working for some time and they never seem to work. Right now I'm just trying to turn a led on and off over the radio and it isn't working.

Here's the code for the transmitter

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define button 5
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
boolean buttonState = 0;
void setup() {
  pinMode(5, INPUT_PULLUP);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {

  buttonState = digitalRead(button);
  radio.write(&buttonState, sizeof(buttonState));
}

And here's the code for the receiver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

int led = 2;
RF24 radio(7, 8); // CE, CSN
boolean buttonState = 0;
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
 radio.startListening();
  while (!radio.available());
  radio.read(&buttonState, sizeof(buttonState));
  if (buttonState == HIGH)
  {
    digitalWrite(led, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }
}

I have the voltage regulator which steps the 5v arduino to 3.3 to the chip so I don't think not having a capacitor (what others recommended) is a problem. I have both radio chips hooked up to arduino nanos.

For the transmitter and receiver I have CE=7,CSN=8, SCK=13, MO=11, and MI=12

I also know that my led is working and the code for my button is working. Is there a problem with my code or is there a chance that my chips are broken even if im using a voltage regulator


texts:
So I have been experimenting with keyboard inputs and I think I may have accidentally put a loop in my code that never actually ends the keyboard input thus not allowing me to upload any sketches to fix the problem.

Here is the error code I got when I tried to upload a blank into the qduino:

Arduino: 1.8.1 (Windows Store 1.8.1.0) (Windows 10), Board: "Qduino Mini"

Build options changed, rebuilding all
Sketch uses 4136 bytes (14%) of program storage space. Maximum is 28672 bytes.
Global variables use 148 bytes (5%) of dynamic memory, leaving 2412 bytes for local variables. Maximum is 2560 bytes.
An error occurred while uploading the sketch
processing.app.SerialException: Error opening serial port 'COM11'.
    at processing.app.Serial.<init>(Serial.java:125)
    at processing.app.Serial.<init>(Serial.java:66)
    at processing.app.SerialMonitor$3.<init>(SerialMonitor.java:93)
    at processing.app.SerialMonitor.open(SerialMonitor.java:93)
    at processing.app.AbstractMonitor.resume(AbstractMonitor.java:110)
    at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2240)
    at processing.app.Editor.access$2400(Editor.java:77)
    at processing.app.Editor$DefaultExportAppHandler.run(Editor.java:2315)
    at java.lang.Thread.run(Thread.java:745)
Caused by: jssc.SerialPortException: Port name - COM11; Method name - openPort(); Exception type - Port busy.
    at jssc.SerialPort.openPort(SerialPort.java:164)
    at processing.app.Serial.<init>(Serial.java:114)
    ... 8 more
Error opening serial port 'COM11'.

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


texts: Arduino UNO not sending serial data to ESP32

texts:
Lately I've been struggling with Serial communication between Uno and ESP32. I'm trying to send a simple string (In my case "100") from my Uno to my ESP32. I made a voltage divider and I'm using HardwareSerial Serial2(1) for the Serial reading on the ESP32's side. On my Uno's side, I use Pin 9 for sending data a.k.a Pin 9 goes to the voltage divider and links with RX2 (GPIO16) on my ESP32, like in the picture below.
My Uno code is:
void setup() {
Serial.begin(9600);
}

void loop() {
Serial.print("100");
delay(2000);
}

and on the other side, ESP32's code:
#define RXD2 16
#define TXD2 -1

HardwareSerial Serial2(1); // Use UART channel 1

void setup() {
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}

void loop() {
if(Serial2.available() >= 1){
Serial.print(Serial2.read());
}
else {
Serial.print("Not sending");
}
delay(2000);
}

I'm not receiving the data and I get "Not sending" all the time.
My question is: Should I use TX pin from my Uno instead of pin 9? Or there's something wrong with my code?
Thank you in advance


texts: Processing printing sensor readings and raising NaN exception at the same time

texts:
I am using pressure sensor with Arduino Uno within Processing.
Given these variables:

Serial myPort;              //the serial port
float sensorValue = 0;      //the value form the sensor

Arduino is printing float numbers on Processing console, according to the snippet below.

(...)

void serialEvent (Serial myPort){
//get the ASCII string
String inString = myPort.readStringUntil('\n');

if (inString != null){
//trim off any whitespace:
inString = trim(inString);
//convert to an int and map to the screen height
sensorValue = float(inString);
println(sensorValue);
sensorValue = map(sensorValue, 0, 1023, 0, height);
//println(sensorValue);

However, I am getting a NaN exception:

sensorValue = map(NaN, 0, 1023, 0, height);

how is this possible? printing numbers that aren't numbers?


texts:
I´m trying to make a pause in a loop, but just for the first time it loops. The next loops i would like the program to NOT do the pause. Just once time, each time a button is pressed. Does anybody knows how to do it?
Thanks!
This is the code i want to pause just once:
void loop() {
  if(digitalRead(switch_pin) == LOW){
    digitalWrite(led_green_pin,LOW);
    digitalWrite(led_red_pin,HIGH);
    lastMotionState    = currentMotionState;
    currentMotionState = digitalRead(MOTION_SENSOR_PIN); //
      if (currentMotionState == LOW && lastMotionState == HIGH) {
      servo.write(90);
      }
      else
      if (currentMotionState == HIGH && lastMotionState == LOW) { // pin state change: HIGH -> LOW
      servo.write(0);
      }
  }


texts: Small, Power-Efficient wireless communication with ATTiny85

texts:
For a project that I'm working on I need an extremely small, power efficient wireless device (could be radio, or some other interface) to network between a series of ATTiny85s and a larger Arduino. The communication range only needs to be about 1 foot, max. I'm currently using wired I2C, so it would be excellent if someone could suggest a radio or another device that can use the two digital pins previously occupied by the SCK and SDA lines on the ATTiny. I have those two, along with one extra digital pin available for use.

This device needs to be extremely small - this common NRF24L01 package is too big and its SPI interface uses too many pins.

Thanks for your help.


texts: Conflicts with USB and external power supply

texts:
I want to power an Arduino Leonardo with an external power supply and simultanously communicate via USB. I have read some other threads on this topic, therefore, I know that if one supplies more than 7V over the power jack, the board will use the external power supply in this case.

My suspicion is rather concerning the ground connection. From the schematic, I can tell that the USB ground is connected via a tiny coil to the board ground, so with DC it is shorted. Wouldn't that cause problems if the computer's USB ground is at a different potential than the external power supply of the board, resulting in a voltage between the two grounds? What if this voltage is up to several Volts?

Thanks a lot!


texts: Arduino Analog pins go all to high problem

texts:
I was taking measures from the  outputs of an OpAmp when all the sudden measure 5 volts from all pins of the Arduino Mega for no reason. I disconnected the Arduino and loaded the Firmata and test. All the pins are reading high to 1023.. 5 volts are been output for no reason even when I have the Analog Ping to input.

Sketches code are loading and the lights look normal. I did noticed the processor chip getting hot and the voltage in the breadboard line to the Arduino Analog pins reading 7 volts.

Is this a sign of a serious damaged to my device?


texts:
I wanted to understand how people are connecting a servo motor to pins without PWM, so I went searching and I read that the Servo library uses the timer1 of pin 9 and pin 10 to be able to use other pins.

I would like to ask some questions about this.

Could I connect a servo motor on pin 12 by emulation of the library, and another servo on pin 9, another on pin 10 and another on pin 11 at the same time?
Or using the Servo library the PWM in pin 9 and 10 stops working?
I could then through library emulation connect one servo on pin 7, another on 8, another on 12 and another on 13 ?
4 emulations at the same time?


texts:
I have written a arduino sketch which is used to measure the distance travelled. Since distance = speed * time , I have initiated speed = 6. I have initiated time = millis() variable and it calculates the time in millis().

So, distance is calculated as (speed*time) /1000 and we get distance for every second.

Now, as soon as the distance==20, I want to print distance and then delay for 5 seconds. So, as soon as distance==20 implies time = 4000 . If I delay for 5 seconds, time becomes 9000. But I want time to start from 4000 itself. So I have initiated another variable called curTime = time - prevTime.At the start, prevTime = 0. Code:

int prevTime = 0;
void loop(){
  unsigned long time = millis();
  unsigned long curTime = time - prevTime;
  int speed = 6;
  unsigned long distance = (speed * curTime)/1000;
  Serial.println(distance); // displays values of distance
  if(distance == 20){
    Serial.println(distance);
    delay(5000);
    prevTime = time;
  }
}

So prevTime = 4000 if distance == 20.
After this, time will be equal to 9000 and curTime will be 9000-4000 which equal 5000. So the distance will be 30 skipping all the values between 20 and 30. I don't want the distance to skip the values between 20 and 30. I have tried a lot but couldn't achieve it. Please help me fix this.

Thanks.

Link for code:

https://circuits.io/circuits/5260912-the-unnamed-circuit/edit


texts: how to ignore a sensor being tripped the first time and start recording millis on the 2nd time it is tripped

texts:
I am building a timing system that has a start, split and finish beams with this I am using a start gate that will drop when the race starts. when it drops it will trip the 1st sensor starting to count the millis which I am using to calculate the time. I am using IR sensors to that give me the 3 times based on the millis and then I do a calculation in excel that will give me the split and finish time.
Where I am running into issues is that after the person goes through the 3 timer sensors I have to close the start gate which trips the first sensor which messes up my times for the next person.
So I need to adjust my sketch so it takes this into consideration when it starts counting the millis. Basically I am thinking it needs a line of code to have the 1st sensor == LOW once and do nothing and then on the 2nd time that same sensor is == LOW it records the millis from that point.
Below is the sketch I am working on.
//timer
unsigned long start, reaction, push, elapsed;

void setup()
{
  Serial.begin(115200);
  pinMode(2, INPUT); // start switch
  pinMode(3, INPUT); // split sensor
  pinMode(4, INPUT); // finish sensor
}

void loop(){

if (digitalRead(2) == LOW)
  {

    start = millis();

  }

  if (digitalRead(3) == HIGH)
  {

    reaction = millis();
 //   delay(200); // for debounce

  }

     if (digitalRead(4)==HIGH)
      {

       push=millis();
       delay(500); // for debounce

    Serial.print(start);
    Serial.print(",");
    Serial.print(reaction);
    Serial.print(",");
    Serial.print(push);
    Serial.println();

  }

}