texts: Temperature anomaly on BS18B20 + NodeMCU on Tingspeak

texts:
Temperature drops occasionally from 59+C to -13C or to other random values. Used sketch and info from this site:
http://internetofthinking.blogspot.com/2016/02/upload-ds18b20-temperature-sensor-data.html

NodeMCU powered by phone charger 5v 1a via microUSB.
Placing 4.7 kOm resistor between data wire and 3v3 didn't help me.

Does anyone know how to solve this issue? Like filtering results and pushing to server only values that do not differ by more than n*C, or something like that?

Here is the sketch

#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define myPeriodic 15 //in sec | Thingspeak pub is 15sec
#define ONE_WIRE_BUS 2  // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float prevTemp = 0;
const char* server = "api.thingspeak.com";
String apiKey ="-";
const char* MY_SSID = "-";
const char* MY_PWD = "-";
int sent = 0;
void setup() {
  Serial.begin(115200);
  connectWifi();
}

void loop() {
  float temp;
  //char buffer[10];
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0)+5;
  //String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()
  Serial.print(String(sent)+" Temperature: ");
  Serial.println(temp);

  //if (temp != prevTemp)
  //{
  //sendTeperatureTS(temp);
  //prevTemp = temp;
  //}

  sendTeperatureTS(temp);
  int count = myPeriodic;
  while(count--)
  delay(1000);
}

void connectWifi()
{
  Serial.print("Connecting to "+*MY_SSID);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }

  Serial.println("");
  Serial.println("Connected");
  Serial.println("");
}//end connect

void sendTeperatureTS(float temp)
{
   WiFiClient client;

   if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
   Serial.println("WiFi Client connected ");

   String postStr = apiKey;
   postStr += "&field1=";
   postStr += String(temp);
   postStr += "\r\n\r\n";

   client.print("POST /update HTTP/1.1\n");
   client.print("Host: api.thingspeak.com\n");
   client.print("Connection: close\n");
   client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(postStr.length());
   client.print("\n\n");
   client.print(postStr);
   delay(1000);

   }//end if
   sent++;
 client.stop();
}//end send


texts: I found a lot of methods on the internet and I was wondering what would be the best method to send data from sensors connected to Arduino to a MySQL database in a WAMP server continuously.


texts: Can two electronic speed controllers be connected to the same ground pin?

texts:
I have a setup to read two sets of signals from a radio control receiver using an Arduino NANO: the throttle channel and the rudder channel. With some programming knowledge (which I have) this isn't too difficult, but I need help on the electrical side of things. This is the current setup I have (it works, though I'm told there is the possibility that my computer is acting as a ground for the PWM signal wires from the receiver):

OK, great. I'm able to control the motor programmatically, mix values from the receiver, etc. See this video for what I'm doing. However, this setup leaves some gaps:

Question 1
I actually need two motors for dual thrust. Each motor is to be controlled individually by the program (for asymmetric thrust). Since there are only two grounds on the Arduino, can I plug both ESC grounds to the same pin? Currently, the receiver is getting power from the Arduino, and grounds back. The speed controller grounds to the second ground pin. Diagram below:

Question 2
All that is great, but the NANO is still powered by USB: obviously I'm not putting my laptop in the RC boat just to supply a few volts! Incidentally, both electronic speed controllers (ESCs) have battery eliminator circuits (BECs), usually used to power the receiver. Would I be able to connect one of them to the VIN pin of the Arduino?

I tried something like that, but the Arduino got very hot near the pin, and it smelled. Unfortunately, I don't have my circuit at the time. The Arduino's Amazon page states support for 5V to 12V external power supply. Each ESC can supply 5V at 3A. Maybe there's a way to plug them to make 10V?

Question 3
My idea also calls for three sets of LEDs, which will be lit also based on inputs from the receiver. Can these be grounded to the same wire, like I was suggesting above for the ESCs?


texts:
I am a complete noob at arduino, so I apologize if this is a stupid question.

I would like to take input from two microphones and send the output to a bluetooth headset using an Arduino processor? Is this something that can be done with these processors or do I need something more powerful, like a Raspberry Pi?

I don't really need to process the signal at all, simply add the 2 inputs together and divide by 2 to keep the output from clipping.


texts:
I am creating a project that uses Bluetooth, But unfortunately it requires some kind of control of the range. I was thinking a potentiometer controlling the power going to the transmitters antenna. But I have no clue how I would program this. Can anyone help me out or point me in the right direction? Thanks

EDIT
Okay I am making this because I am designing a sensor that tells if you are in a room. For example when you leave the room the Bluetooth single is no longer in range then it notifies the arduino. I am not sure if you can do this but I cant see why not.


texts: Write to serial only if the state of a light sensor changes

texts:
I need to know the times when an LED strip turns on and turns off.  The LED switch is driven by light dependent resistor.  When the sun goes down the LED strip turns on. This is all happening on a circuit that I did not create nor is it Arduino driven.  I need to know the times (in local time) that the LED turns on and off.  I have another light dependent resistor near the LED strip and I am using the Arduino Uno to print to the serial monitor its state every second.
I can listen to the serial port via Python and record the seconds via Python.  No worries
What I would like to do is have the Arduino code print to the serial monitor only if the state of the LED changes.  For example, when the LDR turns on the LED strip, Arduino prints to the serial monitor once, then in the morning when the LED goes off, print to the serial monitor once.  I am having trouble figuring out the code to do that.  The LDR is not like a button since it is always reporting back analog data.    Any help is appreciated.


texts:
I am trying to get the response from server using AT commands. This is my program
#include <SoftwareSerial.h>

const byte rxPin = 2; // Wire this to Tx Pin of ESP8266
const byte txPin = 3; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  Serial.println("Sending an AT command...");
  ESP8266.println("AT+CIPMUX=1");
  delay(3000);

  ESP8266.println("AT+CIPSTART=0,\"TCP\",\"192.168.50.1\",1234");
  delay(3000);

  while (ESP8266.available()){
     String res = ESP8266.readStringUntil('\t');
     Serial.println(res);
  }

}

My server is just sending just one string as the output.
My console is getting this kind of output? Is there a way to clean this?
Sending an AT command...
AZi%PSՊj
C⸮j⸮L⸮AT+CIPSTART<0,"TCP","193.168.50.1",1234
0,CONNECT

OK
+IPD,0,1:10,CLOSDD

Sending an AT command...

I read thread and changed SoftwareSerial.h file. But still no luck.
Thanks in advance.


texts: How to use this Arduino code to control multiple different LEDs?

texts:
I am making an Android-controlled LED system over Bluetooth but I need to use 4 LEDs. I have done Android app but I am not able to figure out this Arduino code. Can some please help me get this done?

char command;
String string;
boolean ledon = false;
#define led 5

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

void loop() {
  if (Serial.available() > 0) {
    string = "";
  }

  while(Serial.available() > 0) {
    command = ((byte)Serial.read());
    if(command == ':') {
      break;
    } else {
      string += command;
    }
    delay(1);
  }

  if(string == "TO") {
    ledOn();
    ledon = true;
  }

  if(string =="TF") {
    ledOff();
    ledon = false;
    Serial.println(string);
  }

  if ((string.toInt()>=0)&&(string.toInt()<=255)) {
    if (ledon==true) {
      analogWrite(led, string.toInt());
      Serial.println(string);
      delay(10);
    }
  }
}

void ledOn() {
  analogWrite(led, 255);
  delay(10);
}

void ledOff() {
  analogWrite(led, 0);
  delay(10);
}


texts: How do I make a motor spin every 10 minutes?

texts: I am new to Arduino, please don't be harsh. I want to make a motor spin at every x amount of time (Lets say 10 minutes). Once the program is started, I want it to start the motor (stop after 10 seconds), and every 10 minutes, it continues the process. Is it possible to make it?,


texts: Where could I find the "Serial.find()" source code?

texts:
As written in the title, could you tell me where to find the source code of the function "Serial.find()"?

I haven' t installed the Arduino IDE, so I'm glad if you could me link a web resource, or if you directly copy the source code here .

Thanks for your time.


texts:
After researching many sketches on interfacing with the DFPlayer Mini, all of them include softwareserial.h which the Due does not use. So are there any example sketches for the Due interfacing with a DFPlayer that I could study?
Thank you for your time.


texts:
I'm trying to programming Arduino Nano with another Arduino Nano via ICSP. I have a 6-pin cable directly connected to the ICSP's pin of the second board:

ICSP NANO ISP 1
pin1 pin2 pin3
pin4 pin5 pin6

ICSP NANO 2 (to be programmed)
pin1 pin2 pin3
pin4 pin5 pin6

I have correspondingly wired pin 1 (ICSP) of nano1 to pin 1 (ICSP) Nano 2, pin 2 (ICSP) of nano 1 to pin 2 (ICSP) Nano 2, etc.

I make this step before flashing: getting the Arduino ISP with example sketch ArduinoISP, plug off the Arduino ISP and attach the 6-pin cable to the ICSP port of the second board, plug Arduino ISP to the USB port, in the Tools menu select Arduino as ISP, load with external programmer, and fail...

This is the log:

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

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

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

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Errore durante il caricamento dello sketch
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.


texts: Controlling common anode RGB LED with PWM - Can individual colors be done w/o transistors?

texts:
I am using PWM (analogWrite) with a common anode LED. My previous experience is using a common cathode. My breadboard is as shown:

simulate this circuit – Schematic created using CircuitLab

This creates a semi-bright white (ugly red-green-blue mixture) like I expected. I am using only one PWM output (It is currently fading).

Now, what I ask is how can I use multiple PWM outputs to make different colors display without transistors? I was thinking that I could have 3 dedicated pins on the Arduino that switch from ground to floating extremely fast, but is there an easier way?
If not, a little explanation on how to do it with transistors (mostly just a small wiring diagram) would be great. Cheers!


texts: Why would using the += operator on an unsigned long crash my sketch?

texts:
I wrote a simple Timer class that's designed to work even in the face of the 49 day wrap of the millis() counter. I wanted a library that I could easily re-use and I could never remember the right way of dealing with the wrap-around so I thought: do it once, right. However, it has not gone according to the script!

Here's the source code, header first.

class Timer
    {
public:
    Timer();
    void SetDuration(unsigned long duration);
    bool Expired();
    unsigned long Elapsed();
    unsigned long Remaining();
    void Repeat();
    bool Enabled();
    void Stop();
private:
    unsigned long startedAt;
    unsigned long interval;
    };

...and the implementation...

#include "Timer.h"

Timer::Timer()
    {
    startedAt = 0;
    interval = 0;
    }

/*
 * Sets the timer interval and establishes the reference datum as the instant when this method was called.
 */
void Timer::SetDuration(unsigned long duration)
    {
    startedAt = millis();
    interval = duration;
    }

unsigned long Timer::Elapsed()
    {
    if (!Enabled())
        return 0UL;
    unsigned long elapsed = millis() - startedAt;
    return elapsed;
    }

unsigned long Timer::Remaining()
{
    return interval - Elapsed();
}

bool Timer::Expired()
    {
    return Enabled() ? Elapsed() >= interval : false;
    }

/*
 * Repeats the timer interval but does not reset the reference datum.
 * This should be used when repeatedly timing the same interval, and it is
 * intended that the intervals be consistent _on average_.
 */
void Timer::Repeat()
    {
    startedAt += interval;
    }

bool Timer::Enabled()
{
    return interval > 0;
}

void Timer::Stop()
{
    interval = 0;
}

Now my problem is this. My sketch gets to a certain point then crashes (re-runs from the start). The behaviour seems a lot like an odd stack corruption that's causing the code to branch to Oblivion. I've spent several hours doing a binary-chop on the code to narrow down the cause (it's a big sketch) and much to my surprise, the culprit appears to be the Repeat() method in my timer class. I use it in just one place in my code. When I call the Repeat() method, it crashes my sketch; If I don't call Repeat() but instead call SetDuration(n), the program doesn't crash and everything is fine. I've tried this in two different sketches with consistent results.

I've got spots before my eyes from trying to understand what's happening here. I'm a C# programmer most of the time although I'm not completely new to C and C++, but I've made dumb mistakes in Arduino code before. Repeat() could hardly be simpler or safer code - but is it? Is there anything wrong with my code that I'm just not seeing?

UPDATE: Stack Overflow effect (where you see the solution yourself as soon as you post a question) has kicked in and I've solved it. My implementation of Repeat() was moving startedAt ahead of millis() giving a negative amount of elapsed time (which in unsigned math means a very large positive amount of elapsed time). This was causing immediate time-out of the timer and causing the sketch to think the sky was falling in. So not a memory corruption, just some poorly implemented unsigned math.


texts: How to set the data length for SPI communication in Arduino library?

texts: How can I set the number of bits that need to be transferred in SPI communication from a Slave chip to Master MCU using Arduino SPI Library in a SPI transaction? Let us say I want to read 14-bits data from Slave into my Master Arduino MCU then how would set this 14-bits in the SPI Library?


texts: Circuit diagram for ACS712 and ZMPT101B with ESP8266 using ADS1115

texts: This is probably a cry for help for a circuit diagram which involves connecting ESP8266 with ADS1115 with ACS712 and ZMPT101B(voltage sensor). Since both of them uses analog pins, and using a diode separator is not a proper idea in real-life. Therefore I ended up using the ADS1115 for more analog pins, which should be working fine. I am not a electrical engineer so I am having real trouble as to how to fix all Four of them together. Can any one help me with a circuit diagram for this? Any links or research papers links, etc. Thanks


texts: Android phone can't get ESP8266WebServer page if Content-Length > 1460

texts:
I uploaded the following sketch to my ESP8266:

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

ESP8266WebServer server(80);
String toServe;

void serveShortString() {
    server.send(200, "text/plain", "short string!");
}

void serveLongString() {
    server.send(200, "text/plain", toServe);
}

void setup() {
    WiFi.softAP("test");

    // fill string to serve:
    toServe.reserve(3000);
    for(int i=0; i<150; i++) toServe += "1234567890123456789\n";

    server.on("/long", serveLongString);
    server.on("/short", serveShortString);
    server.begin();
}

void loop() {
    server.handleClient();
}

It serves a short message on /short and a long message (3000 chars) on /long.

The /short page works everywhere: Windows, Desktop Linux (Fedora) and Android.
The /long page, on the other hand, only works on Windows and most of the time on desktop Linux. It never works on Android. I tried two phones.

I captured the network traffic on my Android phone using tPacketCapture. This is the result:

When trying to get /short, everything works fine. When trying to get /long, only the header comes through but the content never arrives. As I said, everything works fine on Windows and (most of the time) on Desktop Linux. Any idea what's going wrong?


texts: Writing a float to a BLE characteristic. What data format?

texts:
I am currently working on a python-based Bluetooth Low Energy client for OS X and I got stuck while trying to write a remote float characteristic value.

First of all: my setup is an Arduino 101 with integrated BLE module and a Macbook. On the Arduino side the code is working well, I can read and write BLE characteristic's from a BLE explorer app on my phone.

Also I did achieve to read out the characteristics float values in my python script on the Macbook. Yet I did not fully understand what exactly I am doing. After requesting the characteristic's value from the peripheral, the peripheral answers and I get what I think is binary data? I could manage to unpack the data to a float by using.

     def characteristic_to_float(data):
        float_value = struct.unpack('f', data)[0]
        return float_value

The received floats are correct. But I couldn't get my python code to properly write a float value to the peripheral. I tried this:

    a_number = 5.3

    def float_to_characteristic(float_value):
        val = struct.pack('<f', float_value)[0]
        return val

    characteristic_1.write_value(float_to_characteristic(a_number))

The python code itself will run through without an error, but the Arduino doesn't receive the data. I am sure of that, because I implemented a function on it that sends out a Serial print when a characteristic has been written.

Remember the characteristics are read & write and I could verify this by using my phone. I think I got something wrong with the struct.pack thing, since I can't find any information about what data format is needed...

Does someone know how I can pack or convert the float to the right data format? Unfortunately the lib I use (Adafruit BluefruitLE) does not have a documentation.

Thanks!


texts: How do I manipulate a large number of moving platforms?

texts:
I am trying to build a device that will allow me to control at least a couple hundred raising platforms. The goal of this is to create a real time editor for board games (Dungeons and Dragons).

Ideally:

All the platforms would move simultaneously
The platforms would be transparent to allow us to place LEDs inside them to color the platform so we can make colors like blue for water and brown for dirt.

In our current setup, we use some acrylic prisms that are 1 inch x 1 inch x 6 inch (width, length, height). We wanted to use a CNC motor like system to move something around and move a platform. Obviously, this can only raise/lower one item at a time. We calculated (on paper) quite a long update time (calculated approximately 1 sec per platform) to raise/lower a platform. A CNC linear drive type system is the only solution we found that had a reasonable cost/quality (a CNC motor for every platform also raised the power consumption very high). After a few weeks of looking around, planning and throwing stupid ideas away, we found this.

Clearly, it's way better then our idea but I have no idea how they did this. They have 900 platforms and they all work simultaneously. We also don't need real time interaction. Loading from computer and staying static until we change it is good (though water movement would be really nice).

What would you guys recommend to raise simultaneously a thousand small platforms?

After looking at this document that the devs made, and doing a bit more research I found that the device they used to move the platforms cost approxomently $30; I don't think I need to say this, but I don't have $27,000.

Key difference between their implementation and our goal:

No real-time interaction with the table. Controlled by an Arduino is fine.
Size of the platforms will be closer to 1 inch^2
All sides of the platform should be light up, but I believe this is mostly a question of choosing the right material


texts:
I'm using AT24C32 EEPROM chip from ATmel. I found code that will write and read bytes from chip.
Code writes and reads bytes correctly and without any problem.

But I have to write few 8-byte values often(every 10-15 seconds). I did "cut" those variables to 48 bit(so 6-byte variable) and with that I speeded up saving but it's still slow.

Is there any chance to speed up saving proccess? Code is below

void EEPROMClass::write48(int16_t address, uint64_t value)
{
    uint8_t byteValue = (value & 0xFF);
    write8(address, byteValue);

    byteValue = ((value >> 8) & 0xFF);
    write8(address + 1, byteValue);

    byteValue = ((value >> 16) & 0xFF);
    write8(address + 2, byteValue);

    byteValue = ((value >> 24) & 0xFF);
    write8(address + 3, byteValue);

    byteValue = ((value >> 32) & 0xFF);
    write8(address + 4, byteValue);

    byteValue = ((value >> 40) & 0xFF);
    write8(address + 5, byteValue);
}

void EEPROMClass::write8(int16_t const address, uint8_t const value)
{
    Wire.beginTransmission(AT24C32);

    Wire.write(highAddressByte(address));
    Wire.write(lowAddressByte(address));

    Wire.write(value);
    delay(2);
    Wire.endTransmission();
}

delay of 2ms is required otherwise EEPROM will write different value. Code has 4 "6-byte" variables(total of 24 bytes). Every byte is minimum 2ms, so total time to save only "6-byte" variables is 48ms(round to 50ms). That is too slow for me. How to speed up write function?


texts: Stm32 Blue Pill Internal reference voltage Arduino IDE

texts: I want to use the internal reference voltage (1.2V) of stm32f103 blue pill using Arduino IDE. I searched the whole internet but couldn't find anything. I need help with this. Thanks.


texts: How does one **get** attributes for SD files?

texts:
To be able to set the date and time of the files on my SD card I followed this answer: https://arduino.stackexchange.com/a/39127/49678

Now I am wondering How do I read the values out in the microcontroller?
To clearify, I get the correct timestamps when I remove the SD card and view them on a PC, but I also want to be able to read this on the microcontroller.

Inside SdFile.cpp on line 1025 there is a function called timestamp which is used to set the timestamp but I cant seem to find any function to read it.
https://github.com/adafruit/SD/blob/master/utility/SdFile.cpp

I would prefer a solution where I don't have to add it to the library myself.

The underlying problem I am facing is that I want to log files, and once the memory is full I which to remove the oldest files.


texts: Arduino to AtTiny change of pin interrupt behaviour?

texts:
I have a project which, to save on battery, is put to sleep until an interrupt pin is rising from LOW to HIGH.
This works well on Arduino Nano, however the translation doesn't on the ATTiny.
#include <avr/sleep.h>
void setup(){
    pinMode(2,INPUT);
    noInterrupts();
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    attachInterrupt(INT0,wakeUp,RISING);
    //Yadada
    Interrupts();
}
void wakeUp(){
   //Something Something
   sleep_mode();
}

Both on the Arduino Nano and the AtTiny, the interrupt Pin 0 is equivalent to Pin 2.

The Arduino is set to ISP
I have run the Bootloader (with internal clock as 8MHz if that makes a difference)
The program loads on the AtTiny45.

Yet, the interrupt pin does not interrupt.
Does the INT0 act differently on a ATTiny than on the Arduino, and if so, how can I wake up my AtTiny?


texts: Arduino hangs after less than a minute, but not on USB

texts:
I have arduino uno + ethernet shield + 9V/200mA adapter. I am trying to send some data with HTTP connection. When it's connected to USB it works perfectly, but when I plugged out USB, hangs (after less than a minute, it stops pinging).
I have tried this:
EthernetClient.cpp

int EthernetClient::connect(IPAddress ip, uint16_t port) {
  if (_sock != MAX_SOCK_NUM)
    return 0; // i changed to -1  as suggested on previous link

  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    uint8_t s = socketStatus(i);
    if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
      _sock = i;
      break;
    }
  }

and also example from library Examples-library-WebClientRepeating, but I get the same problem as in my code.
Is my adapter too weak?
This code is from Example WebClientRepeating:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED    };

// fill in your Domain Name Server address here:
IPAddress ip(193, 77, 60, 66);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(193, 77, 60, 7);
IPAddress myDns(193, 77, 60, 213);

EthernetClient client;

char server[] = "www.arduino.cc";
//IPAddress server(64,131,82,241);

unsigned long lastConnectionTime = 0; // last time you connected to the server, in millisecond
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers

void setup() {
  // start serial port:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // give the ethernet module time to boot up:
  delay(1000);
  // start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac, ip, myDns, gateway, subnet);

  // print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if ten seconds have passed since your last connection, then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }
}

// this method makes a HTTP connection to the server:
void httpRequest() {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.println("GET /latest.txt HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

EDIT 1:
Also when I plug USB in its start working with 9V power adapter.


texts: Arduino and HC-05 hardware serial issues

texts:
I have a software sending bitmap data to an Arduino Pro 5V 16MHz 328P that drives an LED display (sketch). This works using the USB-Serial adapter for the Arduino Pro with baud rates up to 500000 Baud. Now I wanted to switch to Bluetooth...
I tried connecting a 5V HC-05 module (set to 230400 Baud 8N1) to the hardware RX/TX pins on the Arduino Pro (Pins 0/1) and connect the PC to the Bluetooth serial port wirelessly (e.g. /dev/rfcomm0 on Linux). My problem is that I can receive data on the PC side using a terminal (the 'Ada' string is received), but nothing is displayed on the LED display. I have tried connecting an oscilloscope to the RX/TX pins on the Arduino and Data is arriving from the HC-05 module TX pin to the Arduino RX pin.
When the USB-Serial adapter is connected to the same pins (0/1 instead of the regular pin header) it still works as before, so there should be no connection issues.
What I tried was adding a 5kOhm resistor from the Arduino RX line to ground. (I found this hint somewhere here), but no dice...
I'm not sure what's wrong, because communication IS working over the USB-Serial adapter. Any ideas on what to try?!


texts:
When using a digital pin as input, one has the option of using the internal arduino resistor, which is connected to VCC; that is setting the digital pin as INPUT_PULLUP, and then the pin reads HIGH. Does this uses electricity?.

I mean the resistor is connected directly to VCC and I presume electricity is constantly flowing through the system, no?.
as oppose to having the pin as just INPUT?


texts: Arduino Uno power input - is 5 V at 1 A enough?

texts:
I have a Arduino Uno board and phone power bank

Power bank details

Capacity - 8000 mWh
Input  - DC 5 V and 1 A
Output - DC 5 V and 1 A

Can I give the power to Arduino Uno using this power bank, through the Arduino Uno USB?


texts: How to use an PCF8574P with the simplest code possible

texts: i'm having few PCF8574P which i want to use with my arduino and multiplex them however i have no idea how to use the I2C BUS and the IC in general. There are few libraries but they're fairly complex. Is there any library which makes writing and reading from the PCF8574P easy?


texts: Is it possible for Arduino as ISP board to flash an ISP master board?

texts:
I have a setup of 2 Arduino Leonardo boards. Let's refer to them as Board A and Board B.
Board A is a master SPI board that is constantly communicating via SPI to an array of sensors. At some point, board A will need to be flashed with a new sketch.  That's where Board B comes in.
I want to use Board B go use an Arduino as ISP sketch to go and flash a new sketch onto board A. Problem is that Arduino as ISP uses SPI, which conflicts with the code on board B since board B is a master device communicating to other sensors via SPI.
Is it possible for board B to flash board A via ISP?


texts:
I am making a small project, and for that, I need to measure the time between 2 inputs.
basically, a program to measure the time elapsed from when digital pin 2 is high to when it again becomes high.


texts: Using Atmel Studio with Arduino Starter Kit (Uno MCU)

texts:
Can someone tell me if it's possible AND safe to use Atmel Studio with Arduino Starter Kit?  I'm a newbie to firmware in general and I don't want to "brick" my Arduino Uno Microcontroller.  I don't quite know if the micro controller has been programmed in read only or special memory to make it Arduino compatible and me messing with Atmel Studio could mess it up.  In other words, I want to know I can get back to programming through the Arduino IDE and continue working on the projects in the starter kit book.  I've done about half of them.

1)  Can someone tell me if it's doable, safe and WHY?
2)  Any hints or gotchas or examples on how to do it?

My motivation is that I'm taking a job as a C# Windows programmer but will be exposed (I believe) to AVR and Atmel Studio and wanted to get familiar with it by just playing a little bit.  Arduino libraries seems to hide a lot of the messy details (such as setting a pin output) which is fine, but it would probably be good to do those messy details myself and be familiar with the actual tools they will use at work.

I have searched for a "tutorial for dummies" that says what settings to pick, etc. to no avail.

Thanks Dave

P.S.  If the answer is NO WAY is it safe or desirable, perhaps a recommendation for an AVR development kit (cheaper is better!).  Actually, this is probably not a bad idea anyhow.
Many Thanks!


texts:
I have searched everywhere, but can you please help me to get this Byte into int, there are alot of examples on the internet, but not for a beginer like me

CODE:

int Button[] = {2, 4, 7 };

byte E = sizeof(Button);

int I = (int) E;

void setup() {

  Serial.begin(9600);

  Serial.print (I); // has to be 3, currently 61

  }

void loop() {

 }

I don't know why the byte E doen't convert to a int in int I by using the  (int)E command, what would also be convinient would be to read the amount of elements directly  as an int .
(you might wonder, why I want to do this, it is beacause, I am writing a program with multiple buttons, so I just want to add another pin to the array and not have to change the "I" int( the I int is used for loops))


texts:
I have Arduino UNO with 0.96" OLED display with 128(width)*32(height). It is said that I have to edit Adafruit_SSD1306.h for my 128*32 OLED, okey I did it from 128*64 to 128*32 but I still get the compiler error:

ssd1306_128x32_i2c.ino:54:2: error: #error ("Height incorrect, please
fix Adafruit_SSD1306.h!");

Yes, I fixed the Adafruit_SSD1306.h file, but now, it is still gives me a compiler error:

C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h: In member
function 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t, uint8_t)':
C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h:47: error:
too many arguments to function 'uint8_t twi_readFrom(uint8_t,
uint8_t*, uint8_t)'
C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:85: error: at
this point in file
C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h: In member
function 'uint8_t TwoWire::endTransmission(uint8_t)':
C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h:48: error:
too many arguments to function 'uint8_t twi_writeTo(uint8_t, uint8_t*,
uint8_t, uint8_t)'
C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:140: error: at
this point in file
C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp: In member
function 'virtual size_t TwoWire::write(const uint8_t*, size_t)':
C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:195: error:
invalid conversion from 'const uint8_t*' to 'uint8_t*'
C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:195: error:
initializing argument 1 of 'uint8_t twi_transmit(uint8_t*, uint8_t)'

How can I use my four-pin OLED display with no errors?


texts:
RS-485 and RS-232 are a type of communication protocol or a type and cable?

I studying these serial communication protocols and each place refers to the RS-232 / RS-485 in different ways. Some articles mention that it is a cable, the other a protocol, so I was in doubt.


texts: Why delay of more than 64 millisecond stops the servo motor from rotating? I am not using "Servo.h" instead i am just managing the length of pulse

texts:
The code I used was this
int servo = 5;
int angle;

void setup() {

  pinMode(servo, OUTPUT);

}

void loop() {

  for (angle = 0;angle<180;angle++){

    digitalWrite(servo, HIGH);
    delayMicroseconds((angle*(11))+365);
    digitalWrite(servo,LOW);
    delay(65);
  }

  for (angle = 179;angle>0;angle--){

    digitalWrite(servo, HIGH);
    delayMicroseconds((angle*(11))+650);
    digitalWrite(servo,LOW);
    delay(65);

}
}

as u can see I have set the delay after a particular step to be 65 milliseconds but it won't work, any delay greater than 64 milliseconds do not work and the motor just stops rotating.
what is the reason for this??


texts:
I want to test around with my ESP32 and an E-Paper display - yet i am stuck at uploading sketches via Arduino IDE. I get those kind of errors:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x48

and looking into tools,i dont even see my board there - i bought it on amazon and the article just says "ILS - LOLIN32 Lite V1.0.0 Wifi and Bluetooth Board with ESP-32 Rev1 MicroPython 4MB FLASH".

What am i missing here? I am 99% sure i got the pins correct (finally), i got the USB-Serial driver, i got the right port - yet even a simple test sketch i found on the internet didnt work.


texts: How do I connect my Luxorparts keypad to my Arduino?

texts: I just bought a 12 digit keypad from Luxorparts and it doesn't come with any schematics showing how it's wired at all. How do I figure out how to connect it to my Arduino?


texts:
Hello I have a programme that loads a piece of text from a file. In this case it loads "drawrect(4,10,20,20);" from the txt file and stores it in a string. I then use substrings to change the string into just "4,10,20,20" which is good but I need to simplify it down even more to four strings each with one of those 4 numbers in it.

Currently I use:

void drawRectMethod(String s){
  String var1,var2,var3,var4;
  s = s.substring(s.indexOf('(') + 1);
  s = s.substring(0, s.lastIndexOf(')'));
  Serial.println(s);
}

to simplify the string down to "4,10,20,20" but this wont work to store each number in a separate string. How can I can I store each variable in a separate string. The numbers will be stored in var1 - var4.


texts:
I've a low power consumption regulator to get 3.3V from two 1.5V batteries.
I'm going to use it for powering an arduino MKR (MKRFOX1200), so my question is where I should connect it, to the battery connector or directly to VCC.

Looking at schematics it's not clear to me which is the best option in terms of power saving, as VCC seems better but I don't know if it's ok to use that pin to give power


texts:
How can I generate this pulse with an Arduino Micro?

Is it necessary an external component?


texts:
I'm new to this Arduino programming. So I want to ask about my current project. My lecturer told me to make a temperature sensor using an LM35, where a green LED will light up when below some certain temperature that I set. The same goes for yellow and red LEDs for medium, and high temperatures. The tricky part here is that I need to make sure my buzzer (piezo) is on forever if it reaches the high temperature, until I press a button to reset it.

This is my coding so far:

const int greenLed = 3;
const int redLed = 4;
const int yellowLed = 5;
float tempC;
int reading;
int tempPin = 0;
int speakerOut = 11;
const int buttonPin = 2;
int buttonState = 0;
long duration = 10000;
int tempo = 0;

void setup() {
// initialize digital pin 13 as an output.
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
pinMode(11, OUTPUT);
analogReference(INTERNAL);
Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
buttonState = digitalRead(buttonPin);
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.println(tempC);
delay(500);

if (tempC < 30.00) {
//Serial.println("Temp LOW");
digitalWrite(3, HIGH);
delay(10);
}else {
digitalWrite(3,LOW);
delay(10);

}

if (31.00 < tempC < 33){
//Serial.println("Temp MED");
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(50);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(50);

}else {
digitalWrite(4,LOW);
digitalWrite(5,LOW);

}

if(tempC >= 34){
**WHAT SHOULD I FILL UP HERE TO MAKE SURE MY PIEZO BUZZER ON FOREVER**
}
if(buttonState = 1);{
digitalWrite(11, LOW);
}

}

Any help would be great. Or if you have a better idea on how to do this, I'm gonna love it.


texts: How to send data from firebase php to arduino?

texts:
In the project I am working on

  I want to send data to firebase going to arduino this specifically by
  sending an information to change the wifi

SSID

password

  materials I used:

esp8266-01

arduino uno r3

firebase

web server (000webhost)

  code for arduino

    #include <SoftwareSerial.h>
#include <DHT.h>;
SoftwareSerial Serial1(10, 11);
#define Trash "Trash3"
#define DHTTYPE DHT11
#define DHTPIN 2
#define TRIGGER_PIN 4
#define ECHO_PIN 3

DHT dht(DHTPIN, DHTTYPE, 11);

float humidity, temp_f;
int distance;
long duration;

String buff(64);
String getStr(128);

void setup() {

  Serial.begin(9600);

  Serial1.begin(9600);
  //Serial1.resetESP();
  delay(2000);
  Serial1.setTimeout(5000);

  dht.begin();
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);

  if (!connectWiFi()) {
    Serial.println("Can not connect to the WiFi.");
    while (true)
      ; // do nothing
  }
  Serial.println("OK, Connected to WiFi.");

  sendCommand("AT+CIPSTA?");
  //sendCommand("AT+CIPDNS_CUR?");
  sendCommand("AT+CIPSTAMAC?");

}

void loop() {

  temp_f = dht.readTemperature();
  humidity = dht.readHumidity();
  digitalWrite(TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN, LOW);

  duration = pulseIn(ECHO_PIN, HIGH);
  distance = duration * 0.034 / 2;

  // connect to server
  if (sendCommand("AT+CIPSTART=\"TCP\",\"gg.com\",80")) {
    Serial.println("connected to Cloud");

    // build HTTP request
    getStr = "GET /upload.php?trash=";
    getStr += Trash;
    getStr += "&distance=";
    getStr += distance;
    getStr += "&temp_f=";
    getStr += temp_f;
    getStr += "&humidity=";
    getStr += humidity;
    getStr += " HTTP/1.1\r\n";
    getStr += "Host: gg.com\r\n\r\n";

    // open send buffer
    buff = "AT+CIPSEND=";
    buff += getStr.length();
    if (sendCommand(buff.c_str()) && Serial1.find(">")) { // AT firmware is ready to accept data

      // send HTTP request
      Serial.println(getStr);
      Serial1.print(getStr);

      // print HTTP response
      if (Serial1.find("+IPD,")) { // response received
        int l = Serial1.parseInt();
        while (l > 0) {
          if (Serial1.available()) {
            Serial.write(Serial1.read());
            l--;
          }
        }
        Serial.println("--------------");
      } else {
        Serial.println("no response");
      }
    } else {
      Serial.println("send error");
    }
    sendCommand("AT+CIPCLOSE");
  } else {
    Serial.println("Error connecting");
  }
}

bool connectWiFi() {

  if (!sendCommand("ATE0")) // echo off
    return false;
  if (!sendCommand("AT+CIPMUX=0")) // set single connection mode
    return false;
  if (!sendCommand("AT+CWMODE=1")) // set STA mode
    return false;
  return sendCommand("AT+CWJAP=\"CAPSTONE\",\"capstonemis\"");
}

bool sendCommand(const char* cmd) {
  Serial.println(cmd);
  Serial1.println(cmd);
  while (true) {
    buff = Serial1.readStringUntil('\n');
    buff.trim();
    if (buff.length() > 0) {
      Serial.println(buff);
      if (buff == "OK" || buff == "SEND OK" || buff == "ALREADY CONNECTED")
        return true;
      if (buff == "ERROR" || buff == "FAIL" || buff == "SEND FAIL")
        return false;
    }
  }
}

  code for firebase

<?php

require 'firebaseLib.php';
$Trash = $_GET["trash"];

$Distance = $_GET["distance"];
$Temperature = $_GET["temp_f"];
$Humidity= $_GET["humidity"];

// --- This is your Firebase URL
$baseURI = 'https://thesis1-69.firebaseio.com';
// --- Use your token from Firebase here
$token = 'gg';
// --- Here is your parameter from the http GET

$devicestatus= array('Distance' => $Distance,'Temperature' => $Temperature,'Humidity' => $Humidity);

$firebasePath = '/thesis1-69/';

$full= array($Trash => $devicestatus);

/// --- Making calls
$fb = new Firebase($baseURI, $token);
$fb -> update($firebasePath, $full);

?>

any  guide and help can help me a lot
thank you so much :)


texts: I am working on an Arduino project where I need more digital and analofgpins than the Uno offers. I was wondering how to hook up multiple Arduinos (4) together so I can use their digital and analog pins. Thanks in advance.


texts:
I'm trying to get a ESP8266 board with 2x4 pins to work. I'm connecting it to an Olimexino 32u4 (Leonardo-compatible), configured to use 3.3V. This simple snippet I use to transfer everything to the PC (CH_PD is connected to D8, /RST to D9):

void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  delay(2000);
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(115200);
  delay(10000);
  digitalWrite(9, HIGH);
  digitalWrite(8, HIGH);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte);
  }
}

When launching, I see following output:

<"random" bytes>
Ai-Thinker Technology Co. Ltd.

invalid

Performing a reset shows more:

AT+RST

OK

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 1396, room 16
tail 4
chksum 0x89
load 0x3ffe8000, len 776, room 4
tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4
tail 8
chksum 0xc0
csum 0xc0

2nd boot version : 1.4(b1)
  SPI Speed      : 40MHz
  SPI Mode       : QIO
  SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000

ŒÂÕ�MEM CHECK FAIL!!!
äsl�‚rô
Ai-Thinker Technology Co. Ltd.

invalid

The mode is set to station:

AT+CWMODE?

+CWMODE:1

OK

Listing the access points works fine:

AT+CWLAP

+CWLAP:(3,"ap-1",-91,"01:23:45:67:89:ab",1)
+CWLAP:(3,"ap-2",-88,"cd:ef:01:23:45:67",2)
+CWLAP:(3,"ap-3",-74,"89:ab:cd:ef:01:23",11)

OK

But logging in to my Fritzbox router fails (WPA2):

AT+CWJAP="ap-2","mypassword"
WIFI CONNECTED
+CWJAP:1

FAIL
WIFI DISCONNECT

First I thought the reason is the low signal, but even moving directly beside the Fritzbox shows the same result (though with higher signal value in AT+CWLAP).

I've tried nearly everything, e.g. AT+CWMODE=3, AT+RST, AT+RESTORE). Nothing changes. When using a wrong password, I'm getting no "WIFI CONNECTED" messages at all.

Could it be a power problem (that the Olimexino can't provide up to 200mA at the 3.3V line?

Connecting from my smartphone to the ESP8266 in one of its access point modes (2 or 3) works fine. If there were power problems, wouldn't then the access point mode fails as well?


texts: How to tell what components are compatible with Arduino Due?

texts:
I am interested in using the Arduino Due in an upcoming project, however I am worried that the other shields/components that I need will not be compatible with it, because, according to that link:

  The Due is compatible with all Arduino shields that work at 3.3V and are compliant with the 1.0 Arduino pinout.

The components I need to use are:

NightShade Electronics energyShield
Solar Panel
Servo Motors

Essentially a solar panel will power the energyShield (rechargeable battery), which in turn will power multiple servo motors.

I cannot tell if the energyShield uses the 1.0 pinout or not. I am also worried that since the the solar power generates 6V it will overload the energyShield which is rated at 3.3V. At the same time, I am worried that the servo motors, which seem to require 4.8V, will not be capable of being powered by the energyShield which outputs 3.3V. Thoughts?

Bonus Points if someone can explain to me what the "1.0 Pinout" is, and whether it is the latest/most modern pinout available for Arduinos.


texts: Arduino Due uploading error using Eclipse plugin "avrdude: stk500_recv(): programmer is not responding"

texts:
I have a Arduino Due that I'm trying to upload a sketch to. I follow the tutorial http://playground.arduino.cc/Code/Eclipse to get the board running with the Eclipse plugin.

However uploading the sketch gives me the error

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

If I use the Arduino IDE everthing works fine. I'm using Eclipse mars with Arduino 1.6.5

What could have gone wrong?


texts: Why does my lcd screen work fine and then display random characters?

texts:
It works as expected for a few seconds and then random letters appear on the second row. The wiring and the programming should be correct. I wired it according to an Arduino Starter Kit Book and coded it myself.

Code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int hours=23;
int minutes=0;
String none="00";
unsigned long timer;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(6, 0);
lcd.print("Time:");
lcd.setCursor(6, 1);
lcd.print("23:00");
}

void loop() {
timer=millis();
if(timer%600==0){
   minutes++;
  if(minutes==60){
      minutes=0;
      hours++;
      }
   if(hours==24){
      hours=0;
   }
  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("Time:");
  lcd.setCursor(6, 1);
  if(minutes<10){
    if(hours<10){
      lcd.print(String("0")+hours+":"+"0"+minutes);
    }
    else{
      lcd.print(hours+String(":")+"0"+minutes);
    }
  }
  else{
    if(hours<10){
       lcd.print(String("0")+hours+":"+minutes);
    }
    else{
       lcd.print(hours+":"+minutes);
    }

  }
  delay(200);
  }
}

I was able to narrow down the problem. I was testing what happens when it hits 24 hours so I set hours to 23 in the beginning and made the time 600 ms. Once it hits 10 seconds, the characters appear. If the hour is a 2 digit number, the issue happens. I made the hours 9, and the issue disappeared. What can I do?


texts:
I am junior high teacher teaching students how to program using Arduino. I know the basics of programing but the students wanted to program a game which is a little above my skill set. I am using the following sketch (http://www.itopen.it/arduino-pong-with-8x8-led-matrix-and-max7219/) to introduce them to programing games. Thanks to this site I understand most of the code. However I would like to add a line of code that will make a piezo buzzer buzz every time the "ball" hits the pad. I think the code should look something like the code bellow, but I am not sure if it is correct or where I would put it.

#define buz 8 // number of pin buzzer connected to
     if (HIT_CENTER || HIT_RIGHT || HIT_LEFT) {
        digitalWrite(buz, HIGH);
        delay(100);
        digiralWrite(buz, LOW);
        }

Any help would be appreciated.


texts: Rasberry Pi Controlling Arduino - Reads "Ghost" Input - Doesn't Complete Logic Loop

texts:
I am using an Arduino Atmega2560 clone, I have used it many times before with satisfactory results - although I haven't used it with my Rpi before.
My Raspberry Pi is model 4 (B I think?).
#define knap 49
#define motorOutput 8

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(knap, INPUT);
  pinMode(motorOutput, OUTPUT);
  digitalWrite(motorOutput, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  int knapSensor = digitalRead(knap);
  Serial.print(knapSensor);
  if (knapSensor == 1) {
    int knapSensor = digitalRead(knap);
    Serial.print("aktiveret");
    digitalWrite(motorOutput, HIGH);
    delay(500);
    digitalWrite(motorOutput, LOW);
  }
}

Now I have double checked, the motor and the button is wired correctly. There is no hardware issue, aside from the cables being sh- quality.
Problem is, whenever I run this program two things will happen;
Either it starts fine by displaying "0000..." on the serial monitor.
Then when I press the button it goes to
"AktiveretAktiveretAktiveret..." even when I depress the button.
Or, it will just display "AktiveretAktiveretAktiveret...".
In either case the motor won't work.
Once again, I have done tests where I have removed the power from the breadboard and replaced the voltage pin for the motor with the voltage pin leading from the button.
First thing didn't change the input (i.e still "AktiveretAktiveret,") the latter started the motor.
I.e this isn't about bad wiring.
EDIT:
Added schematics and changed the code


texts: ATtiny85 (Digispark) with 433mhz RF transmitter not working

texts:
I have the following components:

ATtiny85 Digispark
433mhz Mini Low Power RF Transmitter

I got a communication flow transmit/receive working between two Wemos D1 and like to outsource the transmitting part now to a ATtiny85. I used the same code as for the Wemos:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  pinMode(1, OUTPUT);
  mySwitch.enableTransmit(2);
}

void loop() {
    mySwitch.send("000110110001010100010001");
    digitalWrite(1, HIGH);
    delay(250);
    digitalWrite(1, LOW);
    delay(250);
}

But the serial monitor for the Wemos does not receive any communication. I went so far that I built up the communication between the two Wemos again and connected only the data pin of the transmitter to the ATtiny85 in order to exclude any voltage problems (ATtiny gets 5V, transmitter likes <3.6V).

Now I am out of ideas. How can I debug the problem or what else can I try?

Requested setup:


texts:
We have worked with a company to design a custom board based on the Arduino Zero and have also had them do some programming for us.

In doing so, they have had to modify the following Arduino core libraries:  variant.cpp, variant.h and wiring_analog.c.

Unfortunately, this causes problems with other projects using Arduino.

Is there a way to keep these libraries local to specific projects without modifying the original files?


texts:
I was wondering if I could use a IR sensor with my Arduino to detect if someone is present in front of it.

Like, the emitter should emit continuously and if the receiver drop connection it should do something.

Will this work fine? or the emitter wide angle and a human body in front of it wont drop the signal?


texts:
I'd like to disable the trinket 10-second bootloader when powered up, so it will just begin running the program. I would still like to be able to press the reset button to re-program it.

I found an edited version of the bootloader here. Currently, I am using an Arduino Uno and the 'repair the bootloader' sketch to load the hex to the trinket. The default hex is hard coded in the images.cpp file and the same hex is included in the Adafruit bootloader GitHub as trinketgemma_v1.hex.

How can I compile the forked copy to get the final compiled hex that can be burnt into the trinket?

Update:

I get this error when I upload to the board, how did you flash yours?

Setting fuses  Set Low Fuse to: F1 -> A000  Set High Fuse to: D5 -> A800  Set Ext Fuse to: 6 -> A400
Verifying fuses...
    Low Fuse: 0xF1 is 0xF1
    High Fuse: 0xD5 is 0xD5
    Ext Fuse: 0x6 is 0x6

Setting fuses

Verifying flash...
verification error at address 0x14C0 Should be 0x33 not 0x5F
Failed to verify chip

The fuses are set correctly, but it cannot verify the flash. The supplied Adafruit hex looks like about 93 lines of:

":2000000093CA15C0EBCA13C012C011C010C00FC00EC00DC00CC00BC00AC009C008C0112422\n"

Where the updated, compiled hex is about 181 lines of:

":100000005FCA5FCA5FCA5FCA5FCA5FCA5FCA5FCAA8\n"

Does the length of each line matter? The output of a successful flash looks like:

Verifying fuses...
    Low Fuse: 0xF1 is 0xF1
    High Fuse: 0xD5 is 0xD5
    Ext Fuse: 0x6 is 0x6

Setting fuses

Verifying flash...
    Flash verified correctly!
Verifying fuses...

Fuses verified correctly!
*OK!*


texts: Connecting to WiFi on ESP32 using credentials from SD card

texts:
I'd like to use an SD card to provide the login credentials to an ESP32. I've already got the ESP32 reading the relative data from the SD card and storing it as a char array on the ESP, but when I use those arrays in the WiFi.begin function it never connects.

Is this something to do with the way arrays work or am I doing something else wrong?

Respective code:

if (dataFile) {
Serial.println("File is available");
while (dataFile.available()) {
  byte currbyte = dataFile.read();
  if (currbyte == 58) {
    reading = 1;    //Begin reading data
    i = 0;
  }
  while (reading == 1 and s == 0) {
    byte currbyte = dataFile.read();
    //Serial.print(currbyte);
    //Serial.println(char(currbyte));
    if (currbyte == 13) {
      s = 1;
      reading = 0 ;
    }
    ssid[i] = char(currbyte);
    i++;
    //Serial.println(ssid);
  }
  while (reading == 1 and s == 1) {
    byte currbyte = dataFile.read();
    //Serial.print(currbyte);
    //Serial.println(char(currbyte));
    if (currbyte == 13) {
      s = 2;
      reading = 0 ;
    }
    password[i] = char(currbyte);
    i++;
    //Serial.println(password);
  }
}
dataFile.close();
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED and count < 20) {
Serial.println("Connecting to WiFi..");
delay(1000);
count++;}


texts: How much ohm resistance I should put between tp120 base and uno?

texts:
I have set up solenoid on of based on soil moisture,
The solenoid is powered by 24 volts, so I power solenoid by 24 volt and Arduino uno by stepping down to 6 volt powering through Vin and gnd.

I have used resistance of 10k ohm but I have twice burnt em.
Not sure how should calculate resistance required of signal coming out from D6 pin to TP120 base !


texts: Understanding global variables on Arduino

texts:
I am rewriting a set of LED manipulation functions to be more object oriented, and I have found that, mysteriously, my global variable memory space has been over consumed, despite a reduction of the use of global variables.

I played around with a number of things, and found something curious.

Here is a fragment of a function that does not live in an object, and is called directly from loop():

Animation *getNewAnim(int index)
{
    switch(index)
    {
        case 0:
            return new RedClouds();
        case 1:
            return new TwoLayerClouds();
        case 2:
            return new LavaLamp1();
        case 3:
            return new Bubbles1();

        ...  (20 or so more cases)
     }

This is a function that lets me switch between display modes based on the value of index.  Only one of these objects is ever created at a given time; I delete the old one before calling this, so there will never be multiple instances in use simultaneously.

Now the curious thing is that if I remove a few of these return statements, collapsing the block into something like this:

Animation *getNewAnim(int index)
{
    switch(index)
    {
        case 0:
        case 1:
        case 2:
        case 3:
            return new Bubbles1();
}

The amount of global memory space used falls considerably.

My hypothesis is that the Arduino build environment is pre-allocating space for each of these objects in the global memory space before the program is even run, rather than doing so dynamically as needed.

Is my hypothesis correct?  And if so, is there any way to tell the build environment not to do this, as I'd rather use the same memory for my new object that was used by the old one.

To clarify: When I build I see this sort of output:

Sketch uses 6,550 bytes (21.3%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,167 bytes (57.0%) of dynamic memory, leaving 881 bytes for local variables. Maximum is 2,048 bytes.

When I refer to "global memory" I am referring to the Global variables number on that output.  I'll also note that when I compile with the second example, the program storage space reported also falls dramatically.

NEW HYPOTHESIS

Here is what I think may be going on.  When I omit the classes from the switch statement, the compiler seems to optimize them out of the codebase, which is what I expect, and is consistent with seeing the program storage space shrink.  Each class has a method that returns it's name.  This method contains an embedded string, and I now believe that this string is stored in the global variable space.  Therefore, if the class is included, more global variable space is consumed to hold the name, and if it is optimized out, less is consumed.  This theory is consistent with all the facts I have, and makes more sense than my previous hypothesis.


texts: Connecting Indicator LEDs to Arduino Pro Mini

texts:
I'm new to electronics and unsure whether my design below will work as intended. XBee Series 2 and Arduino Pro Mini 5V are used. There are 4 LEDs, each with the following roles:

LED1: Flicker when transferring data to XBee
LED2: Flicker when transferring data to Arduino
LED3: Turns on when XBee is powered on
LED4: Turns on when Arduino is powered on

Also, will it suffice to use 3.3V LEDs for LED1, LED2, LED3 and 5V LEDs for LED4?


texts:
Here is what I want to do or get it done (since I am not a embedded guy)...

create a prototype with Arduino to detect open window/door of my room using camera(image processing/object state detection)?
that prototype will take pictures of room door/window at certain interval and than using some algorithm to decide whether they are open or not and will sound an alarm if it is open.
prototype should work in dark as well
No false alarms
Form factor should be small (the final product should not be bigger than smoke detectors that we have it in our room)

My questions are..

Is it possible? :)
What all things I need to create a prototype?
Which camera should I use? Camera should be really small.
Are algorithms available to detect it?


texts: Can I use an Arduino and GSM breakout board for triangulation?

texts: IS there a way for me to use cell towers to triangulate my location with an Arduino Uno and GSM breakout board? if so how?


texts: How to print something when a character touches a character

texts:
I am making a stickman rush game, where it goes up and down and then there is a object that scrolls to the left. Whenever that stickman touches the object, it prints game over. However when the object is below the stickman, it prints game over even though its not touching. Can someone explain why this is happening?
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

byte customChar[] = {
  B01110,
  B01110,
  B01110,
  B00100,
  B01110,
  B10101,
  B00100,
  B01010
};

byte gameObstical[] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111
};

int vX = A0;
int vY = A1;
int sw = 8;

int xPosition = 0;
int yPosition = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;

int screenWidth = 16;
int screenHeight = 2;

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

  pinMode(vX, INPUT);
  pinMode(vY, INPUT);
  pinMode(sw, INPUT);

   lcd.begin(16, 2);
  lcd.createChar(0, customChar);
  lcd.home();
  lcd.write(byte(0));

  lcd.createChar(1, gameObstical);
  lcd.write(byte(1));

}

void loop() {

  int stickManPosition = 0;
  int obsticalPosition = 0;
  int stickManPosition2 = 0;
  int obsticalPosition2 = 0;

  for (obsticalPosition = 15; obsticalPosition >= 0; obsticalPosition--) {
  lcd.setCursor(obsticalPosition, 1);
  lcd.write(byte(1));
  lcd.print(" ");
  delay(150);

  xPosition = analogRead(vX);
  yPosition = analogRead(vY);
  SW_state = digitalRead(sw);
  mapX = map(xPosition, 20, 1003, -500, 500);

    Serial.println("-----------");
  Serial.println(mapX);
  Serial.println("-----------");

    if (mapX > 200) {

    lcd.clear();
    lcd.setCursor(stickManPosition, 0);
    lcd.write(byte(0));

  } else if (mapX < -200) {

    lcd.clear();
    lcd.setCursor(stickManPosition, 1);
    lcd.write(byte(0));
    }

  if (stickManPosition == obsticalPosition) {
    lcd.clear();
    lcd.print("Game Over.");
      } else if (
    }
  }

Any help would be great.


texts: if I add a .cpp file, Serial becomes unusable

texts:
I am using the mega 2560. When I just use .ino and .h files, if I use Serial, it works fine, without even using:
#include <SoftwareSerial.h>

However, when I add a .cpp file I start getting 2 errors, one is solved by adding the aforementioned include, the second one, after adding it, is :
'Serial' was not declared in this scope

I know I can declare it manually and use the RX/TX pins, but I would like to be able to use the default Serial so that I don't have to occupy more pins. Especially since it works file w/o the .cpp file. Can anyone explain to me why this happens? Is it because I specify a C++ file so the compiler changes?


texts: ULN2803 and common-anode RGB strip; how am I doing it wrong?

texts:
I'm not super-good with my electrical foo. But I've managed to get a ULN2803 wired up to give the +12v that my RGB LED strip needs. The strip has four connectors, RGB and common +12v.

My concern is that (I think) the Arduino is shorting out- while the Arduino processes my loop, the USB connection dies and the RX/TX LEDs light up.

Here's how I am wiring things. I'm currently powering the Arduino through USB, so when I say "power supply" I'm referring to the +12v supply I'm using.

power supply ground to Arduino ground, ULN2803 pin 9.
power supply +12v to 2803 pin 10, common +12v on LED strip.
arduino output pin 11 to 2803 pin 1
2803 pin 18 to green LED strip

So, that's my circuit. It works- the strip lights up. But again, I think it's wrong. How do I correct it?


texts: Arduino web server: redirect to mobile site on SD card?

texts:
Is there any way to have an Arduino web server redirect the client to a file on the SD card only if the client is using a mobile browser?

(My arduino server is already successfully serving pages on http://192.168.0.180, and successfully processes GET requests).

I was thinking of having this javascript code on the main page that's served by the arduino:

<script type="text/javascript">
  <!--
  if (screen.width <= 800) {
    window.location = "http://192.168.0.180?mobile";
  }
  //-->
</script>

My first thought was that maybe it's possible for the server to process that GET request and then serve a page from the SD card, instead of the regular page it serves.

Do you think this is possible, and how would you recommend to do it?


texts: SPP-C and HC-05 are they the same thing or something else?

texts:
I was actually thinking to buy a cheap HC-05 module while I was searching I found a similar (think so) module It say it is a replace for HC modules.

Is it compatible with Arduino Nano and will it work same as the HC-05 module ????


texts: Multiple nodes with the same receiving and transmitting address

texts:
I want to make a network with arduinos and nrf24l01 chips. The network will be like this:

1 master arduino
multiple (no specific number) slave nodes

I want all nodes to have the same receiving and the same transmitting address and the master arduino to understand which one send the message from the message itself.
For example:

Master:
Receiving: 0xABCDABCD71
Transmitting: 0xABCDABCD01

Slave 1
Receiving: 0xABCDABCD01
Transmitting: 0xABCDABCD71

Slave 2
Receiving: 0xABCDABCD01
Transmitting: 0xABCDABCD71

Slave 3
Receiving: 0xABCDABCD01
Transmitting: 0xABCDABCD71

Slave 4
Receiving: 0xABCDABCD01
Transmitting: 0xABCDABCD71

When master send a message, all nodes will receive it.
What I want to ask is :

Is that possible?
Will there be any problems?
Is there any other way so I can add more nodes in the future without changing the code?


texts:
I'm using the random() to generate random coordinates for coins in a simple game console. The problem here is that the random() function is not generating random numbers, since the coin is at the same coordinates every single time I upload it. I am using the Adafruit GFX library with the Adafruit 1.44" Color TFT LCD Display. Here is my code (sorry, it's kind of long).
//necessary libraries
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

//colors
#define BLACK    0x0000
#define BLUE     0x001F
#define RED      0xF800
#define GREEN    0x07E0
#define CYAN     0x07FF
#define MAGENTA  0xF81F
#define YELLOW   0xFFE0
#define WHITE    0xFFFF

//pins
#define TFT_CS  10
#define TFT_RST  9
#define TFT_DC   8

//joystick variables
const int VRxPin = A1;
const int VRyPin = A0;
const int SWPin  = 7;
bool mov = false;

//data read from joystick pins
int x = 0;
int y = 0;
int SW = 0;

// X and Y coords for entities
int playerx = 50;
int playery = 50;

long coinx;
long coiny;

//game variables
int score = 0;

//defining the tft class
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

//useful text function
void output(char *text, int x, int y, uint16_t color, bool wrap = 0){
  tft.setCursor(x, y);
  tft.setTextColor(color);
  tft.setTextWrap(wrap);
  tft.print(text);
}

//there is probably a better way to do this but im too lazy to find it
void num_output(int text, int x, int y, uint16_t color, bool wrap = 0){
  tft.setCursor(x, y);
  tft.setTextColor(color);
  tft.setTextWrap(wrap);
  tft.print(text);
}

//clears screen
void clear() {
  tft.fillScreen(BLACK);
}

//setup (lcd init & startup screen)
void setup() {
  Serial.begin(9600);
  pinMode(SWPin,INPUT_PULLUP);
  tft.initR(INITR_GREENTAB);

  long coinx = random(20, 100);
  long coiny = random(20, 100);

  clear();
  output("RAMBUTAN", 40, 60, RED);
  delay(1000);
  clear();
  tft.fillRect(playerx, playery, 5, 5, WHITE);
  tft.fillCircle(coinx, coiny, 5, YELLOW);
}

void loop() {
  //reads data from joystick pins every single tick
  int VRx = analogRead(VRxPin);
  int VRy = analogRead(VRyPin);
  int SW = digitalRead(SWPin);

  //converts joystick pin data into directions
  if (VRx > 250 && VRx < 750 && VRy > 250 && VRy < 750) {
    // middle
  } else if (VRx > 511.5 && VRy < 750 && VRy > 240) {
    // right
    playery -= 5;
    mov = true;
  } else if (VRx < 511.5 && VRy < 750 && VRy > 240) {
    // left
    playery += 5;
    mov = true;
  } else if (VRy > 511.5 && VRx < 750 && VRx > 240) {
    // up
    playerx += 5;
    mov = true;
  } else if (VRy < 511.5 && VRx < 750 && VRx > 240) {
    // down
    playerx -= 5;
    mov = true;
  } else {
    mov = false;
  }

  if (mov == true) {
    clear();
    tft.fillRect(playerx, playery, 5, 5, WHITE);
    num_output(score, 10, 10, WHITE);
    tft.fillCircle(coinx, coiny, 5, YELLOW);
    mov = false;
  }
  delay(100);
}


texts: The reason for signal not going back to LOW

texts:
I have written a simple Arduino sketch, that shall produce a clock signal.

Here is the code:

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

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(8,HIGH);
  delayMicroseconds(500);
  digitalWrite(8,LOW);
  delayMicroseconds(500);
}

Namely the pin 8 of Arduino Uno is periodicaly set to HIGH and LOW.

The output that I receive, for three different frequencies, is:

My question is: Why is falling edge not as sharp as rising edge? As can be noted, for high frequencies the signal wouldn't go to LOW after all.


texts: Test level shifter with Arduino and some data

texts:
Below is a reference to a logical level bi-directional converter (aka level shifter) I purchased on Ebay.  I've soldered the 12 pins (6 for each piece) to the level shifter so that it fits on my bread board.

http://www.ebay.com/itm/121868205078?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

This may sound trivial, but I'd like to troubleshoot the level shifter with communication both ways (Rx and Tx) to make sure it's working properly.  I've got a constant 4.85v (5V) going to the HV pin, and a constant regulated 3.24V (3.3V) going to the LV pin, along with ground to both GND pins.  Right now, I'm using pin0 (Rx) and pin1 (Tx) on the Arduino Mega 2560.

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

void loop() {
  delay(1000);
  Serial.println("Test");
}

How can I test this level shifter without any fancy components?  How could I write a program to toggle an LED both on LV1 and HV1 pins, by modifying the program above?  Please note, that even though the Arduino runs on 5V, I am not using the Arduino as my HV power source.

EDIT (per comment 3 by @Paul):

Test:

Burn blank sketch into Arduino
Connect 5V (Arduino 5V) to HV pin
Connect GND (Arduino GND) to GND pin on same side as HV pin
Connect 3.3V to LV pin
Connect GND (from 3.3V power source) to GND pin on same side as LV
pin
Connect Arduino Tx pin to channel 1 (HV1)
Connect Arduino Rx pin to channel 2 (HV2)
Short channel 1 to channel 2 with jumper wire

When all of this is connected, and I open the Serial Monitor on Arduino IDE, anything I type will echo back exactly what I typed.  And when I disconnect one of these jumpers, it doesn't echo back.  So it seems to work.


texts: Sending "Blink" to pin 12 is causing on-board led to blink?

texts:
I recently picked up an Uno clone and noticed that if pin 12 is set to an output and I run the Blink sketch on it, the built in led (supposedly connected to pin 13) blinks. It's not as bright as it is when I run it on pin 13, but nonetheless it blinks. If I run it on any other pin, nothing happens, which is the behavior I expected with pin 12.

Is this a common issue with arduino boards, the microcontrollers, etc. or did I get a bad board?

Overall the board visibly appears to have solid construction and appears as the one on the site that I linked to.

Lastly as a side note, I'm currently living in India and won't have a problem going back to their factory for a replacement, if it is a bad board. They include a 6 month warranty.

int ledPin = 12;
int delayPeriod = 100;

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

void loop()
{
  digitalWrite(ledPin, HIGH);
  delay(delayPeriod);
  digitalWrite(ledPin,LOW);
  delay(delayPeriod);
  delayPeriod = delayPeriod + 100;
}


texts: No headers (.h) found in Documents\Arduino\libraries\arduino_144469 with demo code

texts:
I followed this tutorial for a demo code for the SR04 ultrasonic distance sensor (without the LCD display). I've installed the Arduino IDE and wrote the code in it and saved it in some location. Compilation of the code is successful. However when I try to upload the code, I get the message:

Invalid library found in C:\Users\Dame\Documents\Arduino\libraries\arduino_144469: no headers files (.h) found in C:\Users\Dame\Documents\Arduino\libraries\arduino_144469

There are no header files in the directory and I'm wondering if I need to download additional header files or if I should configure something else.


texts: Cannot obtain reading from meter (Modbus)

texts:
I have a system in which I am taking readings from a meter and processing it through an Arduino Nano. My code looks as follows:

#include <SoftwareSerial.h>

#define SerialControl 7
#define RS485Tx HIGH
#define RS485Rx LOW

SoftwareSerial RS485Serial(11, 12);
uint8_t window[8]; // Initialising window of 8 bytes

byte SendKWh[] = { 0x01, 0x03, 0x40, 0x34, 0x00, 0x02, 0x90, 0x05 };

// 0x01: Meter Address, 0x03: Read Function Code, 0x40: Register Address Variable (Start address high bit)
// 0x34: Register Address Variable (Start address low bit)
// 0x00: Register Quantity (High Bit), 0x02: Register Quantity (Low Bit)
// 0x90: CRC check code (CRC code Low bit)
// 0x05: CRC check code (CRC code High bit)

void dumpWin() {
  for (int i = 0; i < 8; i++) {
    Serial.print(window[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

void ReadRx() {
  // Sliding Window Implementation for reading data
  if(RS485Serial.available()) {
    uint8_t b = RS485Serial.read();
    dumpWin();
    // Slide the contents of the array down
    for (uint8_t i = 0; i < 7; i++) {
      window[i] = window[i+1];
    }
    window[7] = b; // Next frame inserted at the top of previous
    if ((window[0] == 0x01) && (window[1] == 0x03) &&
      (window[2] == 0x40) && (window[3] == 0x34)) {
      // Doing something with window[4] and window[5] here
    }
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(SerialControl, OUTPUT);
  RS485Serial.begin(9600);
}

void loop() {
  static uint32_t ts = millis();
  if (millis() - ts >= 2000) {
    ts = millis();
    digitalWrite(SerialControl, RS485Tx);
    RS485Serial.write(SendKWh, sizeof(SendKWh));
    RS485Serial.flush();
    digitalWrite(SerialControl, RS485Rx);
    RS485Serial.listen();
  }
  ReadRx();
}

The ReadRx() is behaving odd and dumpWin() is giving 0 0 0 0 0 0 0 0 output. I have been trying but I'm not able to figure out where am I going wrong. Your help is appreciated!

EDIT 2: I changed the code as suggested by @Majenko but still window[] O/P is 0 for all. I am not able to understand as to why it is not able to read the values from RS485Serial.


texts: On my lcd my characters collide, how can i remove one(because of the programming)

texts:
My code means that when i press a button it displays a word, but by default words are already there and i need to get rid of those default words.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);

int buttonApin = 4;

void setup() {
 pinMode(buttonApin, INPUT_PULLUP);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Mission Control ");
}

void loop()
{
  if (digitalRead(buttonApin) == LOW)
  {
    lcd.setCursor(0, 1);
    lcd.print("Test");
  }

  lcd.setCursor(0, 1);

lcd.print("launch in ");
lcd.print(millis()/1000);


texts: Some questions about a RGB LED Strip project that Im planning to do

texts:
Good day all

So Im in the planning and research phase of a new project that I want to start for my car. I want to control a bunch of RGB LED strips independently from each other via a micro controller, preferably Arduino  of courese, with a breakout board or something. I am going to run this system off the car battery so the current shouldn't be an issue, I hope, but prolonged usage will most likely drain the battery quite quickly. The strips I want to control are of the following lengths:

6 x 30cm Pieces
3 x 2m Pieces

So I want to be able to control all of them individually as well as the colour and brightness individually. So here are my questions:

Is there a board that the arduino can talk to that has 27 PWM outputs?
Can one maybe use normal outputs and just HIGH Low them quickly in sequence and use an arduino MEGA?
What would the current draw be if all the colours are on full on all strips? Would  it rather be better to blink them in sequence,rather than full on, and lose some brightness to reduce current draw?
Could multiplexing here be an alternative to controlling them individually? Maybe get it so I switch all the Positive outs of the LEDs, and the connect the 3 colours together. So in that case I would have 3 + 9 outputs?
Would addressable LEDs actually work better?

If you could refer to me to similar projects so I can sniff around there that would be greatly appreciated. So far Im just trying to wrap my head around all the aspects of the project. And yes I know that I wil not be able to use this while Im on public roads, its just for show.... So not sure what the legal aspects there are... :P


texts: Error: `nullptr` was not declared in this scope. Arduino IDE

texts:
I try to use this ArduinoThread library. In the Arduino I go Sketch->Import Library->ArduinoThread. After that I have the following line in the beginning of the sketch:
#include <ThreadController.h>
#include <Thread.h>
#include <StaticThreadController.h>

I leave setup() and loop() empty and try to verify or upload the sketch on my Arduino board. But I get the following errors:

Is this about the library or I do something wrong?


texts: Low Power library messing up serial text

texts:
I noticed something unusual using the Low Power library today.
When printing text in the loop and using LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); to sleep for one second, all the text in the loop gets messed up in the Serial Monitor as if you chose the wrong baud rate.

Example code:

#include "LowPower.h"

void setup() {
  Serial.begin(9600);
  Serial.println(F("HELLO"));
  Serial.println(F("HELLO"));
}

void loop() {
  Serial.println(F("HELLO"));
  LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
}

This code just prints

����11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=

even when using different baud rates. (I used the same baud rate on both the arduino and the monitor).
Replacing the low power command with delay(1000); works fine


texts:
I'm trying to transfer data from ESP8266(NodeMCU ESP12E) to my laptop. I'm coding ESP using Arduino IDE. I am able to receive correct packets (each containing 400 bytes) on a visual basic console program. However, to see whether the transmission is continuous or not, I have toggled an output pin whenever UDP.endpacket() returns 1. I observed waveforms on DSO. I found that UDP.endpacket() does NOT return 1 many times and the there is no transmission from ESP for a significant amount of time (milliseconds). Refer attached waveforms.

Why does UDP.endpacket() return 0 for such long time? Why is UDP transmission getting interrupted? How can I solve this? Please feel free to ask for more details if necessary.

Code :

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "Connectify-me33";
const char* password = "donfour276";

WiFiUDP Udp;
unsigned int localUdpPort = 65000;

unsigned int dest_port = 11000;

unsigned char clientBuf[400];
int clientBuf_len=0;

#define test_pin 5

int return_udp_fcn = 0;

void setup()
{

  WiFi.begin(ssid, password);
  delay(5000);

  Udp.begin(localUdpPort);

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

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);

}

void loop()
{
        digitalWrite(test_pin, HIGH);

        //filling up buffer
        for(clientBuf_len = 0; clientBuf_len<=399; clientBuf_len++)
        {
            clientBuf[clientBuf_len] = 0x7E;
        }

        //UDP transmit
        Udp.beginPacket("172.22.0.1", dest_port);
        Udp.write((const uint8_t *)clientBuf, 400);
        return_udp_fcn = 0;
        return_udp_fcn = Udp.endPacket();
        if(return_udp_fcn){
          digitalWrite(test_pin, LOW);
        }
        delayMicroseconds(100);

}


texts: Driving numerous chips from 2 separate SPI connectors w/ Arduino Micro

texts:
I want to drive numerous chips (L9823, TLC5925, ADG1414, MCP23S08) from an Arduino Micro as well as read input from analog pins connected to momentary buttons, toggles, potentiometers and such. The chips and input controls will be on various boards connected to the Arduino using ribbon cables.

The current idea is to have two sets of 8 pin FFC connectors with the following pins:

FFC digital "bus" conductors:
--
SCLK
VL
SDI
RST
SDO
LE3
LE2
LE1

The clock, VL (5V), SDI and SDO will be shared by both connectors but I still need 6 latches (which can also be commandeered for an interrupt or analog input) and 2 reset pins. This will allow me to run up to 3 types of chips per connector (minus latches used for something else).

I will also have a third 8-conductor FFC connector for 7 analog inputs (the eighth conductor is 5V analog ref).

So my question is, does anyone see any holes in this strategy? I don't think I'm going to try to even breadboard something like this. PCB fab is so easy now (and the first run is always wrong anyway) so I'm just going to make the boards and go from there.

So I just need to settle on what pins to use. Here is a diagram of the Arduino Micro:

So the connectors could use pins:

Connector 1 - Digital I/O:
--
SCLK SCK
VL   5V
SDI  MOSI
RST  11
SDO  MISO
LE3  A8
LE2  A7
LE1  SS

Connector 2 - Digital I/O:
--
SCLK SCK
VL   5V
SDI  MOSI
RST  13
SDO  MISO
LE3  A9
LE2  7 (Arduino INT)
LE1  5

Connector 3 - Analog Inputs:

5V
A0
A1
A2
A3
A4
A5
A6

A10 and A11 are reserved for other purposes as well.

Does this look ok?

UPDATE 1:

I have updated the text of this question to consider many of the great comments. The changes include:

Share MISO and MOSI
between connectors. Not sure why I thought I needed to use separate
ports for the different connectors. SLCK, MISO and MOSI should
indeed be shared by both connectors.
Moved 5V to be in between
SCK and MISO and moved RST to be in between MISO and MOSI. The idea
is that the low impedance of these lines will shield from capacitive
crosstalk described by Majenko. The connectors are 1mm pitch which
isn't terribly small so hopefully this will not be an issue. It does
make routing a little harder since the data pins tend to be next to
each other but the same bus is going to connect to multiple boards
in a daisy chain fashion so capacitive crosstalk could definitely be
an issue. Fortuntely things don't have to run really fast since
everything is ultimately for interfacing with humans who are
relatively slow.


texts:
Can we find out about the parts that the arduino uses?
I want to make a shield, and i bought the same power jacks.
And i thought that there would be two pins, one for power, one for GND.
However, it has three pins.
The supplier did not have a datasheet, and right now i do not have a continuity beeper either, so could i see its datasheet somewhere, or does anyone know why it has three pins?


texts: Arduino to breadboard with LM35 temp sensor

texts:
I have moved the MCU of the Arduino to a breadboard using these steps https://www.arduino.cc/en/Main/Standalone then interfaced it with an LM35 temperature sensor to the ADC0. But I can't get proper values from the LM35. I think it's because of the Aref or AVcc. Both are just connected to +5?
Here is my code:

float tempC;
float reading;

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

void loop()
{
    reading = analogRead(0);
    tempC = (reading * 0.4882815) + 5;
    Serial.print(tempC);
    delay(1000);
}

I get hex values and sometime high values. What to do with Aref and AVcc?

EDIT: I get values like these
€
Œ


texts:
By using the following draft i decode the signals from an RF receiver

#define CH1 2
#define CH2 3
#define CH3 4
#define CH4 5
#define CH5 6
#define CH6 7

int ch1Time, ch2Time, ch3Time, ch4Time, ch5Time, ch6Time = 0;
void channels()
{
  TCNT1 = 0;
  ch1Time = 0; ch2Time = 0; ch3Time = 0; ch4Time = 0; ch5Time = 0; ch6Time = 0;

  while ((PIND & ((1 << CH1) | (1 << CH2) | (1 << CH3) | (1 << CH4) | (1 << CH5) | (1 << CH6))))
  {
    if (PIND & (1 << CH1))
      ch1Time = TCNT1;

    if (PIND & (1 << CH2))
      ch2Time = TCNT1;

    if (PIND & (1 << CH3))
      ch3Time = TCNT1;

    if (PIND & (1 << CH4))
      ch4Time = TCNT1;

    if (PIND & (1 << CH5))
      ch5Time = TCNT1;

    if (PIND & (1 << CH6))
      ch6Time = TCNT1;
  }
}

The issue is that i need also to use the 6 PWM's of the nano board.
So i thought of moving the channels 1-6 to the analog pins like so..

#define CH1 A0
#define CH2 A1
#define CH3 A2
#define CH4 A3
#define CH5 A4
#define CH6 A5

while ((PINC & ((1 << CH1) | (1 << CH2) | (1 << CH3) | (1 << CH4) | (1 << CH5) | (1 << CH6))))
  {
    if (PINC & (1 << CH1))
      ch1Time = TCNT1;
etc...

but it simply does not work. Any thoughts please?


texts:
maybe my problem is just that my thinking is wrong. I hope you can help me.
First of all I will point out what I think in general, then I show you some code to work with.

In general my problem is to wrap me head around a push-button (or any other input) that stops (or better restarts) a running program at any time.
If i use the digitalRead(pin-whatsoever)-statement don't I have to tackle the exact mili/microsecond my MC is working on that specific line of code?
I don't want to use an interrupt either, i want to restart the program, not to interrupt it.

My project is some kind of turn-indicators for a bicycle.
The lights shall "run" from right to left on left-turns and vice versa.
But i want to stop the sequence at any point (or at least after one loop-run) if I push the corresponding button again.
After that the MC shall wait for another button-push to run the indicator either till the for-loop is finished or i press the same button earlier.

Another (general) question: Is there a way to get rid of delay-statements and achieve similar results?

Thank You so far.

   // Var-Setup
  const int mtime = 120; // Time between lights lighting up
  const int ftime = 100; // Time between lights turning out

void setup() {
  // put your setup code here, to run once:
  // Pin-Setup
    // LED-Pins
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

    // Button-Pins
  pinMode(12, INPUT);
  pinMode(13, INPUT);

}

void right(){
  for(int i=0; i<5; i++){
      // Indicator right with running light (like a "half-knight-rider" ;) )
      // Rise
      digitalWrite(11, HIGH);
      delay(mtime);
      digitalWrite(10, HIGH);
      delay(mtime);
      digitalWrite(9, HIGH);
      delay(mtime);
      digitalWrite(8, HIGH);
      delay(mtime);
      digitalWrite(7, HIGH);
      delay(mtime);
      delay(mtime);

      // Fade
      digitalWrite(11, LOW);
      delay(ftime);
      digitalWrite(10, LOW);
      delay(ftime);
      digitalWrite(9, LOW);
      delay(ftime);
      digitalWrite(8, LOW);
      delay(ftime);
      digitalWrite(7, LOW);
      delay(250);
    }
}

void left (){
  for(int i=0; i<5; i++){
    // Indicator left with running light
    // Rise
    digitalWrite(2, HIGH);
    delay(mtime);
    digitalWrite(3, HIGH);
    delay(mtime);
    digitalWrite(4, HIGH);
    delay(mtime);
    digitalWrite(5, HIGH);
    delay(mtime);
    digitalWrite(6, HIGH);
    delay(mtime);
    delay(mtime);

    // Fade
    digitalWrite(2, LOW);
    delay(ftime);
    digitalWrite(3, LOW);
    delay(ftime);
    digitalWrite(4, LOW);
    delay(ftime);
    digitalWrite(5, LOW);
    delay(ftime);
    digitalWrite(6, LOW);
    delay(250);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorL = digitalRead(12);
  int sensorR = digitalRead(13);
  if(sensorL == HIGH){
    left();
  }else if(sensorR == HIGH){
    right();
  }
}


texts:
I have an Arduino Uno. The story is I installed Arduino IDE and Drivers before even buying an Arduino Board. I used it a little and when I bought and connected an arduino board, I was unable to make it detect. I smacked a little usimg google and was able to somehow Fix this. but again another day, It worked a little and started creatimg problems. now its not detecting. Please suggest me a way To make it work...
Should I format my windows 7 and Reinstall all the drivers as per rules?


texts:
I got one of these cheap STM8 boards from China and was hoping to find a way to use this with arduino code.

Does anyone know of an arduino boot loader and board package that works with them ?


texts:
I have some existing code that I've been using with an Uno and a HC-SR04. In order to make my project less expensive, I'm trying to port everything over to a ESP8266-01.

The last hang up I've been running into is that it appears that the ESP8266 doesn't support the pulseIn function.

duration = pulseIn(echoPin, HIGH);

Any idea on how I can change the pulseIn function with interrupts or something else?

Lastly I've done a lot of searching for using a HC-SR04 with a ESP8266 and while there are a couple examples out there, I haven't seen anyone do it with Arduino code...


texts: How to run atmega328p at 8, 4 and 1 mhz?

texts:
Instead of using the regular Arduino board I have purchased the atmega328p-pu along with this components:

22pf ceramic capacitor
10K resistor
16mhz crystal
47uF capacitor
3.3 Volts Power supply

The diagram looks like this:

Because the atmega328p chip that I purchased already comes loaded with arduino bootloader I can program this chip right away! This video explains in more detail how to upload the code to the chip. It is very simple.

The reason why I run my atmega328p chip with a 3.3V power supply is because of these reasons:

I have multiple sensors like the NRF24L01 that cannot take 5 volts.
I run this project of a 3.3 battery as well in order to save power.
I do not want to use voltage regulators as they are inefficient and they will waste my battery.
Everything works great.

Even though everything works great if I am running atmega328P at 16mhz @ 3.3V I am not following the specifications. In order to do things correct I will like to run my code at 8mhz so that I am in within the specs

Question

What is the correct way of running this project at 8mhz? If I change the 16mhz crystal for a 8mhz it runs at 8mhz but everything is half the speed. I have to divide all time related functions by 2. Moreover, I cannot upload new code if it has a 8mhz crystal. In order to upload new code I have to place the 16mhz crystal upload the code and then change the crystal again.

Can I still use my 16mhz crystal and run at 8mhz so that I do not have to keep replacing the crystal? I want my millis function and other time dependent functions to have the correct time. I do not want to have to divide everything by 2.

Do I have to burn a different bootloader for this to work? Where can I find a tutorial that can explain me all this?

There are tutorials on how to use the internal 8mhz crystal from the atmega328 chip but still want to use an external crystal as it is much more accurate

Edit

I just found  this link that explains how to do it. Edgar Bonet answer seems a lot simpler so I will stick to that.


texts:
Is anyone out there building serious metal detectors with the Arduino? By "serious" I mean metal detectors with phase sensitivity to discriminate between ferrous and non-ferrous metals, etc.  Seems like the Uno is a good platform for a smart metal detector project.

Update:
Arduino allows me to control phase discrimination which allows ferrous metals to be rejected.
I already know it can be done with an analog phase shift circuit.
Also Arduino can perform target ID function with readout to 16x2 LCD display.


texts:
I bought an ATMEGA2560 on eBay and programmed it with Arduino IDE 1.6.9 using the USB cable, and the LED blinked as expected - All well and good.

Now I wanted to program the mega from my UNO as follows:

Uploaded ArduinoISP to the UNO
Changed the Board to Mega2560 and changed the Programmer to Arduio as ISP
Connected the two ICPS sockets with a 6 wire cable, where pin 5 on the UNO ICPS is cut and instead connected to D10 on the UNO
Upload the Blink sketch: IDE says Uploading for a minute, then some errors:

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

5) Upload Using Programmer: Activity on the UNO (RX/TX) and the LED on the mega lights constantly - And I can no longer program the mega using the IDE

Any pointers to what I did wrong and how to fix it?
Best regards


texts:
Yesterday afternoon I have left my Arduino running on a fresh Alkaline 9V battery (+ connected to Vin, - connected to GND). Today morning (16 hours later) the LCD display was no longer visible, and when I measured the volatage, I saw the battery was depleted to my surprise - its idle voltage was only 7 V.

My device is Arduino Uno with LCD 2x16 with LCD backlight and 2 DS18B20 sensors. Is it normal for such device to deplete 9V battery this quick?

I have read an answer to What are (or how do I use) the power saving options of the Arduino to extend battery life? question and I think what I see might be related to this, however I am not sure. If it is, is there some common schematics how to connect Arduino to be powered by a battery efficiently?


texts: Using Arduino as contact to the world for linux box if app crashes

texts:
I am new to this micro controller thingie world so bare with me :)

Let me describe a scenario first.
Say I have a linux box for house automation embedded in a wall.
For security reasons is the only active access to the box the display mounted to the wall.

Another access would be via network and ssh but ssh is disabled.
Unfortunately does the web app sometimes crash and nothing goes. In the wake of that do I have to disassemble quite some stuff to get to the box and to revive it.

My Idea:
I can use a nfc or rfid sensor and hook it up to Arduino.
Would it be possible to make Arduino log on to the linux box and fire up and shutdown ssh?

I don't want to use Arduino Yun.
Is it achievable with an Arduino nano/Mega?

If not, which system would be your first choice to accomplish this task?

Thanks for your patience :)