texts:
I'm using I2C and the Arduino Library (Wire) to communicate between two Arduinos, and my code isn't working. It's supposed to read in an int from the slave, write a value to the slave, then read back that value. I'm expecting "0 4", but i keep getting "0 0". Does this mean that the slave isn't registering the write?

Master code:

#include <Wire.h>

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

void ffsis()
{
  //request i
  Wire.requestFrom(2, 1);
  int i = Wire.read();
  Serial.print(i);

  //send n seed
  Wire.beginTransmission(2);
  Wire.write(12);
  Wire.endTransmission();

  Serial.print(" ");

  //request n
  Wire.requestFrom(2, 1);
  int n = Wire.read();
  Serial.print(n);
}

void loop()
{
  delay(100);
}

Slave code:

#include <Wire.h>

void setup()
{
  Wire.begin(2);
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

int n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{
  int n = wire.read();
}


texts: Cannot use radio transmitter after switching to LowPower library

texts:
My Arduino Mini board has DHT22 temperature sensor and 433MHz radio transmitter modules. I'm using DHT and RCswitch libraries to make use of them. Code looks like this:

void setup() {
  tempSwitch.enableTransmit(RADIO_PIN);
  dht.begin();
}

void loop() {
  float temp = dht.readTemperature();

  unsigned long message = createTemperatureMessage(SENSOR_ID, temp);
  tempSwitch.send(message, 32);

#ifdef MY_DEBUG
  unsigned int sleepCount = 1;
#else
  // 3600s / 2 / 8s == 225
  unsigned int sleepCount = 225;
#endif
  for (; sleepCount > 0; sleepCount--) {
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  }
}

So I'm reading temperature and sending it using RCswitch library. Initially I just had delay(1000); instead of fancy LowPower sleep loop but I wanted to make my "device" more battery-friendly so I switched to low-power sleep.

The problem is that now Arduino is only sending data first time and after sleeping 30 minutes (in "release" mode) it does not send anything anymore. If I reduce 30 minutes to 8 seconds it is capable of sending data as well as if I replace sleep with delay(30*60*1000);.

From beyond it looks like something is not caching up after the sleep. Do I need to "wake" radio module in any special way? How to fix that?


texts: "Bad request" error (HTTP) while posting to PHP server using Arduino and ESP8266

texts:
I'm doing an IoT project where the temperature and humidity values from a DHT11 sensor is sent to a PHP server using HTTP post. When I run the Arduino, the Serial Monitor says "Bad request". The sensor values are not appearing on the webpage. Please, help me figure out the problem. I am using an Arduino Uno with and an ESP-01.

// Code to use SoftwareSerial
//The final sketch
#include "SoftwareSerial.h"
#include <dht.h>

#define dht_dpin 8

String data;
String ssid = "TRAK family";

String password = "rukman12345";

SoftwareSerial espSerial(6, 7); // RX, TX

dht DHT;

float t;
float h;

String server = "svce-ece-b.000webhostapp.com";

String uri = "esp.php";

boolean DEBUG = true;

void showResponse(int waitTime)
{
    long t = millis();
    char c;
    while (t + waitTime > millis()) {
        if (espSerial.available()) {
            c = espSerial.read();
            if (DEBUG)
                Serial.print(c);
        }
    }
}

void setup()
{
    DEBUG = true;

    Serial.begin(115200);
    delay(500);

    espSerial.begin(115200);

    espSerial.println("AT+RST");
    showResponse(1000);

    // espSerial.println("CIOBAUD=9600");
    // showResponse(1000);

    espSerial.println("AT+CWMODE=1");
    showResponse(1000);

    espSerial.println("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"");
    showResponse(5000);

    if (DEBUG)
        Serial.println("Setup completed");
}

void httppost()
{
    espSerial.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");

    if (espSerial.find("OK")) {
        Serial.println("TCP connection ready");
    }
    delay(1000);

    String postRequest =
        "POST " + uri + " HTTP/1.0\r\n" +
        "Host: " + server + "\r\n" +
        "Accept: *" + "/" + "*\r\n" +
        "Content-Length: " + data.length() + "\r\n" +
        "Content-Type: application/x-www-form-urlencoded\r\n" +
        "\r\n" + data;

    String sendCmd = "AT+CIPSEND=";
    espSerial.print(sendCmd);
    espSerial.println(postRequest.length());

    delay(500);

    if (espSerial.find(">")) {
        Serial.println("Sending..");
        espSerial.print(postRequest);

        if (espSerial.find("SEND OK")) {
            Serial.println("Packet sent");
            while (espSerial.available()) {
                String tmpResp = espSerial.readString();
                Serial.println(tmpResp);
            }

            // close the connection
            espSerial.println("AT+CIPCLOSE");
        }
    }
}

void loop()
{
    // Read sensor values
    DHT.read11(dht_dpin);
    float t = DHT.temperature;
    float h = DHT.humidity;
    if (isnan(t) || isnan(h)) {
        if (DEBUG)
            Serial.println("Failed to read from DHT");
    }
    else {
        if (DEBUG)
            Serial.println("Temp=" + String(t) + " *C");
        if (DEBUG)
            Serial.println("Humidity=" + String(h) + " %");

        data = "temperature=" + String(t) + "&humidity=" + String(h);

        httppost();
    }

    delay(1000);
}

This is my PHP code:

<?php
    global $Temp;
    global $Humidity;
    if(isset($_POST['temperature'])){
        $Temp=$_POST["temperature"];
    }
    if(isset($_POST['humidity'])){
        $Humidity=$_POST["humidity"];
    }

    $Write="
Temperature : " .$Temp . " Celcius
" . "
Humidity : " .       $Humidity . " %
";
    file_put_contents('sensor.html',$Write);
?>


texts:
I'm trying to connect my nodeMCU to my WiFi network also i have provided ip address  but it keeps printing ........ it is not connecting to the network. Below is my code.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

// Configration Parameter for Access Poin
char * ssid_ap = "";
char * password_ap = "";
IPAddress ip(192, 168, 1, 158);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255,255,255,0);

// Set up the server object
ESP8266WebServer server (80);

// Keep track of sensor data that's going to be sent by the client
float sensor_value = 0.0;

void setup()
{
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(ip,gateway,subnet);
  WiFi.softAP(ssid_ap,password_ap);

  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid_ap);

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

  Serial.println("");
  Serial.println("WiFi connected");

  server.begin();
  Serial.println("Server started");
  Serial.print("IP Address:");
  // Serial.print(WiFi.localIP());
  // Configure Server Router
  server.on("/",handleIndex); // use the top root path to report the last sensor value
  server.on("/update",handleUpdate);
  // server.begin();
}

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

}

void handleIndex()
{
  server.send(200,"text/plain",String(sensor_value)); //we'll need to refresh the page for getting the latest value

}

void handleUpdate()
{
 sensor_value = server.arg("value").toFloat();
 Serial.println(sensor_value);
 server.send(200,"text/plain","Updated");

}


texts: Why is the T2 transistor used in Arduino Micro?

texts:
I was about to design a small custom board using ATmega32U4, replicating the Arduino Micro. I know that T1 is used to block VUSB when VIN is connected.

But why T2? The gate is 5V, so it will be always OFF! Or does it act as a diode?

Schemtic https://www.arduino.cc/en/uploads/Main/arduino-micro-schematic.pdf


texts: Motor not working when connected to motor driver shield?

texts:
My code is getting uploaded to arduino without problem but still my motor is not moving when i connect it to the motor driver shield. I am supplying 6V battery to the shield which is connected to dc motor at M2

What could be the problem?

Code:-

#include <AFMotor.h> //import your motor shield library

AF_DCMotor motor2(2,MOTOR12_2KHZ); // set up motors.
AF_DCMotor motor3(1, MOTOR34_1KHZ);

void setup() {
  Serial.begin(9600); // begin serial communitication
  Serial.println("Motor test!");
  motor2.setSpeed(105); //set the speed of the motors, between 0-255
  motor3.setSpeed(105);
}

void loop() {
   motor2.run(FORWARD);
   motor3.run(FORWARD);
  }


texts:
So I'm trying to learn basic Android app dev. My master plan was to make an app using MIT App Inventor that would turn on an LED over Bluetooth using an Arduino. Once I verified that everything worked, I would write the entire app from scratch using Android Studio. This way, when I inevitably run into bugs with my written-from-scratch app, I could say with 100% certainty that the issue is in my Android code and not hardware/Arduino related.

So I'm having trouble right now. I have two separate LED circuits, a blue LED from port 13 and a green LED from pin 8. I verified that both circuits are working properly by using the Blink code, so I know the issue is definitely not with the LED circuits.

I'm using an HC 06 Bluetooth module. The pins are connected as follows:

HC 06 -> Arduino

RX -> TX

TX -> RX

5V -> 5V

GND -> GND

Here is the Arduino code:

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(0,1);
int ledblue = 13;
int ledgreen = 8;
int tx = 1;
int rx = 0;
int type;

void setup() {
  Serial.begin(9600);
  //bluetooth.begin(9600);
  pinMode(ledblue, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
  allpinslow();
}

void loop() {
  int i = 0;
  int m = 0;
  delay(500);
  if (Serial.available() > 0) {
    while(Serial.available() > 0){
      type = Serial.read();
      Serial.println(type);
    }
    Check_Protocol(type);
  }
}

void allpinslow()
{
  digitalWrite(ledgreen, LOW);
  digitalWrite(ledblue, LOW);
}

void Check_Protocol(int inStr) {
  int i = 0;
  int m = 0;
  if (inStr == '0') { //Led Off equals("2off")
    allpinslow();
  }
  if (inStr == '1') { //Led on
    digitalWrite(ledblue, HIGH);
  }
  if (inStr == '2'){
    digitalWrite(ledgreen,HIGH);
  }
}

Here is the MIT App Inventor block code

If I press the Green or Off button, the Serial Monitor spits out 255. If I press Red, nothing shows up on the serial monitor. I'm a bit dumbfounded on what is broken so I would greatly appreciate any help I can get.

Edit: @Delta_G here is the modified code

#include <SoftwareSerial.h>
int ledblue = 13;
int ledgreen = 8;
SoftwareSerial mySerial(2,4); //RX, TX
int type;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(ledblue, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  allpinslow();
}

void loop() {
  int i = 0;
  int m = 0;
  delay(500);
  if (mySerial.available()) {
    while(mySerial.available()){
      type = mySerial.read();
      Serial.println(type);
    }
    Check_Protocol(type);
    //Serial.println(inSerial);
  }
}

void allpinslow()
{
  digitalWrite(ledblue, HIGH);
  digitalWrite(ledblue, LOW);
}

void Check_Protocol(int inStr) {
  int i = 0;
  int m = 0;
  if (inStr == '0') { //Led Off equals("2off")
    digitalWrite(ledblue, LOW);
    digitalWrite(ledgreen, LOW);
  }
  if (inStr == '1') { //Led on
    digitalWrite(ledblue, HIGH);
  }
  if (inStr == '2'){
    digitalWrite(ledgreen,HIGH);
  }
}


texts: Arduino sketch behaves differently depending on version of Arduino IDE

texts:
I am assisting some friends on an Arduino Uno project, and we've noticed that when using some earlier versions of the Arduino IDE (In this case 1.0.5), the sketch behaves as desired. However, when using 1.6.5, the program behaves differently. The sketch in question is here:

https://github.com/CymaSpace/Programs---Sketches/tree/master/Tim%20Gorbunov/a3%20with%20monosetting/a3

I have noticed that when enabling verbose compilation output, the size of the compiled binary is different between the two different IDE versions. There are also some warnings in the older IDE that are not present in the newer version. There is at least one other version before 1.6.5 that is behaving the same way as 1.0.5 (it's a later version but at the moment I don't know which, I will see if I can find out and post it here later).

Any idea why the two sketches might be behaving differently and how to go about troubleshooting the problem? This occurred on both a windows and mac computer. Thanks!


texts: Dual power supply using Arduino uno and nano

texts: I had a very vague thought. I was wondering if I could I create a dual power supply using an Arduino uno and a nano. Can the  ground terminals of both the boards be shorted and the 5 volt terminals be used as +5v and -5v . Is this possible? Would it damage the board??


texts: How to save data to SD card using Memory Shield Module SPI

texts:
I am trying to save some data to the SD card using the memory shield module that I read from HC-SR04 Ultrasonic Module. The data that gets printed indicates error. This is how my SD card module is connected.

  SD card attached to SPI bus as
  VCC -Arduino 5v
  GND- Arduino GND
  MOSI - pin 11
  MISO - pin 12
  CLK - pin 13
  CS - pin 4

Still, Arduino complains that there was an error opening the file in SD card. My sketch is this:

#include <SPI.h>
#include <SD.h>
#define echoPin 6 // Echo Pin
#define trigPin 7 // Trigger Pin

int maximumRange = 250; // Maximum range needed
int minimumRange = 1; // Minimum range needed
long duration, distance; // Duration used to calculate distance
const int chipSelect = 4;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  Serial.print("Initializing SD card...");
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop() {
  readDistance();
  if(distance>minimumRange && distance < maximumRange){
    String string = "distance is" + distance;
    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    // if the file is available, write to it:
    if( dataFile ){
      dataFile.println(string);
      dataFile.close();
      Serial.println( string );
    }else{
      // if the file isn't open, pop up an error:
      Serial.println("error opening datalog.txt");
      dataFile.close();
    }
  }else{
    Serial.println("Out of range...");
  }
  delay(50);
}

int readDistance(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration/58.2;
}

Output:

rror opening datalog.txt
rror opening datalog.txt
error opening datalog.txt
rror opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt

How do I solve this to save the readings to SD card?


texts: Purposely create compile error to fail the upload

texts:
I would like to create a compile error so sketch does not upload in certain cases.

I have written a library with a function that adds pins being used to an array. If the same pin is used twice I want to fail the compilation (preferably with an error that explains why). Is this possible?

void CheckPinNum(int newPinNum){
  for (int i=0; i <= PinArrayLength; i++){
    if (newPinNum == PinArray[i])
      failCompilation("You entered same pin twice!");
  }
}


texts: Adruino Yun's Linux environment not working

texts:
I was recently given an Arduino Yun board from my university. I am able to upload sketch to the board, and it seems to function properly. However, I am unable to see the Linux booting up. When I want to reset the WLAN, ressing the WLAN RST button does nothing at all, the WLAN LED doesn't even blink or light up. Pressing the YUN RST button also does nothing.

So I did some Googling and found out that I could upload the YunSerialTerminal to the Yun, so I did that. And when I am trying to monitor the Linux boot up from the serial monitor. Nothing is shown. I press the TUN RST button as taught by the Arduino website while monitoring the Serial Monitor, nothing shows. However, the RX button does blink whenever I press enter.

Can anybody help me?


texts: DS3231 AT24C32 IIC making digital outputs not work

texts:
I have just taken the code from

https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout/wiring-and-test

to get DS3231 AT24C32 IIC to work fine with my Aduino and its working fine.

I have then taken
https://learn.adafruit.com/adafruit-arduino-lesson-4-eight-leds
and expanded it to work with three 74HC595 Shift Register. And this is working fine with all three sets of LEDS lighting up one after an other like in the demo.

So I do not think there is anything wrong with my wiring.

When I merge the two demos together, all the output pins on my this shirt register just give out positive current constantly.

I have walked through each line of the code and the problem is caused by

if (! rtc.begin()) {

if I take out that if statement everything works.  But since that is the bit that starts the clock I want that.

So how do I get the DS3231 started and not have all the pins on the third shift register high?

Also if it matter it is an official Leonardo board.

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

RTC_DS3231 rtc;

int latchPinOne = 5;
int clockPinOne = 6;
int dataPinOne = 4;

int latchPinTwo = 11;
int clockPinTwo = 10;
int dataPinTwo = 8;

int latchPinThree = 3;
int clockPinThree = 13;
int dataPinThree = 2;

byte leds = 0;

void setup()
{
#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  pinMode(dataPinOne, OUTPUT);
  pinMode(latchPinOne, OUTPUT);
  pinMode(clockPinOne, OUTPUT);

  pinMode(dataPinTwo, OUTPUT);
  pinMode(latchPinTwo, OUTPUT);
  pinMode(clockPinTwo, OUTPUT);

  pinMode(dataPinThree, OUTPUT);
  pinMode(latchPinThree, OUTPUT);
  pinMode(clockPinThree, OUTPUT);

  Serial.begin(9600);
  Serial.println("Start");

  delay(3000); // wait for console opening
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
}

void loop()
{
  leds = 0;
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(500);
  }
}

void updateShiftRegister()
{

  digitalWrite(latchPinOne, LOW);
  shiftOut(dataPinOne, clockPinOne, LSBFIRST, leds); // send the data
  digitalWrite(latchPinOne, HIGH);

  digitalWrite(latchPinTwo, LOW);
  shiftOut(dataPinTwo, clockPinTwo, LSBFIRST, leds); // send the data
  digitalWrite(latchPinTwo, HIGH);

  digitalWrite(latchPinThree, LOW);
  shiftOut(dataPinThree, clockPinThree, LSBFIRST, leds); // send the data
  digitalWrite(latchPinThree, HIGH);
}


texts: avrdude: stk500_recv(): programmer is not responding - OSX10.11

texts:
I'm getting the following error with a genuine Arduino Uno on Mac OSX10.11 El Capitan when uploading to it (the green light is on, the orange light flashes intermittently while attempting to upload). Here's the error:

avrdude: stk500_recv(): programmer is not responding

I've tried all the solutions I can find. I've selected the correct port and board. I've tried pressing the reset button before uploading. I've tried different USB cables. I've tried unplugging and replugging everything. I've read this: http://arduino.cc/en/Guide/Howto .

I tried all these solutions here: https://stackoverflow.com/questions/23993111/mac-uno-avrdude-stk500-recv-programmer-is-not-responding

I tried the FTDI fix, (but not sure if was actually able to disable the mac drivers, or which drivers are now running, the example I tried is for for OSX 10.10 Here). I ran into the following issue in the Terminal:

Mac-Pro:~ m$ cd /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns
Mac-Pro:PlugIns m$ sudo mv AppleUSBFTDI.kext AppleUSBFTDI.disabled
mv: rename AppleUSBFTDI.kext to AppleUSBFTDI.disabled: No such file or directory

I don't get why it says No such file or directory because AppleUSBFTDI.kext definitely exists as a package in the Extensions folder, but I guess it's talking about another file named that in the plugins folder? Confusing ... Was this moved in OSX 10.11 and should I rename this package in the Extensions folder?

I did download and install the old FTDI drivers, but I don't know if they're actually the ones working right now? How do I clarify that?

Any ideas how to get this working?

I also tried on an old Mac Laptop 10.6.8 - Snow Leopard, and had the same issue :(


texts: I heard that Servo library cannot send and receive from other arduinos without inturrupting the timer and messing up the motors. SoftwareServo is supposedly the answer to this. Is this true? Neither libraries are working for this problem at the moment.


texts:
I'm trying to send the byte 0x5A (0b01011010) on the serial output of an Arduino Due. My program is based on this example project, but I've stripped out all the unrelated parts:

#![feature(lang_items)]
#![no_std]
#![no_main]

extern crate sam3x;

pub mod rust_base;
use sam3x::*;
use sam3x::hal::peripherals::{Peripheral};
use sam3x::drivers::led::{Led};
use sam3x::hal::rtt::{init_timer, wait_ms};
use sam3x::hal::pmc;
use sam3x::hal::uart;

#[link_section=".vectors"]
pub static VECTOR_TABLE: VectorTable =
    VectorTable {
        reset_handler : start,
        exceptions    : [0; 14],
    };

fn start() -> ! {
    init_timer();
    pmc::enable_peripheral_clock_0(Peripheral::PioC);

    let led = Led::connect(Peripheral::PioB, 27).expect("Wrong pin for led.");
    let tx = uart::Tx::init(uart::BR_9600);

    let mut led_on = true;
    led.on();
    loop {
        tx.write_byte(0b01011010);

        wait_ms(250);
        if led_on {
            led.off()
        } else {
            led.on()
        }
        led_on = !led_on;
    }
}

As you can see, all I do is send out the byte 0x5A four times a second, with some LED blinking just to show the program is running.

My problem is that if I connect a serial terminal program with 9600-8N1 settings, I am not getting 0x5A; instead, I am getting mostly 0xBA, and sometimes a 0x9A slips through.

Writing out the bits:

0101 1010    5A
1011 1010    BA
1001 1010    9A

Note that the lower nybble is always correct, which is why I don't think it's a serial communication setting issue; also, it's pretty clear from uart::Tx::init's implementation that it defaults to no parity bits.


texts:
I want to use a TSL2561 light sensor and a DS1307 RTC and a couple of other sensors like DS18B20, AS3935, ML8511, MQ135, 433 mhz sender together with an Arduino.
However on Adafruit I read this today (Quote from Adafruit)

  You may be wondering, how is it OK to connect a 3.3V chip like the
  TSL2561 to 5.0V data pins like the Arduino? Isn't that bad? Well, in
  this specific case its OK. I2c uses pullup lines to the 3.3V power
  pin, so the data is actually being sent at 3.3V. As long as all the
  sensors/device on the i2c bus are running on 3.3V power, we're fine.
  However, don't use a 5.0v powered i2c device (like the DS1307) with
  pullups at the same time as a 3.3V device like the TSL2561! If you
  want to use this sensor with a datalogger that uses the DS1307, remove
  any/all of the pullup resistors from the DS1307 SDA/SCL pins. The
  pullups built into the TSL2561 will then be active and keep the
  voltage at 3.3V which is safe for both the RTC and the sensor.

I don't really understand the meaning of this. What am I supposed to do? It tells me to remove the pullup lines on the RTC, but what are they and where can I find them? Are there any other sensors where I have to do this? If I don't remove the pullup lines, will I damage anything? Can someone clarify those things to me?


texts: Arduino Servo.h library returns error in compilation

texts:
I have a problem with Servo library. This is my (very short XD) "code":

#include <Servo.h>

void setup() {
  Servo.attach(9, 554, 2400);
}

void loop() {
  Servo.write(2000);
}

And it returns:

Arduino:1.6.5 (Windows 7), Board:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

sketch_aug24a.ino: In function 'void setup()':
sketch_aug24a:4: error: expected unqualified-id before '.' token
sketch_aug24a.ino: In function 'void loop()':
sketch_aug24a:8: error: expected unqualified-id before '.' token
expected unqualified-id before '.' token

Like there is no included library. What can I do with it ?


texts: Raspberry Pi with Arduino, Serial connection stops working

texts:
This is the hardware set-up at home,

Raspberry Pi GPIO -> Logic Level Converter -> Arduino -> Multiple Relays

I am running Raspbian and NodeJS on the Pi while the Arduino is loaded with StandardFirmata.
I connect NodeJS to the Arduino with the johnny-five package and it works well after it's started. But after extended periods, a few hours? The Arduino stops responding. Whatever command that I send to the Arduino won't be acted on. It's as though as the Arduino hung.
Both the Raspberry Pi and Arduino are being powered indenpendently with a 1A Nokia USB Adapter.

Does anyone know why this is happening?

johnny-five
StandardFirmata
NodeJS Server Code


texts: Reading Ground/Open signal wire combonations to power specific LED's - Can it be done?

texts:
This might be a super easy question to answer. I ordered an Arduino Uno anyways for the sole purpose to understand this. Would not mind getting a jump on things before it's here.

I would like to setup the Arduino Uno to be used as a gear indicator for GM transmissions (specifically right now the GM 4l60e). Below is how it currently tells the computer/cluster what gear it's in.

This uses a range switch. Basically it's a combination of 4 wires that are grounded (low) in a specific order, the computer reads it, and displays what gear the transmission is in. There are 4 signal wires - Signal A,B,C, and P. Below is how the range switch signals it:

Park    - A=low,  B=open, C=open, P=low
Reverse - A=low,  B=low,  C=open, P=open
Neutral - A=open, B=low,  C=open, P=low
OverDrv - A=open, B=low,  C=low,  P=open
Drive 3 - A=low,  B=low,  C=low,  P=low
Drive 2 - A=low,  B=open, C=low,  P=open
Drive 1 - A=open, B=open, C=low,  P=low

I am wondering what would be the best way to go about this? The Arduino would be powered on by ignition. Display would be an LED (9-12V) output from the Arduino to each gear on a floor mount shifter. Total of 7 LEDs.

Hopefully this is easy to understand what I am trying to do. Thanks!


texts: How to upload a sketch to Arduino if it goes to deep sleep mode quickly

texts: I have created sketch where Arduino goes to powerdown mode in about 1s after boot. Now I can not upload other sketch, because programmer does not get proper response. I tried to hold reset and release it at various stages during compile/upload, but it does not help. I suspect the programmer needs to communicate with Arduino for several seconds. Any advice how to erase the sketch without programmer, or how to ban the sleep mode? It is Pro Mini 168. Thanks


texts:
Being a completely noob with Arduino (but not with coding though) I'm trying to create a simple buttonbox with a Micro unit.

For now, I can not figure out what should I do to make my Windows 10 recognize the Arduino as a HID device (joystick actually). What did I miss?


texts: Using the ATMega328, from an Arduino UNO in a Standalone configuration, and bootloader - I am really lost

texts:
I am really despaired. I have spent a full day to understand this, and it seems that I still don't.

I have an Arduino UNO, with an ATMega328, for which I wrote a great piece of code.

Later, I have built a circuit on a bread board, where I want to use that same ATMega328, in a 3.3V configuration, and hence 8MHz oscillator .

So, I understood that I have to write a new boot loader to it (is that correct?)

So I follow many guides available, including the Arduino Standalone, and then I understood that I don't have another chip (ATMega328), in order to use the UNO as a boot loader.

So, I was trying to connect the ATMega328 directly from the bread board to the UNO's serial data, change the boards.txt file to add "ATMega on bread board 8MHz", and tried to boot-loading it, without success. I get the error that it can't connect with the board.

Now I have been told that I can't connect the ATMega328 directly to the UNO serial to boot load it, so my questions are:

Do I really need to go over this hell in order to work with the same
chip that worked with 16MHz, but now on 8MHz at 3.3V? (why
in microchip I could just switch xtal? )
If I do have to boot loading it, and I have one chip, and
an UNO, how can I do that?
How you do that in mass production?


texts:
I have a project with 9 servo, I want to make a function to control each separate. Only that he is not accepting the servo as a parameter.
Can someone tell me if it is possible to pass the servant as a parameter, and how? Thank you!!
Example:

Servo s1,s2,s3;

void toMove(Servo obj,int inPosition, int forPosition){
var i = 0;
  for(i = inPosition; i<forPosition; i++){
    obj.write(i);
  }
}

void loop(){
  if(true){
     toMove(s1,0,180);
     toMove(s2,0,180);
  }
}


texts: Just sanity-checking a concept... poor man's self-monitored alarm system

texts:
If I wanted to throw together a simple burglar-alarm system that had wireless sensors talking to an Arduino (which would then send me an SMS message via cellular shield as a silent alarm telling me which alarm sensor had changed state_)... what technology would you recommend for the sensor-to-arduino signalling?

It needs to be something that draws little or no power until the alarm is triggered, resistant to radio interference, and as always cheap is a huge plus.... but I haven't gotten much beyond that.

(Of course if anyone's already implemented something like this and there are descriptions/sketches I can adopt and adapt, feel free to point me in the right direction.)

EDIT: To provide more info,this is a wood-framed house, 2 storey plus basement, brick chimney possibly in the way. No straight-line distances greater than 60 feet. Wifi, wireless phone, usual electronics and a wood shop I'm still putting together. Shouldn't be difficult, I just want a robust solution in case a friend asks me to replicate it... and for purely aesthetic reasons.


texts:
I was trying to use a solenoid lock alongside the arduino, using a 12V 2A DC adapter, TIP120, and a diode.

The circuit looks something like this. However, the lock isn't going in automatically (it requires a push).

I've tested the circuit using a multimeter, and the output given by the transistor, is indeed 12V, however, when connected to the lock, the potential difference is around 8V. I don't know if that's normal, but the lock isn't going in on it's own.

Can anyone help me with this issue?


texts:
How can I write lightweight cross correlation code for arduino? I couldnt find any solution. The measurement system contains an ultrasonic sensor and a servo  that turns from 45 to 135 degree and measures distance from 4-300 cm. Than i collect data in an array which contains distances with respect to angle. System makes several measurement like this and program finds cross correlation between new and old arrays.

http://www.instructables.com/id/How-To-Make-an-Obstacle-Avoiding-Arduino-Robot/


texts: How to secure the communication between android app and door lock controller?

texts:
I have been working on a small project using android app over Bluetooth to control a servo motor (close or open lock). To authenticate the communication, I implement HMAC (with SHA256) on both the android app and the arduino controller.

When user press the button to unlock the door, it will generate a random code,  which will be seen as a message. Then HMAC is called to create a hash string with this message and the shared key. The final string sent to arduino would be  "randomcode+commmand+hashed-string"

Something like this:

 5uq0xboq82oih111e30774e4bf8302a04e71eb84c70ce2c130717304f52c67ce709203caea0ce5
(command and the random code are hidden in the string)

As the arduino received the message, it will break the string into three parts. The command, the random code and the hashed string. It will run HMAC with the shared key and the random code. Then compare that with the received hashed string. If matched, the perform the action (command).

This is my first project on implementing HMAC. I know this may be sort of subjective question but any comment on this implementation may helpful. Thanks.


texts: Arduino Mega 2560 ADC sampling instant and other timings

texts:
Hello Everyone (I might be making some mistake in asking this "question", bear with me as I am new to these sites... I honestly think this is the best way to frame my inquiry because it's rather elaborate)

I'd like some help in understanding the "timings" of Arduino MEGA 2560's ADC module, especially with respect to the command analogRead.

I read ATmega2560 microcontroller Datasheet

Let's assume, for now, that our conversions are normal ones ( the other type being a "first" conversion, which takes 25 ADC clock cycles instead of 13, due to the time required for the initialization of analog components )

From what I understood, on a normal single conversion, the sample and hold happens after 1.5 ADC clock cycles from the start of the conversion.

Let's say that I set the prescaler to 32 with the following commands:

const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

ADCSRA &= ~PS_128;  // remove bits set by Arduino library
ADCSRA |= PS_32;  // set our own prescaler to 32

hence 16MHz / 32 = 500 kHz should be the new ADC clock frequency
( or 2 microseconds ADC clock period )

since a normal single conversion takes 13 ADC cycles, the entire conversion should take about 26 microseconds

If I'm not mistaken, (2 microseconds * 1,5)  = 3 microseconds after the ADC conversion starts, my analog pin value is set on hold, right?

I measured the elapsed time using the micros() function and, like I'd expect,
I found out that there's a little overhead introduced with analogRead function
because it takes about 28 \ 32 \ 36 microseconds (these are empirical measures).

analyzing the code in wiring_analog.c
( which is located in the folder [...]/arduino/hardware/arduino/cores/arduino/ )
the actual conversion seems to happen at line 77

// start the conversion
sbi(ADCSRA, ADSC);

does that mean that this is the instant from which the actual ADC conversion start, and so 1.5 ADC clock cycles from here, my analog pin value is set on hold?

how can I know how much time passed before that sbi function call is issued?

I saw that a single instruction on arduino won't take more than 4 microseconds (but micros() function has that resolution so I don't exactly know!)

Now, considering the so called "first" conversion, which take 25 ADC clock cycles

does this conversion happen just the first time I call analogRead since I powered on Arduino?
or does it happen even after some time , because the ADC module gets powered off? (of course, I consider the case when Arduino remains powered on all the time)

Judging by the timings I measured it seems like that the former is the one really happening, even if I don't use ADC for some time, but can anyone confirm?


texts: MAX31865 & NodeMCU RTD Low Threshold and Exception

texts:
I've got a NodeMCU V1 and a MAX31865 with a PT100 attached.  When using the example arduino code, it seems to log out the correct values but with an RTD Low Threshold error like so:
RTD value: 8068
Ratio = 0.24621582
Resistance = 105.87280273
Temperature = 15.09
Fault 0x40
RTD Low Threshold

The loop will continue for a few iterations and then throw an exception, before resuming logging out of the values above
The exception reads:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

>>>stack>>>

ctx: sys
sp: 3fffed00 end: 3fffffb0 offset: 01a0
3fffeea0:  38fe9521 00000000 3ffe8938 00000030
3fffeeb0:  401015ea 3ffe88f4 004ae1cb 40233b68
etc etc etc

The code is as follows.
#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(D4,D1,D2,D3);
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(D4);

#define RREF      430.0
#define RNOMINAL  100.0

void setup() {
  Serial.begin(9600);
  Serial.print("Adafruit MAX31865 PT100 Sensor Test!");
  thermo.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
}

void loop() {
  uint16_t rtd = thermo.readRTD();
  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF));

  // Check and print any faults
  uint8_t fault = thermo.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold");
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold");
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias");
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage");
    }
    thermo.clearFault();
  }
  Serial.println();
  delay(10000);
}

simulate this circuit – Schematic created using CircuitLab


texts:
I have used below program for ESP8266 as ISP to upload a program to an ATmega16.

ISP program uploaded in ESP8266

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266AVRISP.h>

const uint8_t reset_pin = 5;
const uint16_t port = 328;

ESP8266AVRISP avrprog(port, reset_pin);

void setup() {
    Serial.begin(9600);//115200
    Serial.println("");
    Serial.println("Arduino AVR-ISP over TCP");
    avrprog.setReset(false); // let the AVR run

    // listen for avrdudes
    avrprog.begin();
}

void loop() {
    static AVRISPState_t last_state = AVRISP_STATE_IDLE;
    AVRISPState_t new_state = avrprog.update();
    if (last_state != new_state) {
        switch (new_state) {
            case AVRISP_STATE_IDLE: {
                Serial.printf("[AVRISP] now idle\r\n");
                Serial.println("idle...");
                // Use the SPI bus for other purposes
                break;
            }
            case AVRISP_STATE_PENDING: {
                Serial.printf("[AVRISP] connection pending\r\n");
                Serial.println("pending...");
                // Clean up your other purposes and prepare for programming mode
                break;
            }
            case AVRISP_STATE_ACTIVE: {
                Serial.printf("[AVRISP] programming mode\r\n");
                Serial.println("Active...");
                // Stand by for completion
                break;
            }
        }
        last_state = new_state;
    }else{
      Serial.println("newstate not equal to old");
    }
    // Serve the client
    if (last_state != AVRISP_STATE_IDLE) {
        avrprog.serve();
        Serial.println("serve..");
    }
}

Then I have changed the board to ATmega16 and used programmer as AVR ISP and fetched/written below simple blink program to upload in ATmega16.

void setup() {
  // initialize digital pin 13 as an output.
  pinMode(1, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  Serial.println("light on");
  digitalWrite(1, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
  Serial.println("light off...");
}

Tried uploading blink program to ATmega16 using ESP8266 as ISP by Sketch =>Upload Using Programmer. This resulted to compilation followed by uploading status in Arduino IDE for longer period. I didn't get any response after 10 mins of time. Then i have tried opening Serial Monitor which shows newstate not equal to old.

I am not sure what went wrong in my coding? How can I debug this issue ?


texts:
QUCS is the only open source software which offers simulation (and designing PCB layout [in future]) of electrical circuits. But the problem with QUCS is that it is under development and many important features are not yet available in it.

I want to simulate Arduino Uno board in it for my circuit. Does anyone know how to simulate Arduino or any other micro-controller in it?

P.S. Also any other open source software for simulation and PCB designing?


texts: Code is not looping correctly when running on battery

texts:
static const int dry = 570;
static const int wet = 225;
static const int RELAY = 2;
static const unsigned long DELAY_1_S      = 1000;
static const unsigned long DELAY_1_MINUTE = DELAY_1_S * 60;
static const unsigned long DELAY_1_HOUR   = DELAY_1_MINUTE * 60;
static boolean watering = false;

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

void loop() {
  int sensorVal = analogRead(A0);
  int percentageHumidity = map(sensorVal, wet, dry, 100, 0);
  Serial.print(percentageHumidity);
  Serial.println("%");
  if (!watering && percentageHumidity < 60){
    watering = true;
    Serial.println("Watering!!!");
    digitalWrite(RELAY, HIGH);
    delay(3*DELAY_1_S);
    digitalWrite(RELAY, LOW);
    watering = false;
  }
  Serial.println(DELAY_1_S * 10);
  delay(10*DELAY_1_S);
}

I have an analog reading at A0 from a capacitance water sensor. If the sensors read a value of 60% or less humidity it will activate a water pump. The water pump is connected through a 5v relay and the water pump has its independent power supply. For some reason, the code works when connected to the USB as intended, but when I power it with the battery it connects always the water pump.


texts:
I am making an Arduino mod-bus device and I want to make a webpage as well that will allow me to reset the unit if there is any issues remotely. To do this I would need the mod-bus to operate on port 502 and the webpage to operate on port 80. is it possible for the Arduino to support two ports? I am using an Uno with a Ethernet shield and the standard ehternet.h file with a Modbus library. Any suggestions or ideas?

 #include SPI.h
 #include VL53L0X.h
 #include Ethernet.h
 #include Modbus.h
 #include ModbusIP.h
 #include VL53L0X.h
 #include Wire.h

VL53L0X sensor;
EthernetServer server(80);

//Modbus Registers Offsets (0-9999)
const int SENSOR_Hreg0 = 100;

//ModbusIP object
ModbusIP mb;

short ts;

void setup() {
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  byte ip[] = { 192, 168, 1, 177 };

  Wire.begin();
  mb.config(mac, ip);

  // Add SENSOR_Ireg register - Use addIreg() for analog Inputs
  mb.addHreg(SENSOR_Hreg0);

  ts = millis();

  //Sensor setup
  sensor.init();
  sensor.setTimeout(500);
  sensor.startContinuous();

  //remote reset
    pinMode(13, INPUT);
    digitalWrite(13, LOW);

   // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Ethernet WebServer Example");

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

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

}

void loop() {

  mb.task();

    //Webpage
    // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    bool currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("");
          // output the value of each analog input pin

            client.print("Distance Measures ");
            client.print(sensor.readRangeContinuousMillimeters());
            client.print("mm");
            client.println("
");
            client.print("Filter Count:");
            client.print(-2.2*sensor.readRangeContinuousMillimeters()+404);
            client.println("
");
          }
          client.println("");
          break;
        }

      }

  //Modbus
  if (millis() > ts + 100) {
    ts = millis();

     mb.Hreg(SENSOR_Hreg0, sensor.readRangeContinuousMillimeters() );

     }
}}

Edit:
Note: The issue seems to lie somewhere in with the sensor, because when I run it with out have the sensor code in there is no problem but when I add it the issue starts again.


texts:
I would like to use the external analog refence voltage in an Attiny88 project I am working on that will be powered with batteries.

However, the datasheet for this processor does not show an Aref pin like other versions of the attiny, like attiny85 and attiny84, where it is usually the pin PA0 or PB0. Does anyone know where is the pin for the external voltage reference in attiny88 (e.i. Aref pin)? Does this chip has the functionality for an external analog reference voltage?


texts: Timer for how long button is not pressed

texts:
I would like to timer for how long a button is not pressed. So actually if(buttonState == LOW 'for two seconds') than execute the code that comes after it. But the problem is while the user is still pressing the button the timer already starts.

Code:

int ledPin[] = {7,8,9,10};
int ledPin11 = 11;
long randNumber;
const int buttonPin = 2;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
unsigned long previousMillis = 0;
const long interval = 2000;

void setup() {
 Serial.begin(9600);
 pinMode(LED_BUILTIN, OUTPUT);
 randomSeed(analogRead(0));
 randNumber = random(1, 16);
 Serial.println(randNumber);
 for (int i = 0; i < 4; i++) {
   pinMode(ledPin[i], OUTPUT);
 }
  pinMode(buttonPin, INPUT);
 }

 void loop() {
  displayBinary(randNumber); //functie 'display binary'
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= interval){
    previousMillis = currentMillis;
    if(buttonState == LOW){
    antwoord(buttonPushCounter,randNumber);
    delay(5000);
    displayBinary(randNumber);
  }
 }
 buttonState = digitalRead(buttonPin);
 if (buttonState != lastButtonState) { // als de button word ingedrukt krijgt buttonPushCounter + 1
 if (buttonState == HIGH) {
  buttonPushCounter++;
  Serial.print("Nummer hoe vaak is gedrukt");
  Serial.println(buttonPushCounter);
 } else {
  Serial.println("off");
}
delay(250);
 }
}

void antwoord(int teller, int antwoord) {
 if (teller == antwoord) {
  for (int i = 0; i < 4; i++) {
  pinMode(ledPin[i], LOW);
 }
 digitalWrite(LED_BUILTIN, HIGH);
 delay(250);
 digitalWrite(LED_BUILTIN, LOW);
 delay(250);
 digitalWrite(LED_BUILTIN, HIGH);
 delay(250);
 } else if (teller > antwoord || teller < antwoord) {
   for (int i = 0; i < 4; i++) {
    pinMode(ledPin[i], LOW);
  }
    digitalWrite(LED_BUILTIN, HIGH);
  }
}

void displayBinary(byte numToShow) //van byte naar decimaal
  {
   for (int i = 0; i < 4; i++) {
    if (bitRead(numToShow, i) == 1) {
    digitalWrite(ledPin[i], HIGH);
    } else {
      digitalWrite(ledPin[i], LOW);
    }
   }
  }


texts:
I am trying to log data onto a SD card using UNO and the speed is critical. I am using two buffers to achieve this, so that when the data is being written to SD card the data from ADC gets stored in other buffer. Code is attached below and the issue is the same number "255" is getting printed to the text file with a speed of 3 KHz.

Code:

// Interrupt routine *******************************************
// this is the key to the program!!  readings =no. of readings required
ISR(ADC_vect) {
  if (counter < readings) {
    if(aready) {   // get the new value from analogue port
    bufa[bufcount]=ADCH;
    }    else {
    bufb[bufcount]=ADCH;
    }
  counter++;
  bufcount++;
    if(bufcount==BUF_SIZE){
      if(writeit==false) {
      bufcount=0;
      aready = ! aready;
      writeit=true; // flag that a write is needed
      } else {
      bufcount--;
      counter--;
      }
    }
  } else {
cli();//disable interrupts
  cbi(ADCSRA,ADEN); // disable ADC
  sei();//enable interrupts
  // write the last block
    if (aready){
      for(int i=0;i< BUF_SIZE;i++)
      {

      tempfile.println(bufa[i]);
      }
    } else {
      for(int i=0;i<BUF_SIZE;i++)
      {
      tempfile.println(bufb[i]);
      }
    }
  tempfile.flush();

  }
}

void loop(){
    if(writeit){
      if (aready){
        for(int i=0;i< BUF_SIZE;i++)
      {
        tempfile.println(bufb[i]);
      }
      }
    else {
        for(int i=0;i< BUF_SIZE;i++)
      {
        tempfile.println(bufa[i]);
      }
      }
    writeit=false; // the write is done!
    }
}
}


texts:
I am testing esp8266's deep sleep mode. And i have some questions about that.

1- I want to wakeup esp via timer. I did it. I implemented GPIO16-RST connection and this version done.

2- I want to ake up esp with external button too. It means, I will use timer and button to wake up esp8266 same time.

Is it possible and how can i connect  button to RST pin that while GPIO16 has already connected to RST?


texts: Arduino Mimicking Voltage Dividing Keypad / Matrix

texts:
Still very new to Arduino, so bare with me. I've been all over Google looking for ways to hack my alarm keypad. This is my first time using the Arduino to hack something  :smiley-confuse:

The keypad has a 13.7v input. Every other contact I can touch shows 5v or less. I realized quickly that the key buttons were producing various voltages. A quick search revealed that it was a voltage divider. I can see the resistors on the ladder. I though about mimicking the ladder via the Arduino and using a common ground.

I can see two shift resistors that say HEF4094BT. My guess is that these power the led's on the board.
I can also see a chip that reads KSL1 r1342 that I can't seem to find a datasheet on.

I have a few questions, but I guess I need to tell you my end goal. I want to make my keypad an IoT device. I want to be able to read the status of the alarm, and possibly mimick the keypresses to disable the alarm or activate it.

1st. I was thinking I could share a common ground, and read a led state for high/low. Like the "Armed" Led. Thought I'd ask the community before I go and short something  :(

2nd. How can I mimick the keypad's output voltages? Maybe a DAC? If so, what do you recommend?

Other Information: It's a DSC PC1550 - 6 zone alarm. (...and I'm also guessing the Rx/Tx are some DSC proprietary serial connection for security :/ )

Cheers,
Robert.


texts: I have a PWM analog port that is outputting a frequency, is it possible to do an analogRead on the same pin and get a correct value? If so, will reading that port disrupt the freq output on the pin? This is being done on a Teensy 3.2 device. My goal is to output the freq visually on an OLED. Tnx.


texts: Is it possible to pass HIGH and LOW values as parameter in a function?

texts:
I've created the following function:

void runMotor(int _dir, int _step, int wait){
  digitalWrite(_dir, HIGH);
  for (int x = 0; x < 3200; x++) {
    digitalWrite(_step, HIGH);
    delayMicroseconds(wait);
    digitalWrite(_step, LOW);
    delayMicroseconds(wait);
  }

In the first line inside the function I used the value HIGH as a fixed value. I would like to know if there's a way to pass the values HIGH and LOW as a parameter in this function. Is it possible?

Or should I just create a new function to rotate my step motor to the other side?


texts: I am wanting to have a display where I can design the GUI on a program and then somehow transfer it to the display. For the graphics I want to make, it would be really hard to manually write the code. I heard that the Nextion displays do this but they are quite costly. Is there some cheaper alternative? If not, can you make a normal display do all of that?


texts: HC-05 sending data to Android a value but it cracked out of its form

texts:
I am totally beginner but I am trying to finish my project as school work :-(
but from the beginning, I am really stuck.

Could anyone help me out?

#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX

void setup() {
  // initialize serial communication at 9600 bits per second:
  BTserial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);
  BTserial.print(sensorValue1);
  BTserial.print('|');
  BTserial.println(sensorValue2);
  delay(50);
}

The received value is here

D/BluetoothConnectionSrv: InputStream: 955|108
D/BluetoothConnectionSrv: InputStream: 9
D/BluetoothConnectionSrv: InputStream: 46|51
D/BluetoothConnectionSrv: InputStream: 9
D/BluetoothConnectionSrv: InputStream: 47|57

I need only values from 2 sensors, it seems to be as
    D/BluetoothConnectionSrv: InputStream: 955|108
    D/BluetoothConnectionSrv: InputStream: 946|51
    D/BluetoothConnectionSrv: InputStream: 947|57

I've tried to send "How are you?", then the result in the app was this

D/BF: o
D/BF: u ?Are yo
D/BF: u ?
D/BF: H
D/BF: ow Are you
D/BF:  ?

Source code in my app

        bluetoothSocket = socket;
        InputStream tempIn = null;
        OutputStream tempOut = null;

        try {
            tempIn = bluetoothSocket.getInputStream();
            tempOut = bluetoothSocket.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

        inputStream = tempIn;
        outputStream = tempOut;
    }

    public void run(){
        byte[] buffer = new byte[1024];
        int bytes;

        while(true){
            try {
                bytes = inputStream.read(buffer);
                handler.obtainMessage(STATE_MESSAGE_RECEIVED, bytes, -1, buffer).sendToTarget();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

            case STATE_MESSAGE_RECEIVED:
                byte[] readBuff = (byte[]) msg.obj;
                String tempMsg = new String(readBuff, 0, msg.arg1);
                tvMessage.setText(tempMsg);
                Log.d("BF",tempMsg);
                break;


texts: ESP-8266 stopped working due to possibly faulty perfboard layout

texts:
I have been following this tutorial to set up my ESP8266. I have also recreated on a perfboard the circuit provided in the tutorial, and I intend to use this perfboard circuit in my project.

The problem arises when I plug my ESP into the perfboard and try to talk to it through the serial monitor. When using a baud rate of 115200, the ESP responds to commands but in a garbled format. Also, the blue LED stays on after powerup for increasingly long periods of time. Now the blue LED is always on and the ESP no longer responds to any commands, except when reset and asked for the startup firmware info. I suspect that the ESP is now broken but am not sure how to check.

Also note that the ESP was working fine on a breadboard at 9600 baud, prior to the blue LED incident. Now it won't work with the breadboard either.

All commands were sent with newline and carriage return.

Is the ESP8266 broken? Could there be something wrong with my perfboard circuit? The circuit is rather dense and contains wiring for several other components in addition to the ESP-8266.


texts: I am doing a watch with GPS tracker project. I am using an Ultrasonic HC-SR04 sensor. I don't know where to connect the Echo and trig pins with my Arduino. Please let me know how to connect it.


texts: I have bought a HC05 bluetooth module and I think I accidentally short circuited it. Is there any way to change the voltage regulator or methods to reuse it again?


texts: Send packet of multiple sensors data to Bluetooth module

texts:
In my project I am using 3 sensors. I am sending a regular stream of sensors data to Bluetooth module  but now I want to send data in form of packet (which may be 30 bytes or 40 bytes of size) in which first 10 bytes contain the first sensor data while next 10 bytes contain second sensor data and so on. But problem here is I am not finding something relevant to my approach. Can any one suggest me some link or some way to do this.
Thanks in advance.


texts: How to send data from an Arduino to PC, without using the Serial Monitor?

texts: I have an analog sensor which I want to send data from my Arduino Certified Intel Edison to PC, without using a Serial Monitor and preferably putting the data into a text file.


texts:
I want to extend a library, available on github to add some features I need.
Of course I will made available the new source code as well.
Because it's the first time I do this, I'm not sure how to do.

My idea:

fork the original repository
create a new branch
make the changes
commit them locally
push the new branch on another (mine) repository (of course, to avoid messing up the original one)

Is it correct?
How to test the library while developing it? I mean, in which folder I have to clone the repo?


texts: Too few arguments for multiple if statement conditions

texts:
I am using the Arduino Uno.  I am attempting to only light a red LED when both a blue LED is on and the push button is pressed.  However, I keep receiving an error message stating too few arguments in my if statement.  I don't know whether I am simply overlooking something in my code.

The code is as follows:

int redLEDPin=7;
int blueLEDPin=3;
int redLEDOn=2000;
int redLEDOff=1000;
int blueLEDOn=2000;
int blueLEDOff=1000;
int leverR=2;

void setup() {
    pinMode(redLEDPin, OUTPUT);
    pinMode(blueLEDPin, OUTPUT);
    pinMode(leverR, INPUT);
    }

void loop() {
    digitalWrite(blueLEDPin, HIGH);
    delay(blueLEDOn);
    digitalWrite(blueLEDPin, LOW);
    delay(blueLEDOff);
    }

  if ((digitalWrite(blueLEDPin) == HIGH) && (digitalRead(leverR) == HIGH)) {
    digitalWrite(redLEDPin, HIGH);
    delay(redLEDOn);
    digitalWrite(redLEDPin, LOW);
    delay(redLEDOff);
    }
  else
  {
    digitalWrite(redLEDPin, LOW);
  }
}


texts: Getting Bluetooth addresses of connected devices via Arduino Uno?

texts: I want to find all the Bluetooth addresses of connected devices using  an HC-05/HC-06 Bluetooth module and an Arduino. I can't find any code related to this. Basically I need the addresses to put in an array. Is it possible to do this with an HC-05 or 06?


texts: 3 AC current sensors using one Arduino Uno board measuring at 200Hz

texts:
I'm new to electronics and need some help please.

I'm planning to measure current of a 3-phase output using one sensor for each phase (thus 3 sensors would be required). The frequency of data recording should be 200 Hz.

Performance/data transfer wise: Is one Arduino Uno board enough to plug in the three sensors and get the data transferred using the USB cable onto a PC? Or should I get one board for each sensor?

I appreciate your help.

Cheers.

lorena


texts:
I am using a DIY colour sensor (RGB LED and LDR) and a servo to make a skittles sorter. I am testing out just the colour detection now and printing the RGB values to serial. It worked fine until I added servo code. Now it stops printing to serial after about 4 cycles. Not sure why this is happening. I have tried using other programs besides using the Arduino IDE but the same issue.

I am using a NodeMCU with Arduino code:

#define S0 4
#define S1 0
#define S2 2
#include <Servo.h>
Servo topServo;
int frequency = 0;

void setup() {
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  topServo.attach(14);
 Serial.begin(9600);
 Serial.print("Start");
}

void loop() {
  topServo.write(125);
  delay(500);

  for(int i = 150; i > 80; i--) {
    topServo.write(i);
    delay(5);
  }
  checkcolours();
  delay(500);
}
void checkcolours(){
 //RED
digitalWrite(S1,LOW);
digitalWrite(S2,LOW);
digitalWrite(S0,HIGH);
frequency = analogRead(17);
int R = frequency;
Serial.print("R= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print("  ");
delay(100);

//GREEN
digitalWrite(S0,LOW);
digitalWrite(S2,LOW);
digitalWrite(S1,HIGH);
frequency = analogRead(17);
int G = frequency;
Serial.print("G= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print("  ");
delay(100);

//BLUE
digitalWrite(S0,LOW);
digitalWrite(S1,LOW);
digitalWrite(S2,HIGH);
frequency = analogRead(17);
int B = frequency;
Serial.print("B= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.println("  ");
delay(100);
returnservo();
  }
void returnservo(){
  topServo.write(30);
}


texts:
So I am writing code to control a servo with an RC radio. I am using an Arduino Mega.  I get this error whenever I compile.  I am not that experienced with Arduino so I am probably not doing something right. Thanks for the help!

  Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Mega or Mega
  2560, ATmega2560 (Mega 2560)"

  C:\Users\ethan\Desktop\Periferals_control\Periferals_control.ino: In
  function 'void loop()':

  Periferals_control:46: error: expected ';' before '{' token

  {

  ^

  exit status 1 expected ';' before '{' token

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

#include <Servo.h>
Servo servo1;
Servo servo2;
//the following are all ~PWM capable ports
int servoElevator_PwmIn = 6; //Elevator Servo
int servoGrabber_PwmIn = 7; //Grabber Servo

//Channels on AT9
int leftStickVertical = 2; //Channel 3
int rightStickVertical = 3; //Channel 7

int elevatorServoStop = 50;

void setup() {

  //pinMode(servoGrabber_PwmIn, OUTPUT);
  //pinMode(servoElevator_PwmIn, OUTPUT);
  pinMode(leftStickVertical, INPUT);
  pinMode(rightStickVertical, INPUT);
  Serial.begin(9600);

  servo1.attach(6);
  servo2.attach(servoGrabber_PwmIn);
}

void loop() {

  int leftStickVerticalPwm = pulseIn(leftStickVertical, HIGH, 25000);
  int rightStickVerticalPwm = pulseIn(rightStickVertical, HIGH, 25000);
  Serial.print(leftStickVerticalPwm);
  Serial.print("\t");
  Serial.print(rightStickVerticalPwm);
  Serial.print("\n");

  if (rightStickVerticalPwm == 0)
  {
    servo1.write(elevatorServoStop);
  }
  else if (rightStickVerticalPwm > 1500)
  {
    servo1.write(100);
  }
  else (rightStickVerticalPwm < 1400)
  {
    servo1.write(30);
  }
}


texts:
How can I figure out, if an Arduino UNO is defect?
Have on, which I can't upload sketches to.
It's not working on Windows, even on Linux.

Everytime the following warning appears:

avrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_loadaddr(): (a) protocol error, expect=0x14, resp=0x18

avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0x98
avrdude: stk500_cmd(): programmer is out of sync
avr_read(): error reading address 0x0000
    read operation not supported for memory "flash"
avrdude: failed to read all of flash memory, rc=-2
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0xe6

I don't have a clue of how to fix it.
The IDE's version is 1.8.8

Is the Arduino Bricked? Restarting both systems, the Arduino IDE and even Arduino (Reset) didn't help.

~ JackyTech


texts: Random characters transmitted from ESP8266 to Arduino

texts:
Below is  the code for getting a value from Firebase and sending the received data to arduino for performing necessary action.
The code here here sends a string "o" to arduino once

//uploaded to ESP8266
.
.
.
if (cu_st == "c")
  {
    sent = 0;
  }
  cu_st = Firebase.getString("feeder");
   if (cu_st == "o")
   {
    Serial.println("\t\trecd req to feed");
    if(sent == 0)
    {
      esp.print("o");
      sent =1;
      cu_st = "c";
      Serial.println("setting feeder to close in firebase");
      Firebase.setString("feeder" ,"c");

   }
.
.
.

Below is the code that gets the value, carries out necessary actions.

//uploaded to arduino
.
.
.
void feed_cmd()
{
  while(ArduinoUno.available())
  {
    char valve = ArduinoUno.read();
    Serial.print("feeder cmd recd ");
    Serial.println(valve);
    if(valve=='o')
    {
       digitalWrite(led, HIGH);
       //feeder.write(0); //open position
       open_time = millis();
       feeder = 1 ;
       Serial.println("I am opening feeder");
    }
  }
}

void close_feed()
{

  if(feeder == 1)
  {
   close_time = millis();
   if(close_time - open_time > 5000)
  {
    feeder = 0;
    digitalWrite(led , LOW);
    Serial.println("I am closing feeder") ;
  }
  }
}
.
.
.

My expectation/understanding is that:

feed_cmd() continually checks for any data
As soon as it receives data LED turns ON and after 5 sec close_feed() turns OFF the LED.

But what happens is that the while() in feed_cmd() continually executes showing some random data and also all of what I said above is also being carried out! (pic attached)

Why is there random serial data, even after sending only once and even after reading the sent data?

Is it bad coding / hardware?

Thanks for reading through and would really appreciate it if you can help me sort it out!!

Edit I found this link smthg abt pin voltages  when I was looking for possible explanation for my code's behaviour, If somebody can simplify it and explain it, it'd be better !!


texts:
I would like to find an Arduino with built-in Bluetooth.
I know about the HC-06, the shields and the other Bluetooth modules, but i would like to have built in Bluetooth for eliminating the risk for miscommunication on the serial port.

The official Arduino foundation did produce an board but it's retired now.


texts:
I know I can send a newline using the option in the bottom right:

But why doesnt it work to use the option 'No line ending', and send a '\n' or '\r\n' after the text using the arduino serial monitor?


texts: Can one supply an Arduino Zero's VIN pin with 5v?

texts: The title pretty much says it all. I know that most Arduinos can do this, but I couldn't find very much information for the Zero. Any help would be very much appreciated.


texts: Arduino Serial Response is Slow when in While Loop

texts:
Good evening all,

I'm having an issue with a quick "test" project that I am tinkering with (learning the "do's" and "don'ts") the NeoPixel LED strip.  I've been piecing together excerpts from other folks and so far everything is great.

I'm doing it over serial sending switch/case with numbers from the keyboard for different options.  The issue I am currently having is "case 1:", when I hit the "1" key and it fires off, I want to be able to interrupt it immediately by using key "0".  So basically, I'd like it to loop forever after hitting key "1" but terminate after hitting "0".

However, when hitting key "1", then key "0" immediately, the while loop repeats twice, then breaks.  I haven't done any C/C++ since I was 12 and now I'm 38 so now it is all trial and error based so please pardon my syntax.  Any help would be appreciated.

#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>

#define PIN 6
#define LEDs 16

int LED_Fade_Interval = 5;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDs, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  Serial.begin(9600);

  strip.begin();
  strip.show();

}

void loop() {

  while (Serial.available() == 0);

  int numKey = Serial.read() - '0';

  uint32_t low = strip.Color(0, 0, 0);

  switch(numKey)
  {

    case 1:
      Serial.println("LED Strip is ON - BLUE FADE");
      while (numKey != 0)
      {
        int numKey = Serial.read() - '0';
        delay(50);

        ws2812_FadeInOut(0, 0, 255, LED_Fade_Interval);

        if (numKey == 0)
        {

          for( int i = 0; i<LEDs; i++){
            strip.setPixelColor(i, low);
            strip.show();
          }

          break;

        }

      }

    case 0:
      Serial.println("LED Strip is OFF");
      for( int i = 0; i<LEDs; i++){
          strip.setPixelColor(i, low);
          strip.show();
      }
      break;
   }
}

// *******************************************
// FADER Function
// *******************************************
void ws2812_FadeInOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {
  for(uint8_t b = 0; b <255; b++) {
     for(uint8_t i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
     }

     strip.show();
     delay(wait);
  };

  for(uint8_t b=255; b > 0; b--) {
     for(uint8_t i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
     }
     strip.show();
     delay(wait);
  };
};


texts: Check to see that String only contains .csv style numbers

texts:
I'm looking to determine if an Arduino String contains any other character than those that would be in the [number],[number]'\r''\n'where [number] could be positive or negative.

I know I can run a for down the entire string and use if(isDigit([char]) || isWhitespace([char])||[char]=='-') however, I imagine there's a better way to do this.

Could I (for example) convert the String to an array of values and search the array for any value that doesn't correspond to the characters I'm looking for? Or is there a better way to check this out?


texts: Detecting how many button presses(single tap, double tap etc) with two simultaneous buttons

texts:
noob here

So what I am trying to do is output a different number depending on the number of button presses e.g. for 1 button press it should output 1 and so forth. After that I only really want the outputs for 1 to 4 presses. I am using these inputs for a game.  Right now, it does work and counts up until 4 and then resets back to 0. The problem that I am having is it continues after 1 click to 2 clicks; what I want it to do is count 1 click when its clicked once, twice when its clicked twice etc. I am trying to use a debouncing code to distinguish between single tap, double tap, triple tap etc
@VE7JRO kindly provided a great solution to this problem, albeit it was for one button. I am trying to adjust the code to accommodate 2 separate buttons (on separate pins), but it is giving me an error.

This is the code:

#include <Bounce2.h>

// Connect both buttons in series with one connection
// to GND and the other to a digital pin.
const int buttonPin1 = 2;
const int buttonPin2 = 3;

class Button
{
  private:

    int m_buttonPin1;
    int m_buttonPin2;
    int m_counter;
    unsigned long m_buttonPressTimeout;
    unsigned long m_previousMillis;

  public:

    Button(int button):
      m_buttonPin1(buttonPin1),
      m_buttonPin2(buttonPin2),
      m_counter(0),
      m_buttonPressTimeout(1500), // Button press timeout 500 ms.
      m_previousMillis(0){}

    void Update()
    {
      int valA = digitalRead(button1); // read button stateint
      int  valB = digitalRead(button2); // read button state
       if (valA == LOW &&valB == LOW)
       {
      if(m_counter > 0 && millis() - m_previousMillis >= m_buttonPressTimeout)
      {
        Serial.print("Count from Update() just before it's re-set to 0 = ");
        Serial.println(GetCounter());
        m_counter = 0;
      }
    }

    void IncrementCounter(){
      m_counter++;
      if(m_counter > 4){m_counter = 4;}
      if(m_counter == 1){
        m_previousMillis = millis();
      }
    }

    byte GetCounter(){
      return m_counter;
    }

};

Bounce button1Debouncer = Bounce();
Bounce button2Debouncer = Bounce();
Button MyButton(buttonPin1);
Button MyButton(buttonPin2);

void setup(){

  Serial.begin(9600);

  pinMode(buttonPin1, INPUT_PULLUP);
  button1Debouncer.attach(buttonPin);
  button1Debouncer.interval(5);
  pinMode(buttonPin2, INPUT_PULLUP);
  button2Debouncer.attach(buttonPin);
  button2Debouncer.interval(5);

}

void loop(){

  // Call the Update function as fast as possible.
  MyButton.Update();

  // Button pressed.
  if(button1Debouncer.update() && button2Debouncer.update())
  {
    if(button1Debouncer.fell() && button2Debouncer.fell()){
      MyButton.IncrementCounter();
      Serial.print("Count from Button Debouncer = ");
      Serial.println(MyButton.GetCounter());
    }
  }

}
}

The error is: "'buttonPin1' is not a type", I do not understand this error as it didn't give that error for when a single button was used.


texts: Infinite Loop on Pin Input (Teensy 3.1)?

texts:
I have an infinite loop issue that keeps persisting in this code on my Teensy 3.1. This program is intended to take an input on Pin 0 and press the Enter key on the computer it is hooked into.

It is connected to a wire with no current but once a switch is flipped it should send a 5v Digital Signal blip to the Teensy and trigger it to run. It does function but it keeps getting caught in an infinite loop for some reason. Any help would be greatly appreciated!

// Global Variable
int signal_receiving_pin = 0;

void setup() {
  // Outputting for error checking
  Serial.begin(38400);

  // Readying the pin for input
  pinMode(signal_receiving_pin, INPUT);
}

void loop()
{
// If statement to check whether an input has been received
if (digitalRead(signal_receiving_pin) == HIGH)
{
  // If the signal has been detected..
  Serial.println("The signal has been received \n");
  Serial.println("Now sending the ENTER signal \n");

  // .. The ENTER key is sent to the computer
  //Keyboard.press(KEY_ENTER);
  //Keyboard.release(KEY_ENTER);

  // Waiting 1 minute before allowing more input
  //delay(60000); // Pause
}
else
{
  // If the signal is not detected..
  // it will let you know it isn't there
  Serial.println("Input not detected \n");
}
}


texts: Arduino and 127/220 Volts: Relay and Isolation

texts:
I am new to Arduino, also, I am not fluent in english.

I wish to create a controller for several circuits. All of those circuits are "in parallel" with additional circuits.

My question is:

Do a Relay Shield protects the Arduino board from the current and voltage from the power supply?

Suppose the following:

The retangular boxes are "parallel switches" connected to the devices.

R = Power Supply Phase

S = Another Power Supply Phase

N = power Supply Neutral

Arduino, C2 and C3 are 127 Volts, (S+N)

C0 and C1 are 220 Volts (R+S)

Are the Shields safe from oscilations from the eletrical supply?
What / Where / How should I look on what to ground? Local regulations state that I cannot let R and/or S be grounded.


texts:
I have been trying to create a temperature/humidity logger using one of these ESP8266-based dev-kits. I wrote a simple sketch that sends a request to a (working) web server, using GET for simplicity.

Below is the sketch:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <DHTesp.h>

#define ssid "ssid"
#define password "password"

  #define DEVICE_ID 1

DHTesp dht;

void setup() {
  Serial.begin(115200);
  Serial.println("Debug");
  dht.setup(4);
}

void loop() {

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  HTTPClient http;

  float temperature = dht.getTemperature();
  float humidity = dht.getHumidity();

  Serial.println("Measured");

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

  Serial.println("Connected");

  char str_temp[10] = {'-'};
  char str_temp2[10] = {'-'};
  Serial.println(humidity);

  dtostrf(temperature, 2, 2, str_temp);
  dtostrf(humidity, 2, 0, str_temp2);

  char query[400];
  Serial.println(str_temp);

  sprintf(query, "http://192.168.1.198/temp.php?device=%d&temperature=%s&humidity=%s", DEVICE_ID, str_temp, str_temp2);
  Serial.println(query);
  http.begin(query);

  int httpCode = http.GET();

  if (httpCode > 0) {
    Serial.printf("[HTTP] GET... code: %d\n", httpCode);

    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      Serial.println(payload);
    }
  } else {
    Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();
  ESP.deepSleep(60e6);
}

Here is a brief explanation:

When the module powers up, it gets the data from a DHT22 sensor, and sends it to the server. It then goes to sleep for 10 minutes and resets. (D0 and RST are connected)

For some reason, nothing seems to work correctly, I don't even get the first Debug print. BAUD rate is 115200, and this is the Serial output:

  1384, room 16
  tail 8
  chksum sd$⸮⸮|⸮l⸮|⸮$⸮c<ǃ⸮⸮{⸮c⸮#⸮⸮no⸮$g'⸮⸮⸮cp⸮⸮dsd;lx⸮o⸮⸮d⸮⸮co⸮|l⸮⸮c⸮⸮gn⸮dćd⸮ogl n{⸮⸮⸮g⸮⸮ s⸮⸮'⸮⸮sۓnl⸮|⸮⸮ ⸮{⸮o⸮#⸮o#x⸮sd$⸮⸮|⸮l⸮|⸮$⸮c|ǃ⸮⸮{⸮c⸮b⸮⸮ng⸮$gn⸮⸮⸮cp⸮⸮dsdrd8⸮o⸮⸮$⸮⸮#g⸮|l⸮⸮c⸮⸮'o⸮d⸮⸮d⸮g'lo;⸮⸮⸮g⸮⸮s⸮⸮'⸮⸮{ۓol⸮|⸮⸮⸮{⸮⸮o⸮#⸮g#x⸮sdlܟ<⸮l⸮<⸮l⸮c|⸮⸮⸮⸮{⸮c⸮b⸮⸮og⸮lgn⸮⸮⸮cp⸮⸮dsdsd8⸮g⸮⸮$⸮⸮#g⸮|d⸮⸮c⸮⸮'o⸮d⸮⸮$⸮g'lo;Ǜ⸮'⸮⸮s⸮⸮n⸮⸮{⸮⸮ol⸮|⸮⸮⸮;⸮⸮g⸮b⸮gbx⸮{ll⸮⸮|⸮d⸮|⸮l⸮c|⸮⸮⸮⸮r⸮c⸮c⸮⸮g'⸮lno⸮⸮⸮b8x⸮⸮l{l{${ll⸮⸮|⸮d⸮|⸮l⸮#|⸮⸮⸮⸮r⸮#⸮c⸮⸮gn⸮log⸮⸮⸮bx⸮⸮l;l{$p⸮'⸮⸮l⸮⸮cn⸮|$⸮⸮b⸮⸮og⸮l⸮⸮l ⸮no$gs⸮ۓo⸮⸮;⸮⸮o⸮⸮⸮r⸮⸮gd⸮|⸮⸮⸮s⸮⸮'⸮c⸮ncp⸮

Where the random code inserts are just characters and nothing special.


texts: UNO analog input voltage reading not accurate

texts:
My loop code is this:

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(float(sensorValue*5000.0/1023));
delay(1);        // delay in between reads for stability

When I read 5V it gives 5000 mV. When I read 3.3V pin it gives 3211 mV. When I read 1442 mV battery it gives 1392. What do you think about this situation?

NOTE: There is no any additive circuit. Just wires.


texts: Trouble uploading sketch / error in sketch

texts:
I am following this tutorial of a very basic serial communication between 2 arduino unos.

I have made the connections as given and connected the arduino unos to 2 separate laptops via USB.

Code1:

char mystr[3] = "Hello"; //String data

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
}

void loop() {
  Serial.write(mystr,5); //Write the serial data
  delay(1000);
}

Code 2:

char mystr[5]; //Initialized variable to store recieved data

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
}

void loop() {
  Serial.readBytes(mystr,5); //Read the serial data and store in var
  delay(1000);
}

Error on arduino following code 1:

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

Sketch uses 1602 bytes (4%) of program storage space. Maximum is 32256 bytes.
Global variables use 188 bytes (9%) of dynamic memory, leaving 1860 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
An error occurred while uploading the sketch

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

Arduino running code 2 is stuck on the uploading and does not fininsh uploading.

The solutions on the internet only talk of the scenarios where the arduino is having trouble communication with the computer and so the solutions given are:

check com port
check that correct board is selected
do not insert the arduinos in usb 3
press reset button

None of these is my problem as I have checked them all. The arduinos themselves are working fine. I have a very strong feeling that there is a problem with the pins 0 and 1, i.e. with serial comm.

Please help.


texts: Reading data by port manipulation (Arduino Due)

texts:
I have shorted the 23rd pin of port A with 3.3v output pin (i.e. tieing 23rd pin of port A to logic high). Now I am trying to read the 23rd pin of port A by using following code-

void setup() {
  Serial.begin(9600); // put your setup code here, to run once:
  char print_str[40];
  REG_PIOA_PER = 0x00800000;   //Write 1's to A register pins to override other peripherals and allow GPIO use for pins
  REG_PIOA_ODR = 0x00800000;   //Set A register pins to INPUT
  sprintf(print_str, "\n%08X", REG_PIOA_PDSR);
  Serial.println(print_str);
}

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

According to the code, the serial output should be 0x00800000. But I am always getting 0. Could you please tell me, what is going wrong?


texts: Using TX/RX serial pins to communicate over USB

texts:
I'm using an Arduino Nano with an Atmega 328p.
I would like to attach and use a different USB port instead of the builtin one for supplying power, serial debugging and uploading code.
Currently my board is recieving power from the USB port using vin, but I would like to know how I can get the Arduino to use serial communication with the TX/RX pins and the data+ and data- pins on the USB. I'm especially interested in knowing if I can upload new code to the board through TX/RX.
The official page for the Nano says that the serial communication is handled by an FTDI FT232RL chip, which as I understand, translates the signal from the builtin USB to serial. Is there any way that I can use this chip to communicate over the TX/RX pins instead of builtin USB?
Online documentation about this subject is really lacking, and of the few opinions that I've found, many are conflicting. I would really appreciate any help with this, thanks.


texts:
I'm having some problems with my ESP8266 stopping transmission of MQTT messages after a while.
Therefore I'm writing some error handling messages, and I want to publish some AT data to MQTT.

It's probably a simple solution, but how can I, though the code, send AT messages from my 'own' device?
Also, does AT messages get parsed at a higher level than any other user input, so it can't get stuck in any user made input loop?

Many thanks!


texts: Arduino - Playing WAV files with a buzzer

texts:
I have developed an Arduino program that plays a WAV file from the SD card using a speaker.

This is the circuit schematic

The sketch I'm using is based on TMRpcm library and PWM output

#include <TMRpcm.h>
#include <SD.h>
#include <SPI.h>
int sdpin=10;
TMRpcm tmrpcm;

void setup()
{
    Serial.begin(9600);
    pinMode(sdpin, OUTPUT);
    tmrpcm.speakerPin=9;
    tmrpcm.setVolume(3);
    SD.begin();
}

void loop()
{
    if(Serial.available()>0)
    {
        String data=Serial.readString();
        if(data=="pause")
        {
            if(tmrpcm.isPlaying()==1)
            {
                tmrpcm.pause();
            }
        }
        else if(data=="stop")
        {
            if(tmrpcm.isPlaying()==1)
            {
                tmrpcm.stopPlayback();
            }
        }
        else
        {
            String path="/Music/"+data;
            if(tmrpcm.isPlaying()==1)
            {
                tmrpcm.stopPlayback();
            }
            tmrpcm.play(path.c_str());
        }
    }
}

At first I could play the music with the speaker but then it stopped working and because I don't have enough skill to make one myself, I would like to know if I can use a buzzer for that.

I know that buzzers can be used to generate melody using the tone() function but I'm not sure if I can use them to play wav files using PWM output.

Any help will be appreciated.


texts:
Adafruit carries a number of Bluetooth LE 4.0 modules in their store, notably the SPI (https://www.adafruit.com/products/2633) and UART (https://www.adafruit.com/product/2479) version. I have used the NRF24L01 module with ATtiny85 via SPI to transmit data in the past, and this uses 3 pins. I used the following setup to do so: https://www.hackster.io/arjun/nrf24l01-with-attiny85-3-pins-74a1f2.

My previous system consisted of ATtiny85s communicating with a receiver (Bluefruit Feather) via NRF24L01 radios. As the receiver got data, it sent it to an iPhone app that I wrote. Now, I would like to cut out this receiver and BLE straight to the iPhone, which supports multiple peripheral connections.

However, unlike the RF24 library, the Adafruit BLE SPI library needs the actual SPI library to compile correctly, which for some reason the RF24 library (this version: http://tmrh20.github.io/RF24/) doesn't. I don't quite get how the RF24 library can compile fine without the SPI library when targeting the ATtiny85 - Is there some way to get this to work similar to the RF24 library?

Alternatively, I think there is a way to do software UART on ATtiny85, which I know nothing about, so if there truly is no way to do SPI is UART possible?

I realize that this is a question best asked to Adafruit, which I have done, but I thought I'd post it here and see if anyone can help.

Thanks,
Alex


texts: Compute SHA256 of string and output to string

texts:
In my Arduino project I want to compute the SHA256 hash of a string and store the result to a string, and do this recursively many times (i.e. compute hash of hash of hash etc...). So my goal is to have a reliable function as follows:

String h(String input) {
...
return output;
}

where for example h("abc") would return "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad".

I downloaded this library
(from Tools->Manage libraries, it is also in github) and then ran the example in TestSHA256.ino which passes all the checks. However I'm stuggling to make my function work since the library doesn't have a specific example on how to compute and return a SHA256 hash.

I have been looking in function testHash_N() in TestSHA256.ino, which appears to create a hash (from struct TestHashVector data) and compare it with the precomputed hash (from struct TestHashVector hash[]).

The hash seems to be computed in lines 89-96 in TestSHA256.ino.  I just want to take the actual hash string result, so for testVectorSHA256_1  in the example, I would need to have a string = "ba7816bf....15ad" as the result.

I understand that this is related to memory referencing in Arduino but I'm not experienced so I'd be grateful if you helped me with this.

EDIT: My code snippet so far is as follows, but it doesn't output the correct hash..

#include <Crypto.h>
#include <SHA256.h>
#include <string.h>

#define HASH_SIZE 32
#define BLOCK_SIZE 64

char hex[256];

char *hashvalue;

SHA256 sha256;

byte buffer[128];

char *btoh(char *dest, uint8_t *src, int len) {
  char *d = dest;
  while( len-- ) sprintf(d, "%02x", (unsigned char)*src++), d += 2;
  return dest;
}

char* h(Hash *hash, char* hashvalue)
{
    size_t size = sizeof(&hashvalue);
    size_t posn, len;
    size_t inc = sizeof(&hashvalue);
    uint8_t value[HASH_SIZE];

    hash->reset();
    for (posn = 0; posn < size; posn += inc) {
        len = size - posn;
        if (len > inc)
            len = inc;
        hash->update(&hashvalue + posn, len);
    }
    hash->finalize(value, sizeof(value));

    return(btoh(hex, value, 32));
}

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

    bool tmp;
    char *testvalue = "abc";
    Serial.println(h(&sha256,*testvalue));

}

void loop()
{
}


texts: ESP8266 Programming using ESP-01 to USB converter

texts:
I am new to ESP8266. To ease out the task of programming esp8266, I bought this:  ESP-01 ESP8266 Programmer CH340G Chip USB WiFi Wireless UART GPIO0 Adapter.

Configured Arduino Interface to run AT commands in the serial monitor.
I flashed ESP8266 with the basic blink LED example. It worked fine for some time and later on gave this error.

warning: espcomm_sync failed

When i tried to flash another program on to ESP8266, I am getting the following error.

Sketch uses 221,995 bytes (51%) of program storage space. Maximum is 434,160 bytes.
Global variables use 31,568 bytes (38%) of dynamic memory, leaving 50,352 bytes for local variables. Maximum is 81,920 bytes.
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

I could only find one article regarding this adapter.
There he made a custom bridge soldering GPIO 0 to GND for ESP8266 Flashing.

So should i make a removable bridge for the same, to upload a new program.
Is there any other way to simplify this task?


texts: Inheritance: error in calling the constructor of the base class?

texts:
I want to write a library for the RGBDigit shield (http://rgbdigit.com/), which essentially is an Adafruit Neopixel strip, packed as a 7 segment display. The shield also has a DS3231 clock and an IR receiver.

So my plan was to make a class RGBDigit, which inherits from the Adafruit_NeoPixel class and add private objects DS3231 and IRrecv.

This is my RGBDigit.h:

#ifndef RGBDigit_h
#define RGBDigit_h

#include <Arduino.h>
#include "Wire.h"
#include "../Adafruit_NeoPixel/Adafruit_NeoPixel.h"
#include "../IRremote/IRremote.h"
#include "../DS3231/DS3231.h"

class RGBDigit : public Adafruit_NeoPixel {
    public:
        RGBDigit(int nDigits);
        ~RGBDigit();
    private:
        int _nDigits;
        DS3231 _clock;
        IRrecv* _ir;
};

#endif

This is RGBDigit.cpp:

#include "RGBDigit.h"

RGBDigit::RGBDigit(int nDigits)
    : Adafruit_NeoPixel(8 * nDigits, 12, NEO_GRB + NEO_KHZ800),
    _nDigits(nDigits)
{
    _ir = new IRrecv(10);
    _ir->enableIRIn(); // Start the receiver
    Adafruit_NeoPixel::begin();
}

RGBDigit::~RGBDigit()
{
    delete _ir;
}

And this is my Arduino sketch:

#include <Wire.h>
#include <RGBDigit.h>

RGBDigit display = RGBDigit(4);

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

}

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

}

I get al lot of "undefined reference" errors:

RGBDigit/RGBDigit.cpp.o: In function `RGBDigit::RGBDigit(int)':
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:23: undefined reference to `Adafruit_NeoPixel::Adafruit_NeoPixel(unsigned int, unsigned char, unsigned char)'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:23: undefined reference to `DS3231::DS3231()'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:25: undefined reference to `IRrecv::IRrecv(int)'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:26: undefined reference to `IRrecv::enableIRIn()'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:27: undefined reference to `Adafruit_NeoPixel::begin()'
RGBDigit/RGBDigit.cpp.o: In function `RGBDigit::~RGBDigit()':
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:30: undefined reference to `Adafruit_NeoPixel::~Adafruit_NeoPixel()'
collect2: error: ld returned 1 exit status

But I don' t understand why. What am I doing wrong?


texts: How to code an arduino to execute a particular code using a slide switch

texts: I’m pretty new to arduino. I need help concerning a project I’m making. I’m using a SPDT slide switch to switch between what code(method) should be executed.i.e when I shift the switch to the left, XXX method should be executed and when I move the switch to the right, YYYY method should be executed. The center pin of the switch is connected to arduino +5v while the     left and right leg of the switch are connected like how a tactile switch is interfaces with the arduino. Please can anyone help me with the code, or at least how to program the arduino? Thank you


texts: How to I connect the pins of one channel relay to control and led which is connected to pin 13 of an arduino uno.can you tell me the steps which pin will go to which pin


texts: Interfacing Arduino Uno with OV7670 (with FIFO)?

texts:
I need help with interfacing ov7670 to Aduino Uno. I know there is a lot of literature available but the problem is that all this literature is for ov7670 without FIFO. I have Ov7670 with FIFO and its a 22-pin image sensor. I haven't been able to relate the available tutorials to my module. Any help in this regard is appreciated. (I need Wire Configuration as well as Code to get images).
Kind Regards,


texts: speed motor test with IR sensor and PID algorithm

texts:
I'm trying to control motor speed (RPM) using an IR sensor , All I've done is to control it without PID algorithm . and it works . can someone help me with implantation with PID . I'm using Arduino Uno , L298n motor driver , IR sensor and LCD display .

here you can see the circuit :
Circuit
and also this is the code without PID algorithm :

#include<LiquidCrystal.h>
LiquidCrystal lcd(A5,A4,A3,A2,A1,A0);
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
volatile byte REV;
unsigned long int rpm,RPM;
unsigned long st=0;
unsigned long time;
int ledPin = 13;
int led = 0,RPMlen , prevRPM;
int flag = 0;
int flag1=1;
#define bladesInFan 2
float radius=1.9685;   // inch
int preSteps=0;
float stepAngle= 360.0/(float)stepsPerRevolution;
float minSpeed=0;
float maxSpeed=280.0;
float minSteps=0;
float maxSteps=maxSpeed/stepAngle;

void setup()
{
  myStepper.setSpeed(60);
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  lcd.begin(16,2);
  lcd.print("Speedometer");
  delay(2000);
  attachInterrupt(0, RPMCount, RISING);
 }

  void loop()
  {
    readRPM();
    radius=((radius * 2.54)/100.0);  // convering in meter
    int Speed= ((float)RPM * 60.0 * (2.0 * 3.14 *
        radius)/1000.0);
    // RPM in 60 minute, diameter of tyre (2pi r) r is radius,
    1000 to convert in km
    int Steps=map(Speed, minSpeed,maxSpeed,minSteps,maxSteps);

    if(flag1)
    {
       Serial.print(Speed);
       Serial.println("Kmh");
       lcd.setCursor(0,0);
       lcd.print("RPM: ");
       lcd.print(RPM);
       lcd.print("           ");
       lcd.setCursor(0,1);
       lcd.print("Speed: ");
       lcd.print(Speed);
       lcd.print(" Km/h       ");
       flag1=0;
   }
   int currSteps=Steps;
   int steps= currSteps-preSteps;
   preSteps=currSteps;
   myStepper.step(steps);
}

 int readRPM()
 {
    if(REV >= 10 or millis()>=st+1000)                  //  IT
   WILL UPDATE AFETR EVERY 10 READINGS or 1 second in idle
    {
        if(flag==0)
           flag=1;
           rpm = (60/2)*(1000/(millis() - time))*REV/bladesInFan;
           time = millis();
           REV = 0;
           int x= rpm;
           while(x!=0)
           {
              x = x/10;
              RPMlen++;
            }
            Serial.println(rpm,DEC);
            RPM=rpm;
            delay(500);
            st=millis();
            flag1=1;
           }
        }

void RPMCount()
 {
   REV++;
   if (led == LOW)
 {
   led = HIGH;
 }
  else
 {
    led = LOW;
  }
 digitalWrite(ledPin, led);
}

here is the source

thanks


texts:
Is there a simple way to rig two balls in a way that lets you know if they are touching?

For example, here's a bad idea. Put a free-to-move magnet inside of each ball. When the balls get close, the magnets snap together. Use a magnetic sensor within each ball to tell the direction of the magnet. Use an accelerometer to tell the direction of gravity. When the gravity direction differs from the magnet direction, the balls are touching.

I don't need to know the direction of the contact (that would be ideal, but I don't need it). It should work over the whole surface. I would like to have more than two balls and be able to tell which two are touching. I can make the balls however I want.

(Even very basic advice would be quite helpful. I'm not familiar at all with hardware projects or what kinds of sensors are available or how to combine the available pieces into some desired thing. That includes advice like "this is probably too hard".)


texts:
I was trying for one month to make multiple RC522 rfid readers work together on SPI on an arduino yun, one works fine, but if I plug 4, each with a specific slave select, only one, sometimes 2, sometimes none are working.

The library i use is RFID.h (i think the miguelbalboa one) , but I had the same results with MFRC522.h wich have a specific readUidMultiReader so I dont think my code is at fault.

Searching for this issue, I found this question wich is basically my issue, as I suspect the readers I bought are not supporting multidrop. These readers dont work either.

I read about solutions using multiplexers for SPI lines, tristate buffers on miso lines and/or diodes but these are workarounds, and there should be a more straightforward solution.

Also I tested with no resistors most of the time, but tried putting 10kΩ from all MISO to 3v3, no change, as i really dont understand what their use are, even if I feel they could be mandatory.

I am using a yun for the builtin ethernet, because I tried nanos with ethernet shields and again the shields are ignoring the Slave select and thus not working with spi multidrop, so each time I plugged the shield on nano, even not using it, rfid stopped working.