texts: Switch case options get broken after a function call

texts:
I'm sorry for the basic question, but I have a switch case where any code placed after a certain function call simply never gets called, and I've spent half a day looking at it, so thank you so much for your help.
Running on an Arduino UNO.
Here is the loop, and every option in the switch case after the call to moist_sensor.read() simply never gets in:

void loop() {

  while (Serial.available() > 0) {
    char val = (char)Serial.read(); // read data byte by byte and store it
    Serial.println(val);
    switch(val) {

      case 'O':
            digitalWrite(13, LOW);

            break;

      case 'I':
            digitalWrite(13, HIGH);

            break;

      case 'W':
            water(2000);
            break;

      case 'E':

            int reading = moist_sensor.readd(); //THE PROBLEMATIC LINE
            //Serial.println(reading); // send the received data back to raspberry pi
            break;

//it never enters any of these cases below

      case 'M':

        //String reading2 = moist_sensor.packaged_reading();
        //Serial.println(reading2); // send the received data back to raspberry pi
        break;

      case 'W':

        water(5000);
        break;

      default:

        delay(5000);

    }
  }

I've tried changing the name of the function with fears of special keywords, swapping it with other cases (such as putting case 'W' above, where it works, and vice versa), and I always get the same behaviour. If i comment the line, everything works as expected.
I know the method isn't actually called all the time, but for sanity's sake, moist_sensor.readd() right now is just:
int readd() {
return 0;
}

It also works fine if its the last case, but this buggs me, and I want to create other cases with function calls.
Thank you so much!


texts: Can an Arduino (Leonardo) be recognized via Bluetooth as a mouse/keyboard?

texts:
I'm new to wireless communication on Arduinos and doing research for a project. I'm looking at the Arduino Leonardo (which is like the Uno) which via its micro USB port can be automatically recognized as a mouse/keyboard. But also looking at a regular Uno wiFi Rev2.

I want to achieve the same result, but wirelessly via Bluetooth. Because I need to connect it to a device that only recognizes Bluetooth mice/keyboards and nothing else. If I buy something like the HC-05 how would the chip report itself?

How is the Bluetooth stack handled with regards to identification and authentication? Does it somehow copy the USB mouse/keyboard setup?

PS: Can anyone tell me if the Wifi Arduinos (Uno WiFi rev2) also have Bluetooth embedded?


texts: Menus not changing when button is pressed TFT 128 x 128

texts:
I've just followed a tutorial so that when a button is pressed it goes through a menu. Click once, next slide. Only issue is it isn't appearing on my screen at all. It has uploaded but I'm a total novice when it comes to breadboards etc. Here is my code:

    #include "Ucglib.h" // library for this display
#include <TFT.h> // Hardware-specific library
#include <SPI.h>

#define CS   10
#define DC   8
#define RESET  9

#define up 5
#define down 6

TFT TFTscreen = TFT(CS, DC, RESET);
const int menuSize = 4;
String menuItems(menuSize);

bool upLastState = HIGH;
bool downLastState = HIGH;

int currentMenu = 0;
String temp;
char currentPrintOut(10);

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

  pinMode(up, INPUT_PULLUP);
  pinMode(down, INPUT_PULLUP);

  menuItems[0] = ":)";
  menuItems[1] = ":(";
  menuItems[2] = "X(";
  menuItems[3] = ":S";
  menuItems[4] = ":T";

  //initialize the library
  TFTscreen.begin();

  MenuChanged();
}

void loop() {
  if (digitalRead(up) != upLastState) {
    upLastState = !upLastState;
  }

  if (!upLastState) {
    if (currentMenu > 0) {
      currentMenu--;
    } else {
      currentMenu = menuSize - 1;
    }
    MenuChanged();
  } else {
  }

 if (digitalRead(down) !=downLastState) {
  downLastState = !downLastState;

  if (!downLastState) {
    if (currentMenu < menuSize - 1) {
      currentMenu++;
    } else {
      currentMenu = 0;
    }
    //Serial.printIn(menuItems[currentMenu]);
    MenuChanged();
  } else {
    //Release
  }
 }

   delay(50);
 }

 void MenuChanged() {
  Serial.println(menuItems[currentMenu]);

// clear the screen with a black background
  TFTscreen.background(0,0,0);
  TFTscreen.setTextSize(9);
  TFTscreen.stroke(255,255,255);

  temp = String(menuItems[currentMenu]);
  temp.toCharArray(currentPrintOut, 10);

  TFTscreen.text(currentPrintOut, 40, 32);
}

Edited back to original as per request


texts:
I'm running a sketch that looks for inputs to digital pins 3, 4, 5, 6, and 7.  The gist of the sketch is that it's a digitalRead() from 3-7 with a Serial.println() to the monitor. The odd thing is that without any pins connected I'm seeing "0" on some and "1" on others.  I there a reason some will be "0" while other are "1" without anything connected?  I imagine that all pins should read "0" until voltage is detected.

Based on my limited experience I draw the conclusion that a pull-up resistor will likely resolve my problem.  Thoughts?


texts: Two function Reset button - long/short press

texts:
I am trying to make a circuit using an ATmega328, that has a reset button that behaves like many consumer devices:

A short press just restarts the micro-controller
A long press (5 seconds?) causes the settings to be restored to default

What is the best way to achieve this behaviour? I imagine it is going to require two pins? Can it be done just using passive components?

Thanks!


texts: Can I use an Arduino Due as a flash drive?

texts:
More specifically, can I use an Arduino Due to have an interface that can plug in/out of a USB port on a computer, connect it to an SD card or similar via a sd card logging shield, and have it present itself as a flash drive to the computer?

Why do I want this as opposed to a normal flash drive? I would like the Arduino to also have access to the contents of the sd card when the computer interface is not plugged in (or rather controllable via the Arduino which device has access to the card, the Arduino or the computer), without the need to remove/disconnect the cable


texts: How do I turn off a 12V 3A RGB LED strip?

texts:
I'm trying to understand how to control an RGB LED strip, I set up all the TIP120 (because I could get my hands on an n-channel mosfet), if I power everything in this way I can change colours and everything:

but now I'm facing a dilemma now, whats the correct way to manage to switch my power strip ON/OFF based on an input from a pir sensor? I mean, how can I handle 12V 3A (requested by my led strip), how do I correctly wire my Arduino up in order to make it switch the LED strip ON/OFF?


texts:
I wanted to buy an Arduino (ATmega) 2560 (8 Bit MCU) via Amazon. But there was no Arduino visible. There was only a

SainSmart 2560 and

SunFounder 2560

On both websides (SainSmart and SunFounder) there is the information that they are Arduino compatible. But all three boards (Atmel-orginal, SainSmart, SunFounder) do not look similar... There are differences. Is it possible to buy one of those boards without:

checking the datasheet differences
having problems with the Arduino Ethernet Shield !?

So, what is compatible ?


texts: Digital read on voltages between 1 and 31 volts?

texts:
Hello Arduino comunity!

I am working on a circuit that uses an Arduino Mini to read values from certain points of a boost/buck converter circuit to determine things like input state, output state, overheat and so on. The circuit is working all right, and the only part left to do is to connect the digital pins of the Arduino to the different points in the boost/buck regulator.

The problem is however that I need to read from a range of voltages between 1 and 31 volts with the Arduino, which isn't possible, because not only will it damage the controller if the voltage exceeds 5V, but values below 3V will be regarded as false.

I thought of putting some potential dividers, which would obviously not do the trick, and I also thought of using a WS78L05 voltage regulator per input pin (because each pin might have a different voltage from the rest) but that isn't dealing with voltages <=5V and 31V exceeds its rating as well.

Lastly I thought of using transistors, which seemed like a good idea, but I would require 2 transistors per input wired as follows:

simulate this circuit – Schematic created using CircuitLab

But it is impractical to do for 4 inputs and there is limited space available on the PCB too :(

Is there any IC that encapsulates the circuit above, or is there any other way to achieve what I want to do?

Thanks very much :)


texts: EPS8266 ESP-01: LED manipulation seems to interfere with serial communication

texts:
I'm playing around with this udp-example. Both this and the blink-example work perfectly. Now I would like to use the LED to indicate what the ESP is currently doing, as well as reading some data over Serial. My code looks like this:

void setup(){
  Serial.begin(115200);
  Serial.setTimeout(500);
  while(Serial.available()==0){
  }
  String password = Serial.readStringUntil('.');
  Serial.println(password);
  WiFi.begin(ssid.c_str(), password.c_str());
  //pinMode(LED_BUILTIN, OUTPUT);
  while (WiFi.status() != WL_CONNECTED){
    //digitalWrite(LED_BUILTIN, LOW);
    delay(250);
    //digitalWrite(LED_BUILTIN, HIGH);
    delay (250);
  }
  Serial.println("connected");
  Udp.begin(localUdpPort);
}

It works fine, but if I uncomment the led-lines the serial communication doesn't seem to work anymore. All the stuff that is printed on the Serial Monitor is now messed up (missing characters, ...). Is there a problem with my code or what else could be possible going wrong here?

EDIT: I recently tried the same code again, but used an additional power supply (3.3V, 500mA) for the chip. However, this didn't resolve the problem.


texts:
We have developed a custom board with the RFID Scanner and and a Bluetooth Module built into it. The data from the RFID scanner is supped to be read and sent to Bluetooth built into it and then is transmitted to the Phone's Bluetooth which is running an App (Which in turn goes to the cloud and fetches the data to validate the Identity). The communication such as reading the data
sending it to the App is all working fine.

But the issue is if the Bluetooth on the Custom board is disconnected from the Phone's Bluetooth the RFID scanner seems to be scanning the data in lesser time. But the moment it is connected to the Phone's Bluetooth App there is a delay a of at least 6-7 seconds before it lets go the RFID scanner to get ready to scan another Access card. The moment you disconnect the Bluetooth on the board from the Phone the RFID Hardware seems normal scanning the Data (the access card is read continuously). I have three questions.

Is it the common behavior of Bluetooth to act like this?
IS it an issue with the Software App or API?
Is it wise to new implement a Store on forward App just for letting the data read between the Phone's Bluetooth and Bluetooth Module on the custom board then read that data from the Old App??

Please help me as it is for a school project.

Regards,
Ash


texts: How to program an empty Mega2560 with an Arduino sketch?

texts:
I am writing code on Arduino mega. My current code is working fine. However, I'm not using all the pins.

My question is:

I have the hex file for my code and I can purchase a Mega2560 MCU. Is there any way to upload the hex file to it and how?
What are the circuits I would need to to build?
Eagle files of the Arduino mega are available here. Is this circuit more than enough?


texts: Arduino Simple Task - sweeping a buzzer and led, not working as expected

texts:
Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega).

UPDATE: IT seems that there is a problem using pin 11 and 13 together but if I use a different pwm pin like pin 5. It's okay. I'm guessing that the timers used at pin 11 is connected to tone() but not sure...
I’ve encountered a weird problem with an Arduino with this simple task. It involves just a buzzer and LED and a very simple custom library that I made.
I wanted the buzzer to sweep back and forth with a specified frequency range (f1, f2), the led will also display a specific brightness (0, 50) based on the frequency being played.
The buzzer works perfectly on its own, and also the LED, but when you put them together, it malfunctions.
A more detailed explanation can be found here: https://tilarduino.wordpress.com/2015/11/27/weird-arduino-problem-buzzer-led-brightness/
And i've included all the files i've used here: https://gist.github.com/mithi/09ae419a3c7eba285221
Using this code below, commenting out line 19 with line 18 uncommented-out will make the buzzer work, and commenting out line 19 with line 18 back in will make the led work as expected. But together, the code malfunctions. buzzer is attached to pin 13 and led is attached to pin 11.
#include "SimplestLibrary.h"

Sweeper sweeper;
Buzzer buzzer;
AnalogLED led;

int f1 = 3000;
int f2 = 4500;
int f = 0;

void setup() {
    sweeper.New(f1, f2, BACKANDFORTH);
    buzzer.New(13);
    led.New(11);
}

void loop() {
    f = sweeper.Update(1);
    buzzer.Play(f, 4, 2);
    led.NewBrightness(map(f, f1, f2, 0, 50));
    delay(1);
}


texts: Serial communication from Arduino to ESP8266 NodeMCU works, but from NodeMCU to Arduino isn't working

texts:
My circuit connection is like: (I am following this tutorial)

Code uploaded to Arduino:

#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(5,6);

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

void loop() {
  StaticJsonBuffer<1000> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["data1"] = 100;
  root["data2"] = 200;
  if(s.available()>0){
    root.printTo(s);
  }
}

Code uploaded to NodeMCU:

#include <SoftwareSerial.h>
int D5 = 14, D6 = 12;
SoftwareSerial s(D6,D5);
#include <ArduinoJson.h>

void setup() {
  // Initialize Serial port
  Serial.begin(9600);
  s.begin(9600);
  while (!Serial) continue;
}

void loop() {
 StaticJsonBuffer<1000> jsonBuffer;
 JsonObject& root = jsonBuffer.parseObject(s);
 if (root == JsonObject::invalid())
   return;

 Serial.println("JSON received and parsed");
 root.prettyPrintTo(Serial);
 Serial.print("Data 1 ");
 Serial.println("");
 int data1=root["data1"];
 Serial.print(data1);
 Serial.print("   Data 2 ");
 int data2=root["data2"];
 Serial.print(data2);
 Serial.println("");
 Serial.println("---------------------xxxxx--------------------");
}

Arduino sends JSON data and NodeMCU parses it as expected.

--------Till this everything is fine. ---------

But my requirement is vice versa. When I create JSON object in nodeMcu and try to parse in arduino, JSON not received.

This time I wrote this code in nodeMcu:

#include <SoftwareSerial.h>
#include <ArduinoJson.h>

int D5 = 14, D6 = 12;
SoftwareSerial s(D6,D5);

void setup() {
  Serial.begin(9600);
  s.begin(9600);
  while (!Serial) continue;
}

void loop() {
 StaticJsonBuffer<1000> jsonBuffer;
 JsonObject& root = jsonBuffer.createObject();
 root["data1"] = 100;
 root["data2"] = 200;
 if(s.available()>0){
   root.printTo(s);
 }
}

And code in Arduino:

#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(5,6);

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

void loop() {
  StaticJsonBuffer<1000> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(s);
  if (root == JsonObject::invalid())
    return;

  Serial.println("JSON received and parsed");
  Serial.print("Data 1 : ");
  int data1=root["data1"];
  Serial.println(data1);
  Serial.print("Data 2 : ");
  int data2=root["data2"];
  Serial.println(data2);
  Serial.println("---------------------xxxxx--------------------");
 }

This code doesn't work. I don't receive anything in serial monitor of arduino.
The circuit connection remains the same as before.

Anymore information should I provide ? What modification do I need?


texts:
I am working on a small robot project, the code which i made for this has a sequential execution in a single thread. There are a lot of Delay() function needed. Due to which the accuracy is extremely bad.
i want to to implement the movements in one thread and the sensor detection in another thread.

#define M1 3
#define M2 5
#define M3 6
#define M4 9
#define L_trig 2
#define L_echo 4
#define R_trig 7
#define R_echo 8
#define servo 10
#define solenoid_pin 11
#define LDR_pin1 12
#define LDR_pin2 13
void setup()
{
// Motors Initilization
pinMode(M1,OUTPUT);
pinMode(M2,OUTPUT);
pinMode(M3,OUTPUT);
pinMode(M4,OUTPUT);
// Ultrasonic  Initilization
pinMode(L_trig, OUTPUT);
pinMode(L_echo, INPUT);
pinMode(R_trig, OUTPUT);
pinMode(R_echo, INPUT);
S.attach(servo);
}

void loop()
{

 Runmotor(M1);
 Runmotor(M2);
 Runmotor(M3);
 Runmotor(M4);
 servo_rotation();
 Ultrasonic_value(L_trig,L_echo);
 Ultrasonic_value(R_trig,R_echo);

 if(Ultrasonic_value(L_trig,L_echo)<5 || Ultrasonic_value(R_trig,R_echo)<5)

   {
     turnLeft();
     //Serial.println("Working");
   }

}

// Run Motor
void Runmotor(int which)
{
  for(int i=0;i<1023;i++)
  {
 analogWrite(which, i);
  }
}
// Stop Motor
void stopmotor(int which)
{
  digitalWrite(which,LOW);
}
// To turn the robot left side
void turnLeft()
{
  stopmotor(M2);
  stopmotor(M3);
  delay(5000);
  Runmotor(M2);
  Runmotor(M3);
}
// To turn the robot Rightside
void turnRight()
{
  stopmotor(M1);
  stopmotor(M4);
  delay(5000);
  Runmotor(M1);
  Runmotor(M4);
}
// Servo Rotation
void servo_rotation()
{
 for(angle=0;angle<=180;angle++)
{
 S.write(angle);
 if(angle==90)
 {
   delay(2000);
 }
}
delay(2000);
for(angle=180;angle>=0;angle--)
{
  S.write(angle);
  Serial.println(angle);
  if(angle==90)
 {
   delay(2000);
 }
}
 delay(2000);
}

// Calculation of distance
long Ultrasonic_value(int which_trig,int which_echo)
{
  long duration, distance;
  digitalWrite(which_trig, LOW);
  delayMicroseconds(2);
  digitalWrite(which_trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(which_trig, LOW);
  duration = pulseIn(which_echo, HIGH);
  // distance = duration*343*100/2;
  distance = (duration/2) / 29.1;
  delay(100);
  return distance;
}

void Solenoid_Fire()
{
  digitalWrite(solenoid_pin,LOW);
}

void Solenoid_Reload()
{
  digitalWrite(solenoid_pin,HIGH);
}
/*
bool LDR_reading(int LDR_pin1 , int LDR_pin2)
{

}
*/

Please help me. I want to implement this code in a Multi-thread fashion. Thanks in Advance


texts: Is it safe to feed 5v dc 1amp to an Arduino uno R3 board?

texts: Is it safe to feed 5v dc 1amp to an Arduino uno board?


texts: Where can I find a better pinout diagram for "Arduino Ethernet" board?

texts:
I'm looking for a complete pinout of the Arduino Ethernet R3.
I've found one here which is low quality, and seems not complete (where are the digital I/O pins?).

BTW, it was not a good idea for Arduino to name this board "Arduino Ethernet", as this is pretty useless for searching online :-(


texts: ESP8266 using EEPROM to store a value of 100,000

texts:
I'm using Wemos mini in my project. I wish to store a Boolean value in cell #0, which changes every boot.

Since writing to EEPROM is limited to roughly 100,000 cycles - I want to store in cell #1 the amount of writing cycles done so far, so when reaching 100,000 , value will be stored in cell#2 and writing cycles will be stored in cell#3 and so on.

Reading and writing using #include <EEPROM.h> is done as needed, but since each cell can store a byte, it can only reach 255.

My question is how to store a value of 10^6 (except of convert it to a*2^0 + b*2^1 + c*2^2 + d*2^3....).

Guy

EDIT1

Part or relevant code:

void setup() {
        Serial.begin(9600);
        Serial.println("BEGIN:");
        if (HARD_REBOOT) {
                EEPROM.begin(1024);
        }
        if (HARD_REBOOT) {
                EEPROM.write(0,100000);
                EEPROM.commit();
                delay(50);
                Serial.print("value in flash: ");
                Serial.println(EEPROM.read(0));
        }
}

and its output:

Ȥl⸮⸮BGS[⸮<b8ɗ⸮BEGIN:
22:40:58.732 -> value in flash: 160


texts: Newbie - What is the Difference Between Power Supply's GND and Arduino's GND?

texts:
I am new to electronics and Arduino.

What is the difference between power supply ground and Arduino's ground. If I connect my LED cathode to power ground, it doesn't work. But if I connect it to Arduino ground, it works. Aren't all ground the same?

Please see picture below.


texts: Reading pressure sensor using Arduino analog

texts:
I'm using a Arduino Uno to read pressure and I want to know if I have wired/coded the sensor correctly. I'm not sure I'm getting the correct readings (it could be the right readings - I just want to check I have done everything right). The sensor I am using is an OsiSense™ XMLP pressure sensor that reads between 0 and 100 bars and gives out a 0v (zero bars) to 10v (100 bars) charge. Due to the Arduino Uno only being capable of reading up to 5 volts, I've used a voltage divider to reduce the maximum voltage the Arduino receives to 5v.

I've attached a hand-written diagram. Let me know if you need any more information. I've attached the wiring and also the code.

/*
  ReadAnalogVoltage from a OsiSense XMLP presure sensor

  Reads an analog input on pin 0, converts it to voltage and then bar pressure, and prints the result to the Serial Monitor and also MQTT.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).

  Todo
  Static ip. set it to request IP from network
  Work out best way to average readings

*/

#include <SPI.h>  //Serial Peripheral Interface (SPI)
#include <Ethernet.h>  //  These libraries are designed to work with the Arduino Ethernet Shield (Ethernet.h)
#include <PubSubClient.h>  // This library provides a client for doing simple publish/subscribe messaging with a server that supports MQTT

// sets the MAC address and IP address for the network
byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192,34,98,221);  // IP Address of the client
IPAddress server(192,34,98,201); // The IP address of the MQTT server

void callback(char* topic, byte* payload, unsigned int length) {
  // handle message arrived
}

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

void setup() {
  Serial.println("Begin setup");
  Ethernet.begin(mac, ip);
  // Note - the default maximum packet size is 128 bytes. If the
  // combined length of clientId, username and password exceed this,
  // you will need to increase the value of MQTT_MAX_PACKET_SIZE in
  // PubSubClient.h

  // connects to MQTT and says hello world.  Probably change this later on to something more appropriate
  if (client.connect("ArdRigTest")) {
    client.publish("outTopic","Ard Rig Test");
    client.subscribe("inTopic");
  }
  // start serial port
  Serial.begin(9600);
}

void loop() {
  // Note - the default maximum packet size is 128 bytes. If the
  // combined length of clientId, username and password exceed this,
  // you will need to increase the value of MQTT_MAX_PACKET_SIZE in
  // PubSubClient.h

  // read the input on analog pin 0:
  int sensorValue1 = analogRead(A0);
  delay(2); // read twice with small delay to get accurate reading.
  int sensorValue2 = analogRead(A0);

  Serial.println(sensorValue2);
  //Test code. using map function
  int MapBarPressure;
  MapBarPressure = map(sensorValue2, 0, 1023, 0, 100);
  if (client.connect("ArdRigTest" )) {
    client.publish("MapBarPressure",String(MapBarPressure).c_str());  //logs the pressure of the RigTest
    client.subscribe("MapBarPressure");
  }
  delay(100); // Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.)
  client.loop();
}

Thanks in advance.


texts: How to call class A's method from class B?

texts:
I wish to access methods and fields, as well as change them, of class A from class B. Since the main Arduino sketch is not a class, but a list of fields and methods, I created a separate MainClass with a method printStuff() that I want to call from class DoClass. This is how I go about it:

The main sketch:

#include "MainClass.h"
MainClass m;
void setup() {
  m.setup();
}
void loop() {
  m.loop();
}

MainClass.h:

/*
  MainClass.h
*/
#ifndef MainClass_h
#define MainClass_h
#include "Arduino.h"
class MainClass
{
  public:
    MainClass();
    void setup();
    void loop();
    void printStuff();
};
#endif

MainClass.cpp:

/*
  MainClass.cpp
*/

#include "Arduino.h"
#include "MainClass.h"
#include "DoClass.h"
MainClass::MainClass()
{
  d DoClass(this);
}
void MainClass::setup(){
  Serial.begin(9600);
}
void MainClass::loop(){
  d.callMainClassFunct();
}
void MainClass::printStuff(){
  Serial.println("printing stuff");
}

DoClass.h:

/*
  DoClass.h
*/
#ifndef DoClass_h
#define DoClass_h

#include "Arduino.h"
#include "MainClass.h"
class DoClass
{
  public:
    DoClass(MainClass m);
    void callMainClassFunct();
  private:
    MainClass _m;
};
#endif

DoClass.cpp:

/*
  DoClass.cpp
*/

#include "Arduino.h"
#include "MainClass.h"
#include "DoClass.h"

DoClass::DoClass(MainClass m)
{
  _m = m;
}

void DoClass::callMainClassFunct(){
  _m.printStuff();
}

This produces a myriad of errors. Each time I change something, a new kind of error appears, as though I was in a vicious cycle. Clearly, I am unfamiliar with C++. It would greatly help me if you could alter my code so that it works, keeping in mind that I would like to both access methods and fields of class MainClass from class DoClass and change those fields from class DoClass.

For reference, in Java, I would achieve the same in the following way:

MainClass.java:

public class MainClass{
    DoClass d;

    public MainClass(){
        d = new DoClass(this);
}

    public void setup(){

}

public void loop(){
    d.callMainClassFunct();
}

public void printStuff(){
    Serial.println("print stuff");
}

}

DoClass.java:

public class DoClass{
       MainClass _m;
       public DoClass(MainClass m){
          _m = m;
       }
       public callMainClassFunct(){
         _m.printStuff();
}

}

Passing this to the constructor od DoClass passes the value of the reference pointing to MainClass instantitated in the main sketch file. Then, by prepending the name of the instantiated object (in this case, "m"), followed by a dot, I can simply access and change all values of that object from DoClass (provided those methods and fields are visible to DoClass, which is the case here).

I have posted before about this issue, but did not receive any answers to my specific question and could not comment because I do not have enough reputation. Thank you to those who tried to answer me, but the answers did not pertain to my specific question. This time I have included more information to show my problem more clearly. Thank you in advance for your help.


texts:
I am doing an experiment. In this experiment I want to start the RTC by presing the external Push Button which is connected with Aquino's pin 2 and take varites of action according to Time. For interrupt I have made a ISR and in this interrupt I wrote my main logic. But this things is not working.
The schematics is

and The code is

`include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>

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

RTC_DS1307 rtc;
int k = 0;
int led =13;
int pin =2;

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

void setup () {
 lcd.begin(16, 2);
 rtc.begin();
 Serial.begin(11520);
 pinMode(led,OUTPUT);
 pinMode(pin,INPUT);
 attachInterrupt(0, Time  , LOW);
  // Print a message to the LCD.
  if (! rtc.begin()) {
    lcd.print("hello, world!");
    while (1);
}

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
}
void loop()
{}

void Time()
   {
    {DateTime now = rtc.now();
    lcd.setCursor(0, 0);
    lcd.print(now.year(), DEC);
    lcd.print("/");
    lcd.print(now.month(), DEC);
    lcd.print("/");
    lcd.print(now.day(), DEC);
    lcd.print(" ");
    lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
    int c = now.second();
    lcd.setCursor(0, 1);
    lcd.print(c);
    if(c==58)
      {
        k=k+1;
        lcd.setCursor(5, 1);
        lcd.print(k);
        if(k==4)
          {
            digitalWrite(led,HIGH);
            k=0;
          }
     }

    }}`

please help me.


texts: Arduino code won't upload with Ethernet Shield attached

texts:
I've been playing with my Arduino Boards for a while. I have an Arduino Nano and a Duemilanove 328.

I've been able to program both of them without problems for weeks. Any example project I try will compile and upload with no issue.

I recently got an Ethernet shield... I'm trying some test sketches and no matter which board I try, with the shield attached I get:

avrdude: stk500_getsync(): not in sync: resp=0x00

As I said, without the Ethernet shield attached all is bliss....

Do I have a bad shield or am I just doing something stupid?


texts:
I'm in the process of trying to create a "Aurora Glow" effect using a Particle Photon and a Neopixel ring.

I have the code fully working using a single Breadboard-friendly NeoPixel however when upgrading this to a NeoPixel Ring (16 LED) the code does not run as expected

The current working code for a single NeoPixel can be found here: http://pastebin.com/Yj1cywpx

It was my assumption that i could change Line 33 from one LED to Sixteen e.g.:

FastLED.addLeds<NEOPIXEL, 6>(&led, 1);

to

FastLED.addLeds<NEOPIXEL, 6>(&led, 16);

However when I run this code rather than all NeoPixels cycling through the Aurora Colours, only the very Top LED does and rest are either off or a static colour (e.g. http://imgur.com/a/MvKZQ)

Could someone please advise what i missing? Apologies if this is a "Noob" question but this is my 2nd Arduino project and I cannot understand why this would not work.

Thanks


texts: Use SD-Card module in combination with MKR GSM 1400

texts:
I have bought a SD Module with the following Pin-Names: VCC,GND,MOSO,MOSI,CS,SCK. I've found many tutorials on how to use it with the Arduino Uno. But haven't found any on how to wire it with the MKR GSM 1400. Most of these Pin Names are written on the Board itself, but the CS-port isn't marked. (VCC and GND are obvious). So is there any tutorial on how to use them together or any more specific documentation?

Here is a Picture of the SD-Adapter I am using :


texts: Can you program an ESP32 with an Arduino?

texts:
I've done it with an ESP-8266 but can't find any articles on how to do it with an ESP-32. I'm working with an ESP-32 on my own PCB, not a dev board. I exposed:

3V3
GND
EN
TX
RX
IO0

I'm pretty sure I can use a standalone programmer but I was expecting to be able to do it with an Arduino. Is that possible? ...if it's super difficult to do like setting up a toolchain and all that I'd rather just spend $10 and get a programmer.


texts:
I am trying to run a strip of APA102 addressable LED's using a Mini pro.

The same strip I can run using a raspberry pi using SPI so I know the Strip works and what data I need to send to get it running.

My current code is as follows and I have striped it back to the bare minimum as I see it.

It all compiles and runs but nothing on the LED strip. The stip only has data and clock that should be connected to the CLK and Data in to connect to the MOSI.

All i want is to be able to send a 32bit value,

I had also tried

uint32_t value = 0xE0ffffff

but again no luck

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  SPI.begin();

  byte start = 0x00;
  SPI.transfer(start);
  SPI.transfer(start);
  SPI.transfer(start);
  SPI.transfer(start);

  SPI.transfer(0xEF);
  SPI.transfer(255);
  SPI.transfer(0);
  SPI.transfer(10);
}


texts:
I want to control two hitec hs55 micro servos via a Nodemcu v3. These need at least 4.8 V power supply acc to data sheet.
Specs:
Hs-55 micro servo:
Voltage range: 4.8-6 V
Current Drain - no-load (4.8V): 150 mA
Pulse Amplitude: 3-5V
NodeMCU (v3):
From what I found it seems like it can "reliably supply 600 mA".
3.3V pins (standard)
5 V (pin VU), Directly connected from the USB (?)
From what I understand it is generally a good idea to supply power to servos separately, otherwise the board can be damaged. Is this also the case here or would it be OK to connect the supplies to the servos from the VU pin? I'm thinking that there is a possibility it could be ok since it is directly connected to the USB.
For the signals I will use the normal GPIO pins.
Thank you in advance :-)


texts: Ethernet module ENC28C60 doesn't connect to internet when DHCP on router is disabled.

texts:
Update: Examples from library are working if DHCP is enabled!

Using this library I try to connect with static IP but it always say DNS failed. Ethernet module is blinking that means is good connection also static ip is correct..

Question: What is hisip and how can this module connect to internet with static IP`?

Connections :

VCC -   3.3V
GND -    GND
SCK - Pin 52
SO  - Pin 50
SI  - Pin 51
CS  - Pin 53 # Selectable with the ether.begin() function

Code:

// This demo does web requests via DNS lookup, using a fixed gateway.
// 2010-11-27 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

#define REQUEST_RATE 5000 // milliseconds

// ethernet interface mac address
static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
// ethernet interface ip address
static byte myip[] = { XXX, XXX, 216, 199 };
static byte gwip[] = { XXX, XXX, 216, 126 };
static byte dnsip[] = { 8, 8, 8, 8 };
// remote website name
const char website[] PROGMEM = "google.com";

byte Ethernet::buffer[300];   // a very small tcp/ip buffer is enough here
static long timer;

// called when the client request is complete
static void my_result_cb (byte status, word off, word len) {
  Serial.print("<<< reply ");
  Serial.print(millis() - timer);
  Serial.println(" ms");
  Serial.println((const char*) Ethernet::buffer + off);
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[getViaDNS]");

  if (ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
    Serial.println( "Failed to access Ethernet controller");

  ether.staticSetup(myip, gwip);

  if (!ether.dnsLookup(website))
  Serial.println("DNS failed");
  ether.printIp("Hisip: ", ether.hisip);
  ether.printIp("Myip: ", ether.myip);
  ether.printIp("Gateway: ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  timer = - REQUEST_RATE; // start timing out right away
}

void loop () {
  ether.packetLoop(ether.packetReceive());

  if (millis() > timer + REQUEST_RATE) {
    timer = millis();
    Serial.println("\n>>> REQ");
    ether.browseUrl(PSTR("/foo/"), "bar", website, my_result_cb);
  }
}

Output:

[getViaDNS]
DNS failed
Hisip: 0.0.0.0
Myip: XXX.XXX.XXX.199
Gateway: XXX.XXX.216.126
DNS: 8.8.8.8

>>> REQ

>>> REQ
...


texts: Dallas Temperature Sensor DS18B20 not showing correct Result with Ethernet Shield

texts:
I am using Arduino Uno R3 board and a wiznet W5100 ethernet Shield. The temperature from the One wire sensors before using Ethernet Shield was showing correct. However later after connecting the shield, the temperature is showing to be 85. The server and everything else works fine, but the data is all wrong. Now I am pretty sure the connections are correct and it is not in parasite mode. Any suggestions of how I might get the accurate reading ?

/*
  Web Server

  A simple web server that shows the value of the analog input pins.
  using an Arduino Wiznet Ethernet shield.

*/

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

#define ONE_WIRE_BUS 2

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
            0xF0, 0xBF, 0x97, 0x67, 0xF6, 0x98
        };
IPAddress ip(192, 168, XXX, XXX);

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
EthernetServer server(80);

void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    sensors.begin();
    while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
    }
    // start the Ethernet connection and the server:
    Ethernet.begin(mac, ip);
    server.begin();
    Serial.println(sensors.getTempCByIndex(0));
    Serial.print("Siddhartha Temperature ");
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
}

void loop() {
    // listen for incoming clients
    EthernetClient client = server.available();
    if (client) {
        Serial.println("new client");
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                Serial.write(c);
                // 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");
                    client.println("Refresh: 2");
                    client.println();
                    client.println("<!DOCTYPE HTML>");
                    client.println("");
                    // output the value of each analog input pin
                    for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
                        float sensorReading = sensors.getTempCByIndex(0);
                        client.print("Temperature ");
                        client.print(analogChannel);
                        client.print(" is ");
                        client.print(sensorReading);
                        Serial.println(sensorReading);
                        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();
        Serial.println("client disconnected");
    }
}


texts:
I am working on a project in making a timer socket using Arduino and a current sensor. For the code I decided to modify a code that was meant to be a kitchen timer.

In that code I found a statement

currentMode = currentMode == MODE_IDLE ? MODE_RUNNING : MODE_IDLE;

I assumed this works in a way that it chose whether the timer is in the current mode or the idle mode but I don’t understand the mechanism behind it.
What does this statement mean?


texts: Setting a number inside a struct causes timer to misbehave

texts:
The following code:

struct l{
    uint8_t pin;
    uint8_t sensePin;
    float brightnessTarget;
    uint8_t PWMvalue;
    uint8_t inc;
};
typedef struct l led;

led* redLed;
led* whiteLed;
unsigned long secondsOfDay = 79140;
unsigned long minutesOfDay = 0;
unsigned int hoursOfDay = 0;
uint8_t interrupted=0;
uint8_t runPID;
int pin13=0;

void setup() {
  cli();
  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 1hz increments
  OCR1A = OCR1A_val;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10);
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);
  pinMode(13,OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  sei();
}

void loop() {
  if (runPID){
    PIControl(redLed);
    PIControl(whiteLed);
    pin13 = (~pin13 & 1);
    digitalWrite(13, pin13);
    runPID=0;
  }
}

SIGNAL(TIMER1_COMPA_vect){ //1 second timer fire
  runPID = 1;
}

Toggles a pin. However, if I add:

redLed->pin = 3;
whiteLed->pin = 4;
redLed->sensePin = 0;
whiteLed->sensePin = 1;

In the setup anywhere (before cli(), after sei(), or within the block), the interrupt no longer toggles.

I'm absolutely baffled, and I have no idea what's going on.

Edit: everything but whiteLed->sensePin is fine. That line is what is causing the issue (and I still don't understand)


texts: Removing CH340g chip from Arduino Nano clone.. any issues?

texts: In trying to figure out how to solve another problem with Arduino Nano clone using CH340 chip, I was just now wondering, would there be any issues if I were to simply remove the CH340 chip? As it stands, I have the slight suspicion that the chip itself might be causing some problems with communicating using only the Tx Rx pins, could this be the case? More importantly, can I just remove the chip with no issues (other than the already lacking ability to use it as USB-Serial bridge)? In a working board, would removing the chip cause any other problems?


texts: How many PIR Motion Sensors can I connect to my Arduino-Uno R3?

texts: I am doing a school project where I intend to measure the cafeteria line with motion sensors and the send that information with a WiFi module to a server. This is my first time using Arduino and I am not sure how many motion sensors does it support.


texts: Is it possible use Arduino nano with wemos sd shield? If I can, how to I connect sd shield to arduino and what modification I need to do on library setting?


texts:
I am an mid experienced Programmer but I have no clue about electronic circuits. I want my Arduino to do sth if he gets a signal from an external source. The external source has 5V and is 0V or 5V and when it has 5V I want my Arduino to send me a Message, the Code for the Message is no problem, but please help me with the circuit:
The external source is independent and runs on battery and the device has a 2.5mm jack, normally there is an LED attached that lights up, but I want my Arduino to receive the signal. Are there any opportunities for realising this?
Thank you for your help


texts: I am fairly new to Arduino. As far I know all official Arduinos run on 5 volts. Or there is Arduino versions that run from 3.3V? I need use Arduino with devices which chipsets all use 3.3V logic level. Do I need modify Arduino to make it  3.3V powered, like described in this Tips, or there is another way? I plan get Arduino UNO R3 ATmega328P board (comes with bootloader for Arduino UNO ZT).


texts: How can you speed up the ADC on an ATtiny85?

texts:
I'm reading input from a camera and trying to reach a fast frame rate. Problem is my ATtiny85 has a pretty slow conversion time (65 - 260 µs Conversion Time). Is there any way to make this faster? I heard that you can set-up a prescaler for the analogRead() method by doing the following:

#define FASTADC 1

// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

void setup()
{
  #if FASTADC
   // set prescale to 16
   sbi(ADCSRA,ADPS2) ;
   cbi(ADCSRA,ADPS1) ;
   cbi(ADCSRA,ADPS0) ;
  #endif

  /*Rest of the code goes here.*/
}

I can't really make sense of the code and I found it on a less then reliable website so I was wondering if any of the gurus on here could let me know if what I'm attempting is possible and if this is the proper way of achieving my goal.

Also, would this also work for the Arduino Mega? I'm currently using it to test and debug my project since the ATtiny84 doesn't have serial output.

Datasheet: http://www.atmel.com/Images/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf


texts:
Trying to hook up an hazzah feather to a pca9685 scl sda connection and have a bno055 connected to that.The 5 volts to power the PCA is not taken from feather. I have a GPS module connected to pin 12 of feather again not powered from feather. Gps interface works fine. I see it though web page interface.
Then I hook up the PCA. the wifi chip overheats and feather is fried


texts: I’m working at a project which involves 3 stepper motors that are driven by A4988 drivers. I have read that I have to connect an 100uf capacitor in parallel with the motor power supply that goes to the driver, but do I have to use a capacitor for every driver, or only 1 capacitor because the drivers are connected in parallel to the same 12v power supply.


texts: Is it possible to create an interface between Teensy 3.2 and a DSP?

texts:
I realize that this is a forum for Arduino but since the Teensy 3.2 is compatible with the Arduino IDE I thought it would be appropriate to ask the question here.

Anyway, can I create an interface between the Teensy 3.2 and a DSP, more specifically the TMS320C5534-Fixed-Point Digital Signal Processor and how could I go about it?

What I am trying to do do is capture an EEG and EoG (electrooculogram) signal, amplify it, filter the signal, use the DSP for ADC and signal processing and finally get this information from the DSP to the Teensy 3.2, which will then make a decision based on the signal obtained from the DSP.

Maybe this is a simple question but I couldn't find any answers online. I am pretty new to the world of microcontrollers.

Thank you guys!


texts: Why is Toolchain Not Updated with Arduino IDE Install on Mac

texts:
I have not been doing any Arduino work for about a year.  The last time I ran the Arduino IDE was in the previous version of MacOS.  Now that I have updated to the latest MacOS Version Catalina (10.15.2) I discovered that the IDE will not compile because the avr-g++ compiler is 32 bit and will not execute on the now 64-bit required MacOS.

So I did the obvious thing.  I went to the arduino.cc web site and downloaded the latest version of Arduino IDE thinking that this should solve the problem.  I updated to version 1.8.11 of the IDE but the 32-bit problem persisted.

I finally decided that the IDE was updating (new Arduino IDE app) but that the avr toolchain was not being updated.  To force this update, I deleted the entire avr toolchain from my ~/Library folder.  Now, re-running the IDE is all it took:  It discovered the toolchain missing and re-installed and installed with the correct 64 bit binaries (which were part of the new Arduino App all the time).

Perplexing -- why was the toolchain not updated with the install?  Is it a requirement to delete the existing toolchain before doing a new install of the Arduino App?


texts: I2C communication between Attiny85 as master and arduino UNO as slave

texts:
I want to make my Attiny85 and my Arduino UNO communicate together with I2C protocol. Since Attiny do not support Wire library, I use TinyWire by lucullusTheOnly and Wire on the Uno.

The Attiny is sending data as the master to the Uno, the slave.

Here is my code:

Master

#include <TinyWire.h>

byte slave_address = 10;

void setup() {
    // config TinyWire library for I2C master functionality
    TinyWire.begin();
}

void loop() {
    TinyWire.beginTransmission(slave_address);
    TinyWire.send('c');
    // endTransmission sends the bytes in the buffer to the slave and returns 0 if there was no error
    TinyWire.endTransmission();
    delay(500);
}

Slave

#include <Wire.h>

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

void loop() {
  delay(100);
}

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

I connect the pin like this :

Arduino --> Attiny
SCL ---- PIN 7
SDA ---- PIN 5

I try to pull-up the clock and data line with 2.2k resistors but nothing happened, I receive nothing on the Uno from the Attiny.
Any idea ? Thanks !


texts: arduino + GSM/GPRS SIM 900A cannot able to read a message

texts:
Here I am using Arduino uno and GSM sim900A, I want to read sms from sim900A. But i am trying to read message, it is showing the empty values. I tried different methods, but no use. Here I have added my script. Please help me.

#include <avr wdt.h="">
String phoneSMS = "+91xxxxxxxxxx";
String messageTxt;
void setup()
{
Serial.begin(9600);
delay(60000);
srl_msg();
}
String srl_msg()
{
Serial.println("AT+CMGF=1\r");
delay(1000);
Serial.println("AT+CNMI=2,2,0,0,0");
delay(1000);
Serial.println("AT+CMGL=\"ALL\"\r"); // to read ALL the SMS in text mode
delay(1000);
char txtmsg2[100]; // AT command output
String date = readSerial(txtmsg2);
String value = date.substring(1, 50);
messageTxt = "Internal - Heart Beat;";
messageTxt.concat(value);
Serial.println(value);
SendSMS(messageTxt);
}
void loop()
{
}
void SendSMS(String message)
{
Serial.print("at+cmgf=1\r");
delay(1000);
Serial.print("at+cmgs=\"");
Serial.print(phoneSMS);
Serial.println("\"");
delay(1000);
Serial.println(message);
delay(1000);
Serial.print((char)26);
delay(15000); // AAN
}
String readSerial(char result[])
{
int i = 0;
while (Serial.available() > 0)
{
char inChar = Serial.read();
if (inChar != '\r')
{
result[i] = inChar;
i++;
}
}
return result;
}

output is look like this:
AT+CMGF=1

OK

AT+CNMI=2,2,0,0,0

OK
AT+CMGL="ALL"

OK


texts: How to create parametric variable in class decleration

texts:
I hope the subject of this question if correct.

in timeOUT constructor, 3 more instances of other class are defined:
endTimeOUT_inFlash(key1),
inCodeTimeOUT_inFlash(key2),
updatedTimeOUT_inFlash(key3).

// ~~~~~~~~~~~ TimeOut Class ~~~~~~~~~~~~
timeOUT::timeOUT(char *sw_num, int def_val,char *key1, char *key2, char *key3)
        : endTimeOUT_inFlash (key1), inCodeTimeOUT_inFlash(key2), updatedTimeOUT_inFlash(key3)

I'm looking for a way that key1 to key3 will be predefined keys, and sw_num will serve as a prefix to those keys.

For example :

#define key1 "endTO"
#define key2 "inCodeTO"
#define key3 "updatedTO"

and using sw_num's value will be concatenate as: SW0_endTO( for key1 and so on . sw_num=SW0 ofcourse).

This way contructor will be :

// ~~~~~~~~~~~ TimeOut Class ~~~~~~~~~~~~
    timeOUT::timeOUT(char *sw_num, int def_val)
            : endTimeOUT_inFlash (key1), inCodeTimeOUT_inFlash(key2), updatedTimeOUT_inFlash(key3)


texts: RFID-RC522 Cannot read from MIFARE Ultralight

texts:
I tried many ways to get and print UID and other data from MIFARE Ultralight but it always ends with error. I am using RFID-RC522 reader with Arduino UNO and MFRC522 Library.
I can normally get and print the PICC type of chip, but that's the only thing that works.
That's how I have connected my RC522 reader:

This is my code:
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9
#define SS_PIN 10

MFRC522 rfid(SS_PIN, RST_PIN);

unsigned long noSignal = 0;

bool lastState = true;
bool read = true;

void setup()
{
    pinMode(2, OUTPUT); //Red led
    pinMode(3, OUTPUT); //Green led

    Serial.begin(9600);
    SPI.begin();
    while (!Serial);

    rfid.PCD_Init();
    Serial.println("RFID ctecka byla uspesne spustena."); //Prints "RFID Reader succesfully started"
    Serial.println();

    changeLed(true);
}

void changeLed(bool red)
{
    digitalWrite(2, red);
    digitalWrite(3, !red);
}

void loop()
{
    if (millis() - noSignal >= 300)
    {
        changeLed(true);
        read = true;
    }

    bool state = !rfid.PICC_IsNewCardPresent() && !rfid.PICC_ReadCardSerial();

    if (state != lastState)
        if (state)
            noSignal = millis();
        else if (read)
        {
            read = false;

            changeLed(false);
            noSignal = millis();

            Serial.println("---------Cip detekovan----------"); //Prints "Chip detected"
            Serial.println();

            MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);

            Serial.print("Znacka cipu: ");//Prints chip type
            Serial.println(rfid.PICC_GetTypeName(piccType));

            rfid.PICC_DumpToSerial(&rfid.uid); //Here is the error

            Serial.println();
            Serial.println("---------Cteni skoncilo----------");//prints "Read ended"
            Serial.println();

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

    lastState = state;
}

Serial monitor snapshot:

Maybe important thing is that when i call PCD_DumpVersionToSerial() i get:
Firmware Version: 0x12 = (unknown)

Somewere I read that my Arduino isn't compatibile with MIFARE Ultralight and I need MIFARE Classic cards. Is that true? Can I solve this problem by using other library or it's hardware problem? Thanks
Btw. Sorry for my english, it's not my native language.
EDIT:
I asked my friend, which have arduino too from same shop like me, if he can read MIFARE Ultralight cards. He said that it's working for him. So my problem will be probably on hardware side. We both have unoficial arduino from aliexpress.


texts: waking up arduino mini with a external signal

texts:
I have an arduino mini with an ultrasonic sensor conected to the pins 2 and 3, and a RGB LED connected to the 4,5, and 6, I want to include a wake up and sleep functionality that wakes up when receive a high signal in another pin as 7.

I have seen that normaly the pins for that are 2 and 3, as in the arduino web: Arduino sleep web

But can it be done with another pin?


texts:
What is the best / simplest way to play audio files from an SD card?

I'm currently working on a sound board, where each button plays a different sound. But I have yet to find the right combination of shields / hardware to do this efficiently.

Is there a shield that supports this directly (SD card -> speaker)? Note that I also need additional pinheads for my buttons to connect to. I think I will be using the Arduino Mega for that purpose.


texts: Suggestions for latest ESP8266 WiFi module

texts:
I am having problems with the ESP8266-01 I bought. It works at only 115200 baud rate and it gives many problems when programming with Arduino Uno. I got it flashed to 9600 baud rate, but still many times it becomes unreliable.

I have seen many videos online that has the ESP8266 that works at 9600 by default.

Could someone please tell me where I can buy the latest ESP8266 that runs at 9600 baud rate by default?


texts: Arduino Mega with two Arduino Unos as slaves via I2C?

texts:
Good morning!  This is my first post here, and my first time diving into the world of microcontrollers.  Bear with me, as I describe this theoretical project.

I've got an Arduino Mega 2560, two Arduino Unos, one accelerometer, two Wii Nunchucks (with Nunchucky adapters) and two 3-axis joysticks.  I'm curious how to go about wiring/programming the two Unos to the Mega as slaves; both with one nunchuck and joystick going to them to control a set of servos/actuators each, for a total two sets of servos/actuators.  The accelerometer will be connected directly to the Mega, and will control a third set of servos/actuators via head-tracking (accelerometer mounted to a headset).

I've been reading all over, and the first thing I need to learn is how to go about establishing I2C between the Mega and two Unos.  I found a few diagrams, but wasn't sure if that way was best for my application.  After the I2C is established, I am interested in learning how to make accelerometers and joystick potentiometers most effectively control servos and actuators.  I'm also interested in how to program buttons to playback pre-programmed servo sequences, but I'm getting way ahead of myself.  If anyone's wondering about this project, it's for a large animatronic suit.  Any advice is welcome, and thanks for reading!

*edit: I made a sketch in Fritzing to give you an idea of what I have in mind.  Don't mind the accelerometer on the left- that'll come later when I get into solenoids.


texts:
I am trying to create something that will allow me to control an individually adressable LED strip using an electric piano using its midi output.

Some things to note:

The piano can output midi either via USB or via standard midi connectors.
I have an Arduino Uno and an Arduino Mega available
I'm using a WS2812B strip with +ve, ground and data cables

I don't believe there's a way to read midi from my piano direct to the arduinos without reflashing the USB controller. For this reason I'm connecting via USB to my mac.  On my mac I've written a program which reads the midi input and can understand it and send it on to somewhere else.

The arduino for the light strip I think I can program pretty easily but I have some questions:

If I need to power the LED strip, should I be powering it from the arduino power or giving it its own power source with common ground?
Is splitting it up into midi -> computer, computer -> arduino, arduino -> LED strip sensible? If not how should I be going about it?
Am I making life difficult by going the USB route for Midi or should I switch to midi connectors and connect direct to the arduino somehow?


texts:
I'm currently working on a project where I need to use PID to get the correct speed for a motor when it is angled a certain amount.

The problem is that I'm only getting 0.00 and 255.00 as the speed. Nothing in between. The code is supposed to activate when the angle value is more than 1300 and less than -1300. The ax variable is from an MPU6050 sensor.

int16_t ax, ay, az;

double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp,Ki,Kd, DIRECT);

void setup() {
  Input = analogRead(ax);
  Setpoint = 100;
  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}

void loop() {
  accelgyro.getAcceleration(&ax, &ay, &az);
  int a=ax+10900;
  //Here I set the used variable to around 0. ax is actually around -10900
  //This is always true, this won't be in the final code. This is just making it work.
  if(1) {
    int val;
    val = map(a, -1300, 1300, 0, 1023);
    Input = val;
    myPID.Compute();
    Serial.println(Output);
  }
}


texts: Relay + Arduino uses too much power for battery to handle. Which solution is best?

texts:
You can see in my crumby schematic that I am using a Non-latching relay to turn on a 3A circuit (one of them arc lighters), which is powered by a 25C (supposedly) lipo battery. That same battery also powers an Arduino through a TP4056. This works fine when I first turn it all on, but once the relay is activated by the Arduino, the lighter + Relay only turn on for a split second before stopping (when the Arduino is powered via USB, it works fine). I am thinking that the Arduino+Relay+Lighter is too much for the battery, even though it claims to be 25C. It is just strange because the Arduino+Activated Relay consume what, like 200 mA?
Notes:
When I manually turn on the lighter, the light on the Arduino dims a fair bit, but stays on.
The Arduino is running at logic level of 3.3V so that I didn't need a booster.

As for fixes, I was thinking about trying to use a transistor or SSR instead of the chunky relay I have now (which would be good, I need this to be compact). Or maybe the TP4056 is failing to provide enough output despite a decent input?
I am FAR from an electrical engineer so if anyone has any pro tips for improving this it would be much appreciated.


texts:
I am trying to connect a distance sensor VL6180x to Arduino Pro Mini via I2C. Yesterday it was working without any problems, but today it refuses to work, even though I haven't changed anything. The sensor has a logic level shifter and pullup resistors onboard. I tested it with Arduino Uno and works perfectly again. However I can't get it to work with Pro Mini again. I am using the Wire library and the VL6180x library. Pins are A4-SDA, A5-SCL, VCC-VIN, GND-GND. Here is the code I am using. It is giving TIMEOUT all the time. I am using an FTDI USB to serial converter to program the Pro Mini.

#include <Wire.h>
#include <VL6180X.h>

VL6180X sensor;

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

  sensor.init();
  sensor.configureDefault();

  // Reduce range max convergence time and ALS integration
  // time to 30 ms and 50 ms, respectively, to allow 10 Hz
  // operation (as suggested by Table 6 ("Interleaved mode
  // limits (10 Hz operation)") in the datasheet).
  sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
  sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);

  sensor.setTimeout(500);

   // stop continuous mode if already active
  sensor.stopContinuous();
  // in case stopContinuous() triggered a single-shot
  // measurement, wait for it to complete
  delay(300);
  // start interleaved continuous mode with period of 100 ms
  sensor.startInterleavedContinuous(100);

}

void loop()
{
  Serial.print("Ambient: ");
  Serial.print(sensor.readAmbientContinuous());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.print("\tRange: ");
  Serial.print(sensor.readRangeContinuous());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
}

This is the code bit I suspect the problem originates form in the VL6180x library:

uint8_t VL6180X::readRangeContinuous()
{
  uint16_t millis_start = millis();
  while ((readReg(RESULT__INTERRUPT_STATUS_GPIO) & 0x04) == 0)
  {
    if (io_timeout > 0 && ((uint16_t)millis() - millis_start) > io_timeout)
    {
      did_timeout = true;
      return 255;
    }
  }

  uint8_t range = readReg(RESULT__RANGE_VAL);
  writeReg(SYSTEM__INTERRUPT_CLEAR, 0x01);

  return range;
}

Here is my serial monitor:

   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
 TIMEOUT
   Range: 255
.....

Any help would be greatly appreciated.


texts: Arduino based fully controlled aquaculture

texts: I am doing a project on aquaculture,so I am using temperature sensor, water level sensor, dissolved oxygen sensor, pH sensor and also 4 motor's and water heater is it possible for a single Arduino to run all these at the same time??


texts: Serial read SSID and PASSWORD WiFI connection failed in ESP32

texts:
Trying to get Wifi SSID and password dynamically from serial monitor and connecting to WiFi, tried the below program, but wifi is always in Connecting state only, it is not getting connected after receiving input from serial monitor.

#include <WiFi.h>

#define BAUDRATE 115200

char ssid[50];
char pass[50];

void setup() {
  Serial.begin(BAUDRATE);
  Serial.println();
  Serial.print("Enter your WiFi credentials.\n");
  Serial.print("SSID: ");
  while (Serial.available() == 0) {
    // wait
  }
  Serial.readBytesUntil(10, ssid, 50);
  Serial.print(ssid);
Serial.print("donessid");

  Serial.print("PASS: ");
  while (Serial.available() == 0) {
    // wait
  }
  Serial.readBytesUntil(10, pass, 50);
  Serial.print(pass);
 Serial.print("donepass");

  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("Connecting....");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
void loop()
{}


texts: Documentation for creating a Board Manager profile for the Arduino IDE

texts: I'd like to write a Board Manager profile for some Arduino boards that I have. So far I've struck out on finding the documentation on the format and contents of the files. Does anybody know where I can find it?


texts: Waking up async the Arduino while it is sleeping periodically

texts:
I´m using LowPower.h and PinChangeInt.h libraries to put my Arduino into the sleep mode every 8 seconds and then it wakes up, modifies a counter and it goes to sleep again, but also I need to wake it up when a button is pressed asynchronously.

I´ve reached to wake up the Arduino every 8 seconds using LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF) and, in other code, I´ve also reached to wake it up while it sleeps indefinitely with LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF) but I can´t combine that periodical awakening with the asynchronous awakening.

Here is my code:

void setup(){

    Serial.begin(9600);

    //Pines declaration

    loopsToSend = setTimeToSend();  //

    //The three async buttons
    PCintPort::attachInterrupt(4, readOpinion,RISING);
    PCintPort::attachInterrupt(5, readOpinion,RISING);
    PCintPort::attachInterrupt(6, readOpinion,RISING);
}

void loop(){

    if(loops < loopsToSend ){

        byte opinionValue = readOpinion(); //This method must awake the Arduino ASYNC to give a value to the opinionValue var, write the result in the file and go to sleep

        if(opinionValue != 0){
            Serial.println("Button pressed!");

            //Writing result in a file
            opiniones++;
            delay(500);
        }
        //Go to sleep 8 seconds
        LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
        opinionValue = 0;
    }
    else {
        wdt_disable();

        if(opiniones > 0){
            //Send file using GSM module
        }
        else{
            loops = 0;
        }
    }
    loops++;
}

Can anyone help me? Thanks


texts:
For a robotics project I am using an MCP23017 I/O Port Expander in order to have more pins available, and I am also using a PS2 controller for input. Both of these require pins 4 and 5 (because these are the data and clock pins). I was wondering if I can use a breadboard to simply connect these two pins to both devices in order to provide both of them with data and clock pins.

I am using an Arduino UNO and a playstation 2 controller with the following guide:
http://www.techmonkeybusiness.com/using-a-playstation-2-controller-with-your-arduino-project.html


texts: What is the difference between declaring a variable outside of loop and declaring static inside loop?

texts:
These are two ways I can hold a variable outside of loop (or any function).

First, I can declare it with global scope outside of loop:

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

int count = 0;

void loop()
{
    Serial.println(count);
    count++;

    delay(250);
}

I can also declare it static inside the loop:

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

void loop()
{
    static int count = 0;

    Serial.println(count);
    count++;

    delay(250);
}

What difference, if any, will this make?


texts: Using Multiple 4 Digit displays with the same pins

texts:
I currently have a ton of 4 Digit 7 Segmented displays(TOFD-5465GGH-B).

The display is driven by a PT6961 LED Driver. Using a Library that I found here I was able to use the display with no issues. The pin out on the display is as such:

1) 5V
2) CS
3) CLK
4) DIN
5) DOUT
6) Common

Since the display has a DOUT does this mean I can run multiple display is series off of the same pins? If so, can someone point me in the right direction to do so. I am currently using a Particle Photon and I am limited as to the number of PWM pins.


texts: Using C# Program to Interpret Keystrokes

texts: I am in the process of developing an Arduino application that can read keystrokes from a PS/2 keyboard. I was wondering if it would be possible to upload a C# program onto the Arduino to interpret the keystrokes from the keyboard and write an Arduino program to perform operations based on the keystrokes.


texts: How to send AT command to sim800l with SoftwareSerial

texts:
I have SIM800l module connected to Arduino and I'm trying to initialize it in my setup function with this code:

#include <SoftwareSerial.h>

//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 6
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

void setup()
{
  Serial.begin(38400);
  while(!Serial);
  serialSIM800.begin(38400);
  Serial.println("wait for .... it");
  delay(10000);

  // comments added just for example, both commands return junk
  //serialSIM800.write("AT\r\n");
  //serialSIM800.write("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r\n");

  Serial.println("command sent");
  delay(2500);

  Serial.write(serialSIM800.read());
}

But Serial.write returns junk.

When I use this code in loop:

  //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
  if(serialSIM800.available()){
    Serial.write(serialSIM800.read());
  }
  //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
  if(Serial.available()){
    serialSIM800.write(Serial.read());
  }

and send AT+SAPBR=3,1,"Contype","GPRS" or just AT command with serial monitor, everything works fine.

Can someone help with this?


texts: RF receiver becomes weakened after motor turns on

texts:
I recently bought a simple SMAKN 315MHz RF receiver and transmitter, and I got everything working so that the transmitter transmits the value of a joystick, and the receiver receives that and uses it to set the analogWrite() of a motor on a PWM pin.

However, the moment the motor turns on, the receiver just weakens tremendously. At that point it only gets a message when I stick the receiver right against the transmitter. I’m powering the arduino and motor with a 3.7v LiPo battery btw.

Any help? I’ve tried with a 9V alkaline and a 9V adapter and nothing significantly changed.


texts: Can i use Arduino IDE with the Wemos D1 R2 AND also use its ESP8266 module to send AT commands?

texts:
I have recently started digging into ESP8266 and learned a little about AT commands and i would really like to add the Wi-Fi functionality in my electronics project, which already uses an Arduino UNO R3. I think it would be much easier to use the Wemos D1 R2 since it is basically an UNO + ESP8266. Here is a link to the official product information page: https://wiki.wemos.cc/products:d1:d1 and its schematic: https://wiki.wemos.cc/_media/products:d1:d1_v2.0.0.pdf

I would like to know if it's possible to use the Arduino IDE to program on the Wemos D1 as i do with the normal UNO but also at the same time, be able to send AT commands using its on-board ESP8266?


texts: How to upload code without closing puTTY

texts: My question is quite simple: can you, somehow, upload Arduino code without closing puTTY's serial console? I hate having to close the program to open it again for reading the incoming information.


texts:
The ESP 12 board has 22 pins

Are all of them usable?

I understand that there is an external flash memory that is accessed through SPI, but I'm not sure what the impact on the pins is.

And if it is so, then why are the pins available?

Is there a sort of a decoder board that receive as an input, let's say 3 SPIOs and outputs 8 GPIOs?

Is there a way to obtain more GPIO pins?


texts: Why doesn't the LED turn on in this circuit?

texts:
I'm experimenting with buttons and LEDs and I would like my code to change a LED's brightness once a button is pressed. I connect the LED to the PWD digital pin.

My circuit looks like this one:

This is the code I'm using:

int switchPin = 8;
int ledPin = 11;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledLevel = 0;

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

boolean debounce(boolean last) {
    boolean current = digitalRead(switchPin);
    if (last != current) {
        delay(5);
        current = digitalRead(switchPin);
    }
return current;
}

void loop() {
    currentButton = debounce(lastButton);
    if (lastButton == LOW && currentButton == HIGH) {
        ledLevel = ledLevel + 51;
    }
    lastButton = currentButton;

    if (ledLevel > 255) ledLevel = 0;
    analogWrite(ledPin, ledLevel);
}

Though, the LED never turns on, but the light on the Arduino is on. I made sure the leads of the LED were in the right spot. Why doesn't the LED turn on?


texts:
I bought a this voltage regulator . DC-DC 5v 8A voltage regulator. ıts supported 8-35V input voltage . And i want to use this with 12v power supply.
But i searched on the internet . Nodemcu max amp is 800mA. This device can provide 2A per usb output if i will plug the nodemcu with usb cable this what happen ? Does it burn ? How can i drop the amps ?  i want to use other 3 usb output with other devices sensors and screen .


texts:
I'm building an electronic gate. I'm needing a photoelectric sensor to detect cars. This one in the link looks decent. it runs on 12v so I will need to power it separately from the arduino. But does this mean it also puts 12v back to the signal wire? Will that work with ardunio without burning the circuit? How many V can i send into an arduino pin?

thanks

photo electric sensor


texts:
I'm trying to call an interrupt routine (let's call it handler() ) every second on my arduino DUE.
I thought the simplest way to do this was to use this library
but it seems that i don't know how to use it...


texts:
i have some data logging to do. And i want some what accurate time meaning accuracy has to be +/- 1 minute.

I have considered a RTC, but then i thought. When i was 10 i got a watch that kept time from this radio clock. And if it is possible 20 years ago to make a clock that updates automatically in such as small form factor, then i should be able to do it with my arduino today.

Does anyone know of a guide/solution with components where i can read this atomic radio clock?


texts: using a switch case with a 5-position switch and serial output

texts:
I'm trying to get started on developing a menu system for my LCD1602. I have a Parallax 5-position switch (up,down,left,right,center) and I would like to interface the two.
I've been trying to get some code working but I'm kind of lost. I don't have a lot of recent experience with Arduino and could use some advice. I realize that there is a version of the 1602 that comes with a keypad integrated into the circuit but I don't have that model. I have a plain-jane screen and a separate 5-position switch.
I'm also aware that the easiest way to accomplish what I desire is with a resistor network and mapping the ADC values. However, I don't want to make an analog switch, I want to make a digital switch.
Is there any way I can take the pins and put them into an array and then translate that into a switch case statement?
I've tried several different ideas and nothing seems to be working. Forgive the example code, it's hacked together.
below is my code
*/

// constants won't change. They're used here to set pin numbers:
char buttonChar1 = 'a';     // the number of the pushbutton pin
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int pinsArray[5] = {2, 3, 4, 5, 6};
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(buttonPin5, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1) == 2;
  buttonState2 = digitalRead(buttonPin2) == 3;
  buttonState3 = digitalRead(buttonPin3) == 4;
  buttonState4 = digitalRead(buttonPin4) == 5;
  buttonState5 = digitalRead(buttonPin5) == 6;
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:

  switch (pinsArray[5]) {
    case 2:    //
      digitalWrite(ledPin, HIGH);
      Serial.println("button1");
      break;
    case 3:     //
      digitalWrite(ledPin, HIGH);
      Serial.println("dim");
      break;
    case 4:    //
      Serial.println("medium");
      break;
    case 5:    //
      Serial.println("bright");
      break;
  }
  }


texts:
The Arduino LiquidCrystal library has 4 constructors with different arguments:

LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)

The following comments are stated for the constructor arguments:

  [...] d0, d1, d2, and d3 are optional; if omitted, the LCD will be controlled using only the four data lines (d4, d5, d6, d7).

What is the point of d0-d3 if they are not needed? Will they decrease the response time?


texts: Why is no PWM signal generated using Timer 2?

texts:
I managed to work with timer 0 and 1 but am unable to generate a PWM with timer 2 in my atmega328p.

This is the code:

#include <avr/io.h>

int main(void)
{
    /* PD6 output */
    DDRD |= (1 << DDD6);

    /* 50% duty cycle */
    OCR2A = 128;

    /* fast PWM  */
    TCCR2A |= (1 << WGM21) | (1 << WGM20);

    /* prescaler = 8 */
    TCCR2B |= (1 << CS21);

    while (1);

}

Could someone explain what the issue is and why I am not seeing a pwm signal on pin 6 of my arduino uno board?

Thanks


texts:
For a bitbanging project I'm working on, I need to measure microseconds as accurately as possible. The function micros() won't work for me here because of the unpredictable times at which it might roll over. I have been using this project by Louis Frigon as an example:

https://web.archive.org/web/20140627135927/http://www.sigmaobjects.com/toyota/

In this document he sets his Atmega8's prescaler value:

// Timer 0 prescaler = 8 ( 1 count / us )
TCCR0 = _BV(CS01);

Do I understand that after these instructions, TCNT0 counts up by nearly precise microseconds?
If so, what math could I use to set my prescaler for measuring microseconds? The 328P has a higher clock speed, does that mean I won't be able to do this?


texts:
I know that the Arduino IDE does some simple tasks automatically: for example it creates function prototypes, but this function sometimes fails.

Does that IDE run other hidden "pre-precompiler" tasks?

Is there a way to disable them? (this question refers especially to the function prototypes creator).


texts: Problem with connecting ESP8266 to arduino

texts:
I have:

Arduino Uno
ESP8266

Problem:
I see SoftAP and can connect to it. But I can't send AT-commands to ESP8266 from Arduino.
I use Arduino app v.1.6.5 for send command to ESP8266 via Arduino. But I don't get answer. And ESP8266 doesn't blinking.

I use this scheme:

Please, help me. I'm trying to fix this is very time consuming.


texts: How to read frequency into voltage with Arduino with an external source of frequency of 0-1Khz max?


texts:
I'm building a monitoring IP class, IPmonitoring, that using an SPIFFS class that I wrote, flashLOG. Inside IPmonitoring I have 2 instances of flashLOG (code below).
My sketch have several instances of IPmonitoring for several servicesI wish to monitor. I Wish that connectionLOG and disconnectionLOG have unique and automated names.
For example if I'm monitoring a service called MQTT its connect and disconnect log will be MQTT_discolog.txt and MQTT_conlog.txt. In my code below, filename1 and  filename2 are consts.
class IPmonitoring
{
private:
        char *_IP;
        char *_nick;

        flashLOG connectionLOG;
        flashLOG disconnectionLOG;

public:
        IPmonitoring(char *IP, char *nick, char *filename1 = "/conlog.txt", char *filename2 = "/disconlog.txt")
            : connectionLOG(filename1), disconnectionLOG(filename2)
        {
                _IP = IP;
                _nick = nick;
        }

EDIT1 - example how to use class
my goal is that filename1 for example will be MQTTbroker_connlog.txt meaning a combination of _nick and a suffix,
IPmonitoring MQTT_service("192.168.3.200","MQTTbroker");

void setup()
{
MQTT_service.start();
}

void loop()
{
MQTT_service.loop();
}


texts: Debugging my Stepper Motor Driver circuit

texts:
I'm using the Pololu DRV8825 Stepper Motor Driver to control a NEMA 17 Steppermotor with an Arduino Uno.  According to the Pololu website, the circuit should be wired as follows:

I did, however, deviate from this exact sketch a little bit:

The Arduino (microcontroller) is powered by a USB cable connected to the computer
I connected the 5V pin on the arduino to the + rail on a breadboard.  I then connected two wires on this rail to the RESET and SLEEP pins on the driver.
I'm using a 9V battery to power the motor.
I've connected the DIR and STEP pins to Arduino Uno pins 12 & 13, respectively.

Consequently, I coded and uploaded the following sketch:

int stp = 13;  //connect pin 13 to step
int dir = 12;  // connect pin 12 to dir
int a = 0;     //  gen counter

void setup()
{
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
}

void loop()
{
  if (a <  200)  //sweep 200 step in dir 1
   {
    a++;
    digitalWrite(stp, HIGH);
    delay(10);
    digitalWrite(stp, LOW);
    delay(10);
   }
  else
   {
    digitalWrite(dir, HIGH);
    a++;
    digitalWrite(stp, HIGH);
    delay(10);
    digitalWrite(stp, LOW);
    delay(10);

    if (a>400)    //sweep 200 in dir 2
     {
      a = 0;
      digitalWrite(dir, LOW);
     }
    }
}

RESULT
The stepper motor does not turn.  Instead, it just hisses at a high pitch.  After a short while, the driver gets very hot.

THINGS I'VE TRIED

I double checked to make sure that connected stepper wires pairs are properly connected to the "A" pins and "B" pins on the driver.
I tried reversing the A1-A2 pair and B1-B2 pair in all possible combinations.  All combinations produce the same result as above.
I tried increasing the motor power supply to 12V (8 alkaline AA batteries).  The same result occurs.
I double checked to make sure the 100microF radial electrolytic capacitor is connected with the long end to the positive motor supply and short end to the negative motor supply (on a different breadboard rail than the logic power supply, of course).
I tried using the 3.3V pin instead of the 5V pin to connect to SLEEP and RESET on the driver.  Again, the same result occurs.

I'm not really sure what to try next to debug my circuit.

My Hunch:

I do, however, have one suspicion based on a little warning box on the pololu website which reads:

  Caution: Installing the header pins so that the silkscreen side is up
  and the components are down can limit the range of motion of the
  trimpot used to set the current limit. If you plan on installing the
  header pins in this orientation, please set the current limit before
  soldering in the pins.

The way I soldered the headers onto the driver looks like the bottom left corner of the picture below:

My Question:
Given that my stepper motor requires 1.7A current, is there anything I can do to improve this circuit to make it work?  Did I make any mistakes?  Is there anything else I should try or check?  Did I solder the header in the wrong way?


texts: 10 DOF gyro and accelerometer to x,y,z displacement

texts: I have a 10 DOF sensor with wire outputs labeled "VIN", "GND", "SCL", and "SDA".  I would like to wire these into my arduino and ultimately obtain x, y, and z displacement.  This might sound like a simple problem for a veteran but I have gotten lost in the literature and code.  Where can I learn how to do this or is there a library that I can use?


texts:
I am trying to get a nice sounding varying PWM to DAC, and intend to use a Sallen Key as part of an active low pass filter.
I set the Fast PWM at a max of 255 (WGM1[0-3] = 5) and set/clear OC1A upon comparing with OCR1A (1<< COM1A1)
I also update the value of OCR1A in 64 distinct steps, changing those steps around 15'000 times a second to create a specific sinusoidal shape.
As the chip works at 16 Mega Hertz, does this mean that one cycle of PWM is 16'000'000/256= 62.5 Kilo Hertz? If not, what is its resolution
Thank you!


texts:
i want the led to light at the beginning and stays like this for a while then turns off, so i wrote:

int led=13;
void setup() {
  pinMode(led,OUTPUT);
}
void loop() {
    digitalWrite(led,HIGH);
    delay (5000);
    digitalWrite (led,LOW);
}

as i understand it should start with high means on digitalWrite(led,HIGH)...and stays like this for 5000us  delay (5000)  then it should turn off with  digitalWrite (led,LOW).
but why its not working, it starts with off for afew seconds then stays on..what i understand wrong with these simple steps ????


texts:
I'm a total newbie. I bought a Pro Micro but I didn't know that it can't be used, if you don't solder things in his holes.
I found this picture on Google:

And it seems that exists those stuffs (green and white) to test the circuit before soldering.

Do you know where can I buy them? Or do you know their name?

Thanks.


texts: Error 400. The request has an invalid header name ESP8266 (HTTP-POST)

texts:
I'm trying to send a http post to my server from an esp8266-Wifi (I use the ESP8266 library)

I check all my http post format, and I guess is okay... but at the response, the monitor serial answer me like this:

Requesting POST: HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Sat, 10 Jun 2017 23:12:48 GMT
Connection: close
Content-Length: 339

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">

Bad Request - Invalid Header

HTTP Error 400. The request has an invalid header name.

closing connection

and this is my code:

#include <ESP8266WiFi.h>
const char* ssid     = "Putostodosmenosyo";
const char* password = "CetriX.2016%Gdl";

const char* host = "187.201.44.110";

const String Cadenadatos = "info=Micanton|2017-06-09%2012:00|25" ;
//const String Tamano = String(Cadenadatos.length()) ;
const String postiu = "POST /wsCo2Keellingv1002/wsCo2Keelling.asmx/GuardaInfoArduino HTTP/1.1\r\nHost:187.201.44.110:80\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length:144\r\n\r\n?info="+String(Cadenadatos)+"\n" ;
const String postam = String(postiu);

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

  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

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

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  delay(2000) ;
}

void loop() {

  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host,httpPort)) {
    Serial.println("Conexion fallida");
    return;
  }

 //String data = "pst=temperature>" + String(random(0,100)) +"||humidity>" + String(random(0,100)) + "||data>text";

   Serial.print("Requesting POST: ");
   // Send request to the server:
   //client.println("POST /wsCo2Keellingv1002/wsCo2Keelling.asmx/GuardaInfoArduino HTTP/1.1");
   //client.println();
   //client.println("co2kelling.hopto.org") ;
   client.println("POST /wsCo2Keellingv1002/wsCo2Keelling.asmx/GuardaInfoArduino HTTP/1.1");
   client.println("Host: co2kelling.hopto.org");
   client.println("Content-Type: application/x-www-form-urlencoded");
   client.print("Content-length: ");
   client.print(postiu.length());
   client.println();
   client.print(String(Cadenadatos));
   while(client.connected())
   {
    while(client.available())
    //String line = client.readStringUntil('\r') ;
    Serial.write(client.read()) ;
   }

   /*delay(500); // Can be changed
  if (client.connected()) {
    client.stop();  // DISCONNECT FROM THE SERVER
  }*/
  Serial.println();
  Serial.println("closing connection");
  delay(5000);
}

NOTE: this is my fixed url
http://187.201.44.110/wsCo2Keellingv1002/wsCo2Keelling.asmx/GuardaInfoArduino?info=Micanton|2017-06-09%2012:00|25

EDIT

This is my Post format:

POST /wsCo2Keellingv1002/wsCo2Keelling.asmx/GuardaInfoArduino HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
info=string


texts: How to avoid electromagnetic interference on ESP32 input

texts:
I've realized a simple circuit like the following, in order to implement a rain gauge that I can access via HTTP:

With the following sketch:

#include <WebServer.h>
#include <WiFi.h>
#include <WiFiClient.h>

/**
 * This constant is calculated with the following procedure:
 * - Area of pluviometer is 55 cm^2
 * - Volume of test water is 100 cm^2
 * Resulting height of water is 1.82 cm. Using this water quantity, generates 40 ticks of the pluviometer. So every tick is 0.455 mm of rain.
 */
const double millimetersPerTick = 0.455;
const char* ssid = "*********";
const char* password = "*********";

WebServer server(80);

/* LED pin */
byte ledPin = 2;
/* pin that is attached to interrupt */
byte interruptPin = 14;
/* hold the state of LED when toggling */
volatile byte state = LOW;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;

void IRAM_ATTR handleInterrupt() {
  portENTER_CRITICAL_ISR(&mux);
  interruptCounter++;
  portEXIT_CRITICAL_ISR(&mux);
}

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

  // WIFI initialization
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  pinMode(ledPin, OUTPUT);
  /* set the interrupt pin as input pullup*/
  pinMode(interruptPin, INPUT_PULLUP);
  /* attach interrupt to the pin
  function blink will be invoked when interrupt occurs
  interrupt occurs whenever the pin change value */

   // Notify wifi connection
  digitalWrite(ledPin, HIGH);
  delay(2000);
  digitalWrite(ledPin, LOW);

  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, RISING);

  server.on("/", []() {
    server.send(200, "text/plain", String(millimetersPerTick * numberOfInterrupts));
    numberOfInterrupts = 0;
  });

  server.onNotFound([]() {
    server.send(404, "text/plain", "Not found");
  });

  server.begin();
}

void loop() {
  server.handleClient();

  if(interruptCounter>0) {
    portENTER_CRITICAL(&mux);
    interruptCounter--;
    portEXIT_CRITICAL(&mux);

    numberOfInterrupts++;
    Serial.print("An interrupt has occurred. Total: ");
    Serial.println(numberOfInterrupts);
    state = !state;
    digitalWrite(ledPin, state);
    delay(100);
    state = !state;
    digitalWrite(ledPin, state);
  }
}

The main issue of this circuit is that if I connect the AC plug it suffers from interferences from the household electricity. For example if I turn on the light, the interrupt is called. I tried also to buy an EMI filter like this but it doesn't reduce the problem. What can I do to avoid this?


texts: How to get data from 9DOF razor IMU directly to arduino mega

texts:
My final project goal is to make Brushless gimbal for drones using only Arduino MEGA 2560 and 9DOF IMU for control. On Instructables I found two excellent tutorials. Both are different than mine in selected components.
I use the following components:
Arduino MEGA2560
Motors - Quanum 2208 Precision Brushless Gimbal Motor ( httpx://goo.gl/RDBvJL)
Motor Driver - H bridge L298n (httpx://goo.gl/A4ZQi5)
9DOF Razor IMU (httpx://goo.gl/myg9oj )
I'm stuck with 9DOF Razor IMU. Surfing on the internet I found a great tutorial and  github repository (httpx://goo.gl/jh2pfU). This tutorial is excellent and AHRS works great with the FTDI Basic Breakout 3.3V. They gave me a good starting point, but my goal is use only Arduino MEGA2560 and sensors.
I want to connect the Arduino and 9DOF IMU directly and use the accelerometer data (Yaw, Pitch, Roll) for directly control the engines. On the website of the manufacturer Sparkfun (httpx://goo.gl/myg9oj ) I can’t find any datasheet exclusively for 9DOF IMU that could help me to connect Arduino and IMU. There are only datasheet of sensors that are on IMU ( ITG-3200 (MEMS triple-axis gyro), ADXL345 (triple-axis accelerometer), and HMC5883L (triple-axis magnetometer)  which are useless for me.
That's why I decided to use code from this site ( httpx://goo.gl/zOnYjN ) and he works great. I connected everything as is in tutorial and  Arduino SerialMonitor show me the desired values YPR. Values load very quickly directly from IMU and printed on SerialMonitor.
Values on SerialMonitor looks like this:
YPR=72.13,1.74,-16.38
YPR=72.14,1.72,-16.39
YPR=72.12,1.71,-16.39
YPR=72.13,1.71,-16.37
YPR=72.13,1.70,-16.40 …
HELP ME
This is my first solo Arduino project and I have a lot of questions about it.
How could I parse the data that appears on SerialMonitor to get new variables eg. Yaw = 72.12, Pitch = 1.74, Roll = -16.39?
Is it possible to do that?
Does anyone have any experience with 9DOF razor IMU and maybe know  better way to collect information from the accelerometer 9DOF razor IMU?
I want to achieve three separate variables which i will use to control the brushless motor. I think this should be an easier method as it is just comma separated numbers but then again i am new to arduino serial communication so i would appreciate any help with this. Even if it's only how to parse and extract the values.


texts: Selection of External CT for my application

texts:
Here I have attached my ckt for my application. My application is Motor protection Relay. Based on Current sense of 3 CT tripping of relay will occur. Tripping might due to under/over/SC/Locked rotor Etc. Now I am facing in selection of CT and interfacing with Arduino Un0.

I know HP rating and its max current measurement range.

How to Select CT for my application based on Current measurement range
How Burden resistor calculated.
How Size of CT can be calculated.
How to judge max supply voltage supplied to Arduino
Type of CT to be used protection class CT or Normal CT
How to calculate Max Current level can read through CT. it will be mentioned in datasheet. what it will do when it cross rated current? means when it attain saturation if I use above circuit what is effect on Arduino Uno board.
How burden VA calculated here.

I have researched and got one of application where they using AC AC1030 datasheet

Ip=30A I max=75A
 turns ratio: 1000:1
 supply voltage = 220VAC
min power continuous CT can sense = 220X30 = 6.6 kW
Max power sense for short period=220*75=16.5 kW
 Irms=1.4*30A=42A

burden resistor= 2.5/(42/1000)=59.5ohm R1=R2=100kohm resistor.

Is it correct? What are other care I need to consider while taking hardware design?


texts:
I am getting the following error when attempting to compile my sketch:

  In file included from sketch.ino:24:0: SerialRenderer.h:7: error:
  expected class-name before '{' token

SerialRenderer.h

#ifndef SERIALRENDERER_H_
#define SERIALRENDERER_H_

#include <MenuSystem.h>

class SerialRenderer : public MenuComponentRenderer
{
public:
    SerialRenderer();
    virtual ~SerialRenderer();

public: // methods from MenuComponentRenderer
    virtual void render(Menu const& menu) const;
    virtual void render_menu_item(MenuItem const& menu_item) const;
    virtual void render_back_menu_item(BackMenuItem const& menu_item) const;
    virtual void render_numeric_menu_item(NumericMenuItem const& menu_item) const;
    virtual void render_menu(Menu const& menu) const;
};

#endif // SERIALRENDERER_H_

The contents of MenuSystem.h can be found at https://github.com/jonblack/arduino-menusystem/blob/master/MenuSystem.h.

It seems like the include of MenuSystem.h does not happen when SerialRenderer.h is included from my main sketch file. I get the same error if the include in SerialRenderer.h is removed.

Is there something simple I am missing for the compiler to be able to "see" MenuSystem.h?

EDIT:

Turns out I was looking at a newer version of the arduino-menusystem library than I had installed (version 2.1.1). That version did not have a class called MenuComponentRenderer.

I pulled the latest version from https://github.com/jonblack/arduino-menusystem/tree/master and it compiles fine.


texts:
As an exercise to learn rather then the most efficient way to accomplish a goal.... (i'm a hands on hardware guy, but I need to get my Sh!T together and learn some coding)
I would like to make an LED less bright within a project.  I have a nano set up to control a relay to control a dc load when a momentary switch is pressed (this is kinda needlessly complicated solely to allow me to use a particular momentary switch I wanted to use for a bunch of not that great reasons ;-)
Anyway... the code i'm using is this:
int pbuttonPin = 2;// connect output to push button
int relayPin = 10;// Connected to relay (LED)

int val = 0; // push value from pin 2
int lightON = 0;//light status
int pushed = 0;//push status

void setup() {
  // Robojax.com code and video tutorial for push button ON and OFF
  Serial.begin(9600);
  pinMode(pbuttonPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, HIGH);// keep the load OFF at the begining. If you wanted to be ON, change the HIGH to LOW
}

void loop() {
// Robojax.com code and video tutorial for push button ON and OFF
  val = digitalRead(pbuttonPin);// read the push button value

  if(val == HIGH && lightON == LOW){

    pushed = 1-pushed;
    delay(100);
  }

  lightON = val;

      if(pushed == HIGH){
        Serial.println("Light ON");
        digitalWrite(relayPin, LOW);

      }else{
        Serial.println("Light OFF");
        digitalWrite(relayPin, HIGH);

      }

// Robojax.com code and video tutorial for push button ON and OFF

  delay(100);

The above code is straight up cut and paste... i'm clueless
I have a LED cathode on pin 10, (so i know the relay is on more easily from a distance).  however the application is on a boat, and at night it is too bright and distracting.  So i want to make the LED dimmer... I know I could add a larger value resistor, but i want to expand my understanding and would like suggestions on other ways PWM maybe....
cheers:


texts: What happens when there's no space left on SD card?

texts: I'm coding a data logger and I would like to know what happens if there are no bytes remaining to be written using SD library, ie, if the SD card is full of data. The logging would just stop or I would get some nasty error?