texts:
My first question here.
As an example, I'm using https://howtomechatronics.com/tutorials/arduino/how-to-control-ws2812b-individually-addressable-leds-using-arduino/ code to control my lighting, which I'm going to install to my car, just my code was a bit simplified, but I left the line, where brightness is being controlled and here's the fun part. When trying to change the brightness, it changes inconsistently. When increasing, it gets a bit brighter then a bit dimmer and at some spots it just turns off, when it should be bright. I'm also new to Arduino, so don't really know how Arduino reads these values, but maybe there is some other way to control brightness?

#include <SoftwareSerial.h>
#include <FastLED.h>
#define NUM_LEDS 20
#define PIN 5
CRGB leds[NUM_LEDS];
int brightness = 155;
//int fadeAmount = 5;
SoftwareSerial BT(0,1);
String dataIn = "";

void setup() {

  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(brightness);
  Serial.begin(9600);
  BT.begin(9600);
  setAll(50, 50, 50);
}

void loop() {

  if (BT.available() > 0) {
    dataIn = BT.readString();
    delay(10);
    FastLED.show();
  }
    if (dataIn.startsWith("0")) {
        setAll(0,0,0);
        delay(10);
    FastLED.show();
    }
    else if (dataIn.startsWith("w")) {
        setAll(255,255,255);
        delay(10);
    FastLED.show();
    }
    else if (dataIn.startsWith("r")) {
        setAll(0,255,0);
        delay(10);
    FastLED.show();
    }
    else if (dataIn.startsWith("g")) {
        setAll(255,0,0);
        delay(10);
    FastLED.show();
    }
    else if (dataIn.startsWith("b")) {
        setAll(0,0,255);
        delay(10);
    FastLED.show();
    }
    else if (dataIn.startsWith("y")) {
        setAll(200,255,0);
    }
    else if (dataIn.startsWith("1")) { //This is the brightness lines
      String stringBrightness = dataIn.substring(dataIn.indexOf("1") + 1);
      brightness = stringBrightness.toInt();
      FastLED.setBrightness(brightness);
      FastLED.show();
    }
  }

void showStrip() {
   FastLED.show();
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}


texts: Can't use Arduino nano as ISP because it can't read the Device signature

texts:
I programmed the 8mhz internal oscillator Bootloader to a new Arduino Nano with another Arduino nano running the ISP Sketch, wich worked fine the first time(Arduino as ISP selected as programmer).
(I wanted to test it befor i want to burn this Bootloader on an Empty 328p-au uC.)
But now since I received the 328p-au uC's i tried the same thing, to burn the Bootloader to the epty uC's but somehow it can't read the device signature, neither from a fresh arduino Nano or another avr(At least that is what avrdude said). I wired everything exectly like it was written in the ISP Sketch.

Here is one of the error messages i received when I was trining to Burn the standard 16mhz Bootloader:

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

     Fehler beim Brennen des Bootloaders.
     avrdude: AVR device initialized and ready to accept instructions

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

     avrdude: Device signature = 0xff0000
     avrdude: Expected signature for ATmega328P is 1E 95 0F
     Double check chip, or use -F to override this check.

     avrdude done.  Thank you.

So what am I doing wrong?
(Using -F is what I tried but it didn't work, except the first time I programmed the 8Mhz Int. Oscillator Bootloader)

What stand out to me is that there was nothing happening on the MISO line. Here is a screenshot from my Logic Aalyzer software: ibb.co/hWXrpp7

And here is an Image of my setup(the right Arduino is the programmer and the left one has the empty uC soldered onto it): https://ibb.co/zXQFmwR
I am relative new to Arduino, so I hope some of you can help me with that.


texts: Arduino software won't open in Mac OSX 10.10.1

texts:
I am having trouble opening the Arduino software on my mac, since I have updated Java to version 8 the Arduino software won't open. It does not give an error just closes instantly.

I have tried getting the newest version of the Arduino.cc site but no change.

Can anyone tell me how to open Arduino using an older version of Java?


texts: Standard Practice for including custom library in examples folder

texts:
I have created my custom library with examples folder in them. The main header file is ABC_Node.h. I am referring the structure of Adafruit libraries for Arduino and in some repos under the examples folder I found a conflict for the inclusion of their header files.

Example

in some repos. they use double quotes ("") for including their header files e.g. #include "Adafruit_SHT31.h"
SHT31test.ino

on the contrary, in their BNO055 Arduino library they use brackets (<>) #include <Adafruit_BNO055.h> BNO055 Bunny sketch

I locally tested my library on the IDE and I have examples in which my library is in #include "ABC_Node.h" and it compiles without a problem.

Soon I wish to make the repository public and want to know if there is a standard practice for including header files for examples.


texts: Change RF Receiver Frequency by Antenna Length

texts:
This may be a very stupid question, but I have got me one of those cheap 433 MHz RF modules for the Arduino.
I'm wondering if I can vary the receiver's frequency by simply changing the length of the antenna? Or does the circuit limit the frequency band to 433 MHz?

Thanks in advance.


texts: Arduino uno board is not responsing back while uploading sketch. I tried to upload a sketch Rx LED was blinking but Tx LED was not blinking.


texts: I2C device responding, but data is nacked

texts:
I'm working on a project where I have to communicate to several devices over I2C using a Genuino 101. Now I'm trying to get data off the bus but wire.available() stays at 0, even though my trace clearly shows there's data being sent.

with the following timings

Because the wire is never available my readbuf will always be empty.
Rdbuf[0] is: 0 Hex is: 0
Rdbuf[1] is: 0 Hex is: 0

I'm using the following code to read from the I2C bus.
void i2cRead(unsigned char device, unsigned char memory, int len, unsigned char * rdBuf) {
  ushort memstart = memory;
  bool available = true;;
  while (len > 0 && available) {
    available = false;
    ushort blockSize;
    /*If the number of bytes is smaller than the block size, read that size*/
    (len < RD_BLCK_SIZE) ? blockSize = len : blockSize = RD_BLCK_SIZE;
    Wire.beginTransmission(static_cast<int>(device));
    //send i2c START command
    Wire.write(memory);
    //Write memory address
    Wire.endTransmission();
    //send i2c STOP command
    Wire.requestFrom(static_cast<int>(device), blockSize,true);
    //Request blockSize bytes from the device
    /* for every byte in the response add that byte to the read buffer */
    while (Wire.available() && (len != 0)) {
      available = true;
      rdBuf[memory - memstart] = Wire.read();
      memory++;
      len--;
    }
  }
}

I'm not quite sure what I'm doing wrong, any help would be much appreciated.
Edit:
Below is an image of the current (minimal) setup. On the left there's the board with the ADC and multiplexer visible.

The third set of wires goes to my protocol analyzer.


texts:
I'm trying to use the sketch bellow to work with my WeMos D1 mini (ESP8266 Arduino platform) together with Rotary Encoder KY-040 or MJKDZ, and it's not working for some reason, but the same sketch is working great on the Arduino Uno (with different pin assignment - 2, 3, 4).

Can someone explain to me what is the issue with the sketch?

const int PinA = 14; // Used for generating interrupts using CLK signal
const int PinB = 12; // Used for reading DT signal
const int PinSW = 13; // Used for the push button switch

int lCnt = 0; // Keep track of last rotary value
volatile int vPos = 0; // Updated by the ISR (Interrupt Service Routine)

void isr_event ()  {
  static unsigned long lIsrTmr = 0; // Last Interrupt time
  unsigned long IsrTmr = millis(); // Interrupt time

  // If interrupts come faster than 5ms, assume it's a bounce and ignore
  if (IsrTmr - lIsrTmr > 5) {
    if (digitalRead(PinB) == LOW)
    {
      vPos++ ; // Could be +5 or +10
    }
    else {
      vPos-- ; // Could be -5 or -10
    }

    // Restrict value from 0 to +100
    vPos = min(10, max(0, vPos));

    // Keep track of when we were here last (no more than every 5ms)
    lIsrTmr = IsrTmr;
  }
}

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

  // Rotary pulses are INPUTs
  pinMode(PinA, INPUT);
  pinMode(PinB, INPUT);

  pinMode(PinSW, INPUT_PULLUP); // Switch is floating so use the in-built PULLUP so we don't need a resistor

  attachInterrupt(digitalPinToInterrupt(PinA), isr_event, LOW); // Attach the routine to service the interrupts

  Serial.println(F("Starting..."));  // Ready to go!
}

void loop()
{

  // Is someone pressing the rotary switch?
  if ((!digitalRead(PinSW))) {
    vPos = 0;
    while (!digitalRead(PinSW))
      delay(10);
  }

  // If the current rotary switch position has changed then update everything
  if (vPos != lCnt) {
    // Write out to serial monitor the value and direction
    Serial.println(vPos);
    // Keep track of this new value
    lCnt = vPos ;
  }
}


texts:
I want to get data from ESP to my Arduino. I added firmware v2 to my ESP and it works correctly in my serial USB to TTL and shows the JSON data that I send to it.

But when I connect to my Uno serial it shows some unknown chars.

#include <SoftwareSerial.h> //Including the software serial library
#define DEBUG true
SoftwareSerial esp8266(2, 3); // This will make the Arduino pin 2 as the RX pin and Arduino pin 3 as the TX. Software UART
/* So you have to connect the TX of the esp8266 to the pin 2 of the Arduino and the TX of the esp8266 to the pin 3 of the Arduino. This means that you need to connect the TX line from the esp to the Arduino's pin 2 */

void setup() {
  Serial.begin(115200); // Setting the baudrate to 9600
  esp8266.begin(115200); // Set it according to your esp’s baudrate. Different esp’s have different baud rates.
  pinMode(11, OUTPUT); // Setting the pin 11 as the output pin.
  digitalWrite(11, LOW); // Making it low.
  pinMode(12, OUTPUT); // Setting the pin 12 as the output pin..
  digitalWrite(12, LOW); // Making pin 12 low.
  pinMode(13, OUTPUT); // Setting the pin 13 as the output pin.
  digitalWrite(13, LOW); // Making pin 13 low.
  sendData("AT+RST\r\n", 2000, DEBUG); //This command will reset module to default
  sendData("AT+CWMODE=2\r\n", 1000, DEBUG); // This will configure the mode as access point
  sendData("AT+CIFSR\r\n", 1000, DEBUG); // This will get ip address and will show it
  sendData("AT+CIPMUX=1\r\n", 1000, DEBUG); // This will configure the ESP8266 for multiple connections
  sendData("AT+CIPSERVER=1,80\r\n", 1000, DEBUG); // This will set the server on port 80
}

void loop() {
  if (esp8266.available()) {
    // Checking that whether the esp8266 is sending a message or not (Software UART Data)
    while (esp8266.available()) {
      // Checking whether ESP8266 has received the data or not
      char c = esp8266.read(); // Read the next character.
      Serial.print(c);
      // Storing the response from the ESP8266
    }
  }
}

String sendData(String command, const int timeout, boolean debug) {
  // Function to send the data to the esp8266
  String response = "";
  esp8266.print(command); // Send the command to the ESP8266
  long int time = millis();
  while ((time + timeout) > millis()) {
    // ESP8266 will wait for some time for the data to receive
    while (esp8266.available()) {
      // Checking whether ESP8266 has received the data or not
      char c = esp8266.read(); // Read the next character.
      response += c; // Storing the response from the ESP8266
    }
  }
  if (debug) {
    Serial.print(response);
   // Printing the response of the ESP8266 on the serial monitor.
  }
  return response;
}

Prints this for me:

???AR)?WS?TZ?eO?C?AJ+CIFSR
+CIFSR:APHP,"192.168.4.1"
+CIFSQ:APMAC,"62:01:94:22:96:7e"

OK
AZ??R????jC?u?H?AT+CIPSERVDR=1,80

OK
0,CONNECT

+IPD,0,385:POST / HTTP/1.1
cache-control: no-cache
Postman-Token; 45494ff7-b3e1-400f-8afc-fcda26514705
Content,Type: application/jsonUser-Agent: PostmanRunthme/6.1.6
@ccept: */*Host: 192.178.4.1
accept-encoding: gzip, defl`te
content,length: 14Connection: keep-alive
{"name":"`li"}0,CLOSED

My correct JSON is: {"name":"ali"}. But it shows incorrectly. And I set the mt serial library to #define _SS_MAX_RX_BUFF 1024.

How can I fix this?

My connection is:


texts: Use Print library to set string variable

texts: I need a function that has the basic functionality of the Print library, accepting different kinds of argument types and parsing them. However, I would like to then store the result in a string/char array. Does anybody know how I might utilize the Print library to do so?


texts:
I would like to create an array of a generic type so I can use multiple sensors and make my code as extensible as possible.

/*
  Planning for good design. Agent library
  should be able to use more than one sensor.

  The agent's constructor will accept a vector
  of sensors.
*/
class Sensor
{
 public:
  Sensor(){};
};

My implementation class

#include "Arduino.h"

class UltraSonicSensor: public Sensor {
 public:
  /*
    Constructors
   */
  UltraSonicSensor(){};
  UltraSonicSensor(int pin){
    pin_ = pin;
  };
  int Sense(){ return 20;};
  /*
    Measure Distance
   */
  float DistanceMeasure(void);
 private:
  /*
    Class only suppports Metric
   */
  float microseconds_to_centimeters(void);
  int pin_;
  long duration_;
};

#endif // SROBOT_SENSORS_ULTRASONIC_H_

I have tried many, many variations of this code but always the same error

Sensor *sensors[2];

UltraSonicSensor uSensor;
sensors[0] = &uSensor;

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

void loop(){
  Serial.println("starting...");
  delay(1000);
  Serial.println("ok");
//  delay(2000);
//  for (int i = 0; i < sensors.size(); i++) {
////    sensors[i].Sense();
//  }
}

The error is always a variation of

main:10: error: 'sensors' does not name a type
 sensors[0] = &uSensor;
 ^
exit status 1
'sensors' does not name a type

I also used the code for a small replacement vector class but also the same error


texts:
I'm using this working library to extract H2 & Alcohol in PPM from sensors.
UPDATE
I read the readme file and used the example shown.
But this gives me an error.
This is the code:
  //Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define         Board                   ("Arduino UNO")
#define         Pin                     (A4)  //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define         Type                    ("MQ-4") //MQ4
#define         Voltage_Resolution      (5)
#define         ADC_Bit_Resolution      (10) // For arduino UNO/MEGA/NANO
#define         RatioMQ4CleanAir        (4.4) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
// Setup
MQ4.setRegressionMethod("Exponential"); //_PPM =  a*ratio^b
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
MQ4.setR0(3.86018237); // Value getted on calibration
// Loop
MQ4.init();
MQ4.update();
float ppmCH4 = MQ4.readSensor();

And the error:
Arduino: 1.8.13 (Mac OS X), Board: "WeMos D1 R1, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600"
MQ4:17:1: error: 'MQ4' does not name a type
MQ4.setRegressionMethod("Exponential"); //_PPM =  a*ratio^b
^
MQ4:18:1: error: 'MQ4' does not name a type
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
^
MQ4:18:19: error: 'MQ4' does not name a type
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
^
MQ4:19:1: error: 'MQ4' does not name a type
MQ4.setR0(3.86018237); // Value getted on calibration
^
MQ4:21:1: error: 'MQ4' does not name a type
MQ4.init();
^
MQ4:22:1: error: 'MQ4' does not name a type
MQ4.update();
^
exit status 1
'MQ4' does not name a type


texts: How to use bitset/read on 16bit numbers (Arduino)

texts:
I'm working on an Arduino powered Tetris game. To keep track of the pieces that have fallen and become fixed I have an array of bytes

byte theGrid[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
...

This works great when the well is only 8 LEDs wide, but I need it to be 16 wide. Is there a way to perform bitwise operations on a 16 bit number, like a short? I tried just declaring theGrid as a short, but I'm getting this error no matter what I do.

tetris:62: error: 'B0000000000000000' was not declared in this scope

The reason I was using byte is so I could use bitread and bitset. So if an L piece comes down and lands, I can bitset the appropriate bits like this

bitSet(theGrid[pixelY], 15-pixelX);

and end up with

B1000000000000000, B1110000000000000


texts: Do all Arduino Mega2560's have the same VID/PID identification numbers when seen by a PC as a device? I am planning on designing I specific driver to work with the 2560 and wondering if I will be able to use the same driver for multiple Arduino. Can anyone confirm this? Thanks!


texts:
I have 2 arduino nano and have setup them as a transmitter and reciever. I press a button on the transmitter and the reciever lights up the individual addressable LED sequence as programmed.

The issue is that when I release the button, the signal is sent 3 to 4 times even when the switch is open, this causes the LED sequence to run thrice before returning to the original state. I also tried to ads a delay to remove the bouncing but still no luck.


texts:
I've created a custom pcb with a Atmega328pb cpu.
It's said to be binary compatible with Atmega32p, thus i flash it with my already functioning sketches that i've developed using an arduino.

The thing is that i have a double that i try to cast to int and when i do, it crashes the processor.

The code works perfectly fine on 328p so i'm wondering whether it could be a compiler issue, hardware issue, fuse settings issue.

double globalDouble = 0.0;

void arne() {
  int stuff = globalDouble;
  // program execution halted…
}

The board manager does not include 328pb bit but https://www.pololu.com/ has board config for it, so has http://github.com/watterott/ATmega328PB-Testing, but they make no difference. Still halts.
Any clues on how to move forward? I could ask the factory to replace it with a 328p but i'de rather have my already made products work.

Thank you!


texts: Arduino restarts when a function is called

texts:
When I call a function, get_split(), the Arduino restarts. I have tried to find what is causing this, but I have had no luck. Here is my code:

std::vector<std::vector<std::vector<std::vector<float>>>> get_split(std::vector< std::vector< float > >& dataset) {
  std::vector<int> class_values; // declares vector 'class_values'
  for (int i = 0; i < dataset.size(); i++) { // loops through each value in dataset (the dataset contains vectors)  and appends the last value in each vector to class_values
    class_values.push_back(dataset[i][dataset.size()]);
  }
  std::vector<std::vector<std::vector<float>>> b_index;
  b_index.push_back(std::vector<std::vector<float>>(999));
  std::vector<std::vector<std::vector<float>>> b_value;
  b_value.push_back(std::vector<std::vector<float>>(999));
  std::vector<std::vector<std::vector<float>>> b_score;
  b_score.push_back(std::vector<std::vector<float>>(999));
  std::vector<std::vector<std::vector<float>>> b_groups;
  for (int i = 0; i < dataset[0].size(); i++) {
    for (int j = 0; j < dataset.size(); j++) {
      std::vector<std::vector<std::vector<float>>> groups = test_split(i,  dataset[j][i], dataset); // gets the split of the dataset (assigns each vector in the dataset to either 'left' or 'right')
      float gini = gini_index(class_values, groups); // calculates the gini
      if (gini < b_score[0][0][0]) {
        b_index[0][0][0] = i;
        b_value[0][0][0] = dataset[j][i];
        b_score[0][0][0] = gini;
        b_groups = groups;
      }
    }
  }
  std::vector<std::vector<std::vector<std::vector<float>>>> vals;
  vals.push_back(b_index);
  vals.push_back(b_value);
  vals.push_back(b_groups);
  return vals; // returns the values.
}

This code is meant to check the gini of splitting a certain function (the gini_index() function works fine). Then it calls test_split which assigns the vector values into two sub-vectors in the vector groups, left and right. Then I just choose the split with the lowest gini.

When I delete everything in the function it doesn't restart, but I have deleted the first for loop, and also the part where it returns a vector, but still no luck. Also when deleting the for loop underneath the declaration of b_groups, it still doesn't work. I don't think it is a memory/storage issue because the Arduino IDE says that I'm only using 3% of that.

PS: I have used the library StandardCplusplus library to include vectors.


texts:
I ordered a 128x64 pixel OLED display from Adafruit and wired it according to their guide. (To an Arduino Uno) I'm using SPI right now and the display will not turn on or do anything. I haven't tried i2C, but I don't think that should make a difference. Maybe I will if nothing else works. I've installed the two libraries from the guide and am running the SPI 128x64 example. I've tried to find people with this same issue but I haven't found that much about it. Any help would be greatly appreciated!

Edit: Added pictures. I've used header pins in the past in case anyone is wondering if the connection using these wires isn't good, but the pins did not work either, so it's not a bad connection.


texts: Can I use arduino's 3.3 V output directly to esp8266?

texts:
I just bought esp8266 and ftdi usb driver, I want to power the esp8266 with Arduino's 3.3 V output, is that possible?

I saw some tutorial on youtube in that they are suggesting us to use 3.3v regulator ic instead of directly power 3.3 V of Arduino or ftdi driver's 3.3 V output.

If I connect my ftdi or Arduino output directly into esp8266 is there a chance to damage the esp8266?


texts: Battery life calculation using Nano, NRF24L01+ and window magnetic reed switch

texts:
I'm trying to make my own home wireless security system.  I will be using probably 3 AA batteries to power these devices.  My problem is that I need to know if the batteries will be enough to power the devices for at least 6 months.
Below are the details of all the devices I will be using:

Mini Nano V3.0 ATmega328P Microcontroller Board w/USB Cable For Arduino
Makerfire Arduino NRF24L01+ 2.4GHz Wireless RF Transceiver Module
uxcell MC 38 Mount Wired Door Window Sensor Magnetic Reed Switch Recessed

Below are some project requirements that might be useful:

For the Nano, I want to put it to sleep using delay(2000) in the loop() function.  The Nano will be the one checking the window sensor.
I will be using a project enclosure of about 4X4 inches.

If this will not be possible maybe someone knows of other devices that use less power that will be more suitable for this project? I would prefer something easy to use like Arduino Nano with USB so I can easily program it.

EDIT: sorry but I just like to add that from the main HUB component, I would like to check the status of the window sensor if it is open/closed.  This will be useful if there is an open window/door around the house when going to sleep. Probably the Nano will broadcast its current window sensor status to the main HUB program. Thanks.


texts:
I'm working on implementing CH340 drivers used by cheap Arduino clones on Android (Linux). What endpoints should be used as read endpoint since two endpoints have IN flag - 0x81 and 0x82?

http://usbdriverwriting.blogspot.ru/2012/10/connection-status-device-connected.html

Is there any developer documentation except some old c #1 (http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/drivers/usb/serial/ch341.c?v=2.6.25.8) and some linux driver #2 (http://0xcf.com/?wpdmdl=124)


texts: Arduino metronome - Change time signature on button press

texts:
/**************************************/
const int lowestPin = 1;//the lowest one attach to
const int speaker = 13;
int ts = 4;//how many beats you want
int count = 1;
const int keyPin = 12;
int buttonState = 0;
int bpm = 120;
/**************************************/
void setup()
{
  for (int thisPin = 1; thisPin <= ts; thisPin++)
  {
    pinMode(thisPin, OUTPUT); //initialize thisPin as an output
    pinMode(6, INPUT);

  }
  pinMode(keyPin, INPUT);
}

/****************************************/
void loop()
{

  //iterate over the pins
  //turn the led on from lowest to the highest

  if (digitalRead(keyPin) == HIGH && ts == 2) {
    ts = 3;
    delay(2000);
  }

  else if (digitalRead(keyPin) == HIGH && ts == 3) {
    ts = 4;
    delay(2000);
  }

  else if (digitalRead(keyPin) == HIGH && ts == 4)
  {
    ts = 2;
    delay(2000);
  }

  for (int thisPin = 1; thisPin <= ts; thisPin++)
  {

    bpm = pulseIn(6, HIGH);

    pinMode(13, OUTPUT);
    if (ts > 4)
    {
      if (count > 3)
        for (int a = 4; a <= ts; a++) {
          digitalWrite(a - 3, HIGH);
        }

    }
    else
      digitalWrite(thisPin, HIGH);

    if (count == 1)
      tone(13, 1500, 100);
    else
      tone(13, 1000, 100);

    delay(bpm - 52);
    pinMode(13, INPUT);
    digitalWrite(thisPin, LOW);

    count++;
    if (count > ts)
      count = 1;

  }

}

I am trying to make a metronome using Arduino Uno, with 4 LEDs, each LED is a beat. I want to change the time signature every time I press the pushbutton, so that there are different number of beats per measure, but when I do press the button, it runs the code for 2 and 3 beats per measure once, and then goes back to its default, 4 beats per measure.

Sometimes, it even changes without pressing the button, randomly. I am using a 220 ohm resister instead of 10, as 10 starts much more randomly than the 220.


texts: ESP8266 wifi connects to DLink DSL2750U but not to DIR615

texts:
Earlier all my ESP8266 Wi-Fi modules connected and functioned well using D-Link DSL2750U router but now since I changed to D-Link DIR615 router none of the same ESP8266 wi-fi modules connect. (SSID and Pwd are entered accordingly in their sketches). I tried using WiFiscan sketch in Arduino IDE, it does show the available Wi-Fi names in serial monitor but when I try to connect using the WiFIClient sketch it does nothing, the serial monitor keeps showing endless line of dots. Nor does the Routers admin status shows any of the ESPs connected.
I've also tried changing the router's Wi-fi settings as shown in the other post here. like MODE, CHANNEL AND BANDWIDTH.
Request someone to please help.


texts: Arduino Leonardo bugs and lack of removable microcontroller

texts:
Following one of the article from 2013 :

  Before you start hammering that “add to shopping cart” button, note
  that the general impression around the web seems to be that the
  Leonardo still has a few bugs that need ironing out, and isn’t quite
  as beginner friendly as the Uno. For builders already familiar with
  Arduino, this is the better deal.

The question is if Leonardo is still buggy and may cause any confusion to newbie Arduino programmers. Furthermore, Leonardo doesn't have removable chip, so how can one transfer the project into a separate processor and use Arduino to the other project?


texts: Why does per-led current consumption diminishes when more leds are on?

texts:
I'm rather new to Arduino. I've been performing some current consumption measurements lately, with a INA219 current sensor, on the blue LEDs from a starter kit.

I plugged three LEDs, on pins 2, 3, and 4 of my Arduino UNO, and wrote a simple script:

digitalWrite(led1, 1);
delay(2000);
digitalWrite(led2, 1);
delay(2000);
digitalWrite(led3, 1);
delay(2000);
digitalWrite(led1, 0);
digitalWrite(led2, 0);
digitalWrite(led3, 0);

Which turns on the leds one by one, and finally turn them off at once.
I measured the current consumption of the first LED, and measured that:

When it's the only one on, LED 1 consumes ~23.5 mA
When the second one is on, LED 1 consumes ~21.7 mA
When the third one is on, LED 1 consumes ~20.2 mA

Could you please tell me why it behaves that way ? Is there any source I should read that would formalize that ?

Thank you


texts: Powering Arduino Components with AA in Parallel and Series

texts:
simulate this circuit – Schematic created using CircuitLab
I have 6 AA batteries that I would love to power my Arduino Nano and HCSR04 ultrasonic sensor. However, for my low power application I want to use the bare minimum power required for the components. Since the Nano can run as low as 4.5 volts and the sensor requires 5 volts, I think the best solution would be 4 AA batteries in series to power the hcsr04 and 3 AA batteries in series to power the nano. Since I have 6 batteries I was thinking 3 AA batteries wired in parallel with 3 AA series batteries. I drew the circuit diagram above and realize something is horribly wrong. So I was hoping someone could point me in the right direction.


texts: Using digital pins 0/1 on Arduino Due when writing/reading over serialUSB port

texts:
I am aware that you cannot use pins 0 and 1 as digital pinouts when communicating over serial via serial.print(), but what if you are using the native port on the due with serialUSB.write()?

Thanks


texts: Wait for serial input otherwise start with preconfigured options

texts:
I need to input config parameters from serial input. After a period (1 min) with no input I would like the program to start with preconfigured parameters.

Currently in the loop() section I use Serial.available, which stops until it receives new data.

How can I implement that?

void loop() {
  // read serial input
  if (Serial.available() > 0) {
    inChar = (char)Serial.read();
    inputString += inChar;


texts: Use doorbell output (12VDC) to power arduino?

texts:
Not sure if this is possible, but could I use my existing doorbell setup to power an Arduino? I'd also like to preserve the existing chime's functionality either through the existing button or triggering it through the arduino.

My doorbell chime is made by Nicor and its input is 120VAC, but outputs 12VDC. This seems to be a very unconventional setup, but I've confirmed its output with a multimeter (it's also printed on the chime itself). The chime is very similar to this: http://www.amazon.com/Nicor-18888-Door-Chimes/dp/B006T38PTU (only difference I can see is the output). The 12V line runs to my front door where it's connected to a light up button. Here is a picture of the button's circuitry: http://imgur.com/IjA50rT

What I'd like to do is use the chime's 12VDC output to power the arduino so I don't have to rely on another power source or batteries. I will be adding smart features to the doorbell via the arduino, but my main hangup is getting power to the arduino. I've tried connecting the doorbell wires to VIN and ground, which successfully powers on the Arduino, but it also triggers the chime. It appears closing the circuit triggers the chime to play.

Is this possible to do?


texts:
I am trying to use a load cell (https://www.sparkfun.com/products/13331?_ga=1.55586472.2060096590.1479826091) and an HX711 chip with an arduino and LCD shield to display weight values on the LCD shield  when weight is added to the load cell. Does anyone know how I can connect all of these together?

Mainly, how do I connect the HX711 to the arduino while the LCD shield is already on the arduino?

Any help is welcomed , thanks.

Here is the LCD shield I am using I am using:

LCD Shield- https://www.dfrobot.com/index.php?route=product/product&product_id=51

Arduino- not sure which type of arduino to use.


texts: Does an Arduino 101 come with bluetooth HID capabilities?

texts:
I would like to prototype an Ergodox-like keyboard. My take on this good design would be to affix each half of the keyboard to my chair's armrests, so that the arms are always in a natural relaxed position. In order to achieve this, bluetooth capabilities seem necessary in order to avoid cable mayhem each time I move the chair.

I am aware that the Arduino Leonardo has USB-HID capabilities, but will that translate to the additional USB module that would be required? I saw that Adafruit has an EZ-key bluetooth module that seems to fit the bill, but even so, it would require more cabling and complexity, for a project that is already very near my threshold (or above it).

What would be easy is if the Arduino 101 had HID capabilities. I would just need to solder the matrix of keys, and almost be done. Does it?

Thanks for your attention.


texts: Read & write on Winbond SPI flash using Arduino UNO

texts:
Recently I have brought a original UNO for modifying and flashing various types of bios. I had a dedicated one click bios programmer which was very expensive but few days ago it failed. So I thought it is a good opportunity to learn how bios works in details. After searching on google, I saw people doing everything with bios via Arduino. So I bought one. But now I cant get my head around this as I couldn't find what I am looking for. My first goal is to extract bios from the flash chip and re-program the flash with another bios.
The current bios flash I have, is a Winbond 25Q80DVDAIG. Upon searching for data-sheet, I found this data-sheet. My bios flash is in 8pin 300 mil PDIP package.
For this bios flash I have followed this guide. I have wired every thing following the schematic provided in the guide. I have bought the resistors from a local store. After measuring their values, 10K is 9.64K, 100ohm is 94 to 99ohm, 220ohm is 210 to 220ohm. So they are not so accurate. But still I proceed and connected my UNO to pc. in the Arduino software I run some tests to see if everything is working or not. But when I print manufacturer_id, device_id in serial monitor, I get 0, 0. But according to the datasheet, manufacturer_id should be EFh and device_id should be 13h.
Now I don't know if the bios is dead or the UNO board can't communicate with the bios. Is there any way to just test the bios without this schematic if it is ok or dead? like with multimeter?
Another thing, On the guide there is a instruction, "First, make download_rom() function only active and flash the sketch into your Arduino.". What does it mean? How can I make download_rom() function active or only active? What does even only active means?
If you know any other easy to use guide for this bios flash, please let me know. Also, I have seen EEProm lib in Arduino software. Will it work on this bios flash?
Thanks in advance for the help. Very much needed. Appreciate it.


texts: How to measure the distance between 2 points accurately

texts:
Does anybody know how i would measure the distance between two points which will be no more than 50mm apart with accuracy to 1mm?

I want to record the distance between the two points in a database over time at frequency of 1 datapoint for every second.

Anybody know what sensors could do this?


texts:
I want to count peak of photocell data with serial communication in Arduino.

Here is the question. My problem is when I count one of the peaks it continues the counting and doesn't stop counting. My project is count Michelson Morley fringes with a photocell and Arduino.

If somebody can help me with the coding part I would appreciate it.

Here is the code that I used:

int count=0;
int val;
int data;

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

void loop() {
  data=analogRead(A0);
  val=map(data,0,1023,1000,0);
  if(val>700) {
   count++;
  }
  Serial.println(count);
  delay(100);
}

This picture shows what I am trying to achieve:

Example Michelson Morley fringes:


texts:
I have made an Arduino circuit which outputs in terms of frequency(hz) and I need output in terms of db as well

So is there any formula which can I apply to convert frequency hertz to db or is there any reference link to understand the conversion process.

Any help will be highly appreciated


texts: the communication port (com11) is yellowed with exclamation marks in device manager and I am unable to run arduino on my computer. how to get rid of the yellow exclamation mark on the com 11?


texts: The problem of not saving the previous value when sending it from bluetooth

texts:
Controlling Led's from Buttons and Bluetooth by same method

The problem now :

the LED light up when you send an A over Bluetooth and it will turn off after 2 sec automatically without you doing anything (this is the wrong now in video).

I Want the same char when send data the led turn on and when i want closed led send same char to turn off light .

The code: bottom this page

thank

this is the wrong now in video

 #define CLK 10
 #define CLKI 9
 #define LD 8
 #define SO 11
 #define SER 12

 byte ledstates;
 byte copy=0;
 unsigned long bt_leds_timestamp=0;
 byte bt_leds_activated=0;

 void setup(){
   Serial.begin(9600);
   pinMode(CLK,OUTPUT);
   pinMode(CLKI,OUTPUT);
   pinMode(LD,OUTPUT);
   pinMode(SO,INPUT);
   pinMode(SER,OUTPUT);
  }

 void loop(){
  if (Serial.available()>0){
  message();
 }
  shift_In();
  shift_out(ledstates);

  if(bt_leds_activated && millis()-bt_leds_timestamp > 2000){
  ledstates &= ~bt_leds_activated;
  shift_out(ledstates);
   bt_leds_activated = 0;
  }
 }

 void message(){
  if(Serial.available()){      // Send data only when you receive data:
  char data = Serial.read();        //Read   the incoming data & store into data
  Serial.print(data);          //Print Value inside data in Serial monitor

  switch (data){
  case 'A' :
    bt_leds_activated |= 1;
    break;
  case 'B' :
    bt_leds_activated |= 2;
    break;
  case 'C' :
    bt_leds_activated |= 4;
    break;
  case 'D' :
    bt_leds_activated |= 8;
    break;
  case 'E' :
    bt_leds_activated |= 16;
    break;
  case 'F' :
    bt_leds_activated |= 32 ;
    break;
  case 'G' :
    bt_leds_activated |= 64;
    break;
  case 'H' :
    bt_leds_activated |= 128;
    break;
  default   : return; }
  }
   ledstates |= bt_leds_activated;
   shift_out(ledstates);
   bt_leds_timestamp = millis();
  }

 void shift_out (byte copy){
  digitalWrite(LD, LOW);
  shiftOut(SER,CLK,MSBFIRST,copy);
  digitalWrite(LD, HIGH);
  delay(100);
 }

 void shift_In(){
  digitalWrite(CLKI,HIGH);
  digitalWrite(LD,HIGH);
  digitalWrite(LD,LOW);
  digitalWrite(LD,HIGH);
  digitalWrite(CLK,HIGH);
  digitalWrite(CLKI,LOW);
  byte buttonstates = shiftIn(SO,CLK,MSBFIRST); //read button states in a local variable
  digitalWrite(CLKI,HIGH);
  for(int i=0;i<8;i++){ // loop through all 8 bits of the buttonstates
    if(!(copy & (1<<i)) && (buttonstates & (1<<i))){ // check if old button state (in copy) is zero and new buttonstate is 1 (for the currently check bit)
        ledstates ^= 1<<i; // toggle the corresponding bit in the ledstates variable (will be shifted out later in the loop() function)
    }
  }
  copy = buttonstates;
  delay(10); // delay for debouncing
  }


texts:
I'm currently trying to send data from esp32 to my android app that I made. The sensor readings are showing in the serial monitor, however, what's showing on my app are either @ or &. Please help and thank you. I'm new to bluetooth coding.
Here's the code:
#include "BluetoothSerial.h"
int sensorPin = 35;
int sensorreading;

BluetoothSerial SerialBT;

void  setup ()
{
    Serial.begin(115200);
    SerialBT.begin("ESP32_ABO");
    pinMode (sensorPin, INPUT);
}
void  loop ()
{
   sensorreading = analogRead(sensorPin);
   String toSend = String (sensorreading);
   sendData(toSend);}

void sendData(String textToSend){

   Serial.print(sensorreading);
   SerialBT.write(textToSend[sensorreading]);
}
delay(1000);}


texts:
I know very little about Arduino and even less about programming one. Before I purchase a board, and learn how to program it, I was wondering if my idea is feasible.

I want to program the Arduino to sequentially open one after another irrigation valve. There would be approximately eight 24 volt solenoid valves. Each one would need to be open for approximately 15 minutes, then open the next valve in sequence and finally close the previous valve. Similar to a multi-zone irrigation controller.

I see that I may need to use a transistor in the power circuit of the solenoid. But it is not clear to me if the Arduino can control eight solenoids and if so, does each solenoid require its own transistor?


texts: problem uploading arduino sketch on esp8266-12e

texts:
i have a new mac os sierra installed.
i just installed arduino IDE and the serial drivers for mac os x to make the serial usb port available for esp8266 device

when i try to flash the device through the IDE i have these errors:

Arduino:1.8.3 (Mac OS X), Scheda:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"

Archiving built core (caching) in: /var/folders/vz/qxry2ffs3rnd2xtd557pgcf00000gp/T/arduino_cache_169716/core/core_esp8266_esp8266_nodemcuv2_CpuFrequency_80,UploadSpeed_115200,FlashSize_4M3M_244c37a477ed4ef8a63952f7a6e6a50b.a
Lo sketch usa 222149 byte (21%) dello spazio disponibile per i programmi. Il massimo è 1044464 byte.
Le variabili globali usano 31524 byte (38%) di memoria dinamica, lasciando altri 50396 byte liberi per le variabili locali. Il massimo è 81920 byte.
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: unslip sequence wrong
warning: espcomm_send_command: can't receive command response header
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

what can i do?


texts:
I am using ESP32 and SHT21 temp+humidity sensor but while compiling the code I get the following error:
variable "SHT21" is not a type name

I see an SHT21 class defined in the SHT21.cpp file in the library folder. I don't know much about classes so could you please tell what is wrong with the SHT21 class in this case?
Here is the link to the library:
https://github.com/markbeee/SHT21
Sketch:
#include <Arduino.h>

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

SHT21 SHT21;

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

void loop()
{
  Serial.print("Humidity(%RH): ");
  Serial.print(SHT21.getHumidity());
  Serial.print("     Temperature(C): ");
  Serial.println(SHT21.getTemperature());

  delay(1000);
}


texts: Is there complex application examples out there that can be considered best practice material?

texts:
I'm coming from a web environment and not that fluent in C++. About to start a moderately complex dev on an ESP32 device.

I know that there is hundreds of arduino libraries out there but I haven't found a lot of complex actual application examples.

I'm mostly interested in the file structure, separation of concerns and other C++ tweaks that should be considered best practices when coding on embedded devices in a more robust way.

I found the ardupilot GitHub project to be very interseting to look into, but its quite big, and I'm not sure if it would be considered well written code as I can't judge myself.

Can you recommend other great projects to look into?


texts: Arduino DS3231 error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'

texts:
I am building a arduino based bicycle speedometer with time and temperature display.
Im currently stuck with the DS3231 (zs-042) chip. I found online a lot of library issues, i tried using
multiple libraries (Rinky-Dink, ds3231-master) but nothing works. I found a simple code online to test the chip but when I upload it the following error shows up: "no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)"
#include <Wire.h>
#include <DS3231.h>
DS3231  rtc(SDA, SCL);

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

  // Initialize the rtc object
  rtc.begin();
  rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014
}

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

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

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

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

The error occurs in the third line (rtc (SDA,SCL)) - I have checked the pins and switched the battery on the chip. I also tried using A4 and A5 instead of SDA and SCL pins...
Any type of help would be awesome.
Best regards,
Marin


texts:
Can I get help to connect Arduino Mega 2560 and servo motor in Proteus 7.8
correctly because I tried this connection, in the image below, with sweep.ino.hex in the Arduino software examples but did not work!


texts: HC-05 bridge using Arduino Nano and GNU Screen

texts:
I connect an HC-05 module to an Arduino nano with CH341 serial chip (voltage divider on RX pin). I am trying to make a bridge for a test, i.e. serial in, echo local and echo to Bluetooth and vice versa. I modified the echo code from here.

int incomingByte = 0;    // for incoming serial data

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() {
    BTSerial.begin(38400);    // opens serial port, sets data rate to 9600 bps
    Serial.begin(9600);    // opens serial port, sets data rate to 9600 bps
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {

    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }

  if (BTSerial.available() > 0) {

    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }

under OSX I open two terminals. In the first terminal using screen /dev/cu.wchusbserial1410 9600 I see local echo as desired. But on the second terminal using screen /dev/cu.HC-05-SPPDev 38400 I see nothing after pairing. The only effect is that by typing the latter command, the module stops blinking rapidly and blinks only two times with long pause in between. Exiting the screen environment, then again blinks rapidly.

Appreciate any hints what I am doing wrong...

=====

intermediate success but not quite there yet:

I simplified the code and corrected the wrong connection. Local echo on serial works as usual, even between the two, characters are being transferred, but they are black question marks instead of why I typed.

/*
 * echo script
 */

byte incomingByte;

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(3, 2); // RX | TX

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

void loop() {
  if (Serial.available()) {
    incomingByte = Serial.read();
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }

  if (BTSerial.available()) {
    incomingByte = BTSerial.read();
    Serial.print((char)incomingByte);
    BTSerial.print((char)incomingByte);
  }
}

Any ideas?

========

Edited the Buadrate to 9600. Now everything works.


texts:
Suppose I have a number with 2 digits, 42.
It is an integer, received from my RTC

Now for my 7 segment displays, I will need 2 seperate numbers,
4 on display 1.
2 on display 2.
How do I slice this number in 2?


texts: variable name standards, e.g best method to send motion_detect=true

texts:
I am working with some sensors and sending data to a public web server via http, I was thinking this server can be possibly used by more people to send their data and server displays a chart.
I was wondering if there is a IOT industry standard when sending certain type of data, so that in future I don't need to rename this or change documentation to be more compatible or more intuitive.
For example when sending a "motion detected" ping, do I go with pir=true, pir=1, motion_detect=true ?
Then for example when sending temperature, it would be much better temp_celsius=30 then just temp=30.
It should also make developers job much easier if there is a certain standard. Is there one ?


texts: Oil Pressure / Water Pressure / Boost Pressure ( Turbo Engine )

texts:
I'm an automotive enthusiast and I want to build some gauges by myself using Arduino.

I was taking a look at this pressure transducer or sender, 100 psi, stainless steel, for oil, fuel, air, water and I was thinking if I can use this sensor to do all of the these tasks: Water, Boost and Oil Pressure.

Look at the Signal output vs read PSI chart of the sensor

I came out with this equation for the PSI calculation:

Since it is a Y = bx + a, where:

a = 0.5
b = y2 - y1 / x2 - x1 = (4.5 - 0.5 ) / (100 - 0) = 4/100 = 0.04
x = PSI
y = Signal's Voltage

This means that

Voltage Reading = 0.04PSI + 0.5

So we have :

PSI = (Voltage Reading - 0.5 ) / 0.04

Am I correct? Can I use this sensor?


texts: How can I adapt the DallasTemperature library to accept another 1-Wire class?

texts:
A commonly used library is the DallasTemperature library, used to access DS18B20 sensors on a 1-Wire bus. When creating a DallasTemperature object you pass a reference to a OneWire object. OneWire can create a 1-Wire bus on pretty much any port of an Arduino.

An example of this is like so:

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

However, there are some issues with using OneWire to drive a 1-Wire bus, mainly around driving longer bus lengths, dealing with shorts, and other errors.

There is a commonly available chip called the DS2482-100 that can drive longer busses (hundreds of feet), deals with shorts and other errors. It is also less CPU heavy and it deals with a number of the slower aspects of 1-Wire.

For this reason, I would like to be able to pass a reference to a library that I have created instead. Currently, I am doing this by:

Calling the library OneWire
Replicating all the methods called by the DallasTemperature library
Swapping out the OneWire library for mine

This is relatively messy. I would ideally like to be able to pass either a reference to my library or a 1-Wire library, so that people can chose which interface to use.

How would I go about doing this?


texts:
I've been using an Adafruit Huzzah ESP8266 Breakout to read data from an OpenTherm Gateway connected to my central heating unit, and publish that to MQTT. I'm programming the ESP8266 using the Arduino IDE.

The gateway publishes messages to the ESP8266 via serial. These messages look like this: T901812F3 or B501812F3

The first letter indicates whether the message comes from the thermostat or the boiler, while the remaining characters represent four bytes, hexadecimally encoded.

These four bytes are structured as follows:

I'm trying to extract the MSG-TYPE, DATA-ID, and DATA-VALUE from the four bytes, but I'm getting weird (to me) results. I'm new to Arduino and C in general.

I'm familiar with PHP, and extracting the data using that is easy:

$decimal = hexdec(substr("B501812F3", 1));      // 1343754995
$messageType = (($decimal & 0x70000000) >> 28); // 5
$dataId = (($decimal & 0x00FF0000) >> 16);      // 24
$dataValue = ($decimal & 0x0000FFFF);           // 4851

However when I try something similar in the Arduino IDE, and upload it an Arduino, I get a different result:

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

    parseLine("B501812F3");
}

parseLine(char* message) {
    // Extract data
    char messageType;
    unsigned long data;
    int numberExtracted = sscanf(message, "%c%08x", &messageType, &data);

    // Decompose a single message
    int flag = (int) ((data & 0x70000000) >> 28);
    unsigned char openThermId = (unsigned char)((data & 0x00FF0000) >> 16);
    unsigned short openThermPayload = (unsigned short)(data & 0x0000FFFF);

    Serial.println(data);             // 4851
    Serial.println(flag);             // 0
    Serial.println(openThermId);      // 0
    Serial.println(openThermPayload); // 4851
}

I (perhaps incorrectly) assume that the effect will be the same when I upload the code to an ESP8266.

What am I missing here? I suspect it has something to do with the different max integer value on the Arduino, but I'm not really sure how to proceed.


texts:
Hello everyone I write my code and have some troubles.
When I write on in my serial monitor my buzzer condition wasn't changed.
Can you help me realize the reason. I wrote code with int type and it works with Serial.parseInt() function properly.
String ask="Please enter buzzer condition";
int buzzerPin=2;
String state;
void setup() {
  pinMode(buzzerPin,OUTPUT);
  Serial.begin(115200);

}

void loop() {
 Serial.println(ask);
 state=Serial.readString();
 Serial.println(state);
 while(Serial.available()==0){

 }
 if(state=="on"){
  digitalWrite(buzzerPin,HIGH);
 }
 if(state=="off"){
  digitalWrite(buzzerPin,LOW);
}
}


texts:
I had an idea to create a control panel using an arduino and some buttons. How would I go about making the arduino emulate an input device so that when I press a button connected to the arduino, it would cause the same effect as when a keyboard key was pressed? (I'm using arduino UNO, if it helps.)

Thanks in advance.


texts: Secure HTTPS request fails 90% of the time

texts:
I'm using a NodeMCU, which is connected to an enterprise network at a school. The information given in the GET requests that the ESP8266 sends is sensitive, so naturally we want to make it secure and encrypted - enter SSL. We do the request like so;

HTTPClient http.begin(url, thumbprint)

However, on the network at the school, doing this request fails 90% of the time, so I did a few tests - 100 requests to the exact same IP and certificate, noting how many went through;

School network

HTTPS requests: 10/100 successful [10%]
HTTP requests: 100/100 successful [100%]

Private home network

HTTPS requests: 100/100 successful [100%]
HTTP requests: 100/100 successful [100%]

We have also tried using the WiFiClient class, and while 100% of the requests went through, each one took 15 seconds which is too long.

My question is; what would the problem be, and what can we do to fix it? Can I do something in the code, or on the network?


texts: Creating a library for attiny85 out of working program

texts:
Apologies if this is the wrong sub-forum, the involvement of ATTiny and arduino places this into a strange category. Please correct me if I should post elsewhere.

It is important for this to be a library as small kids will be using this program and hardware for their own projects. Its kind of a rip on the LOLshield but it involves a lot more steps to integrate more lessons all at once.

My whole program takes 8 bytes of information and converts it to data for a shift register driving two multiplexers all driving an 8x8 LED matrix. It can also use multiple of these packets to make a slide show. I have it in a working state right now and would like to turn it into a library for easy use. I am a bit lost in this step as I had to create an interrupt timer and this makes it more complicated than the tutorial on the arduino website covers.

Also if someone could point me to a library for ATTiny85 that makes calling a timer interrupt easy then the rest of this project will likewise become easier.

Any help would be great! I will be continuing to look on online resources and will update should I figure it out.


texts: reversing a micro motor by reversing two pins - one Source and one sink?

texts:
can I use this configuration of two pins to run a micro motor ,so I be able to change the polarity of the current (by the code itself-one time out pin1-high out pin2 - low , while next time one low two high!) every time I would like ?(and by changing the polarity OF THE CURRENT to the motor it will revers it) !

Thank's !


texts: Can I connect an Arduino GSM Shield directly to a PC?

texts: Is it possible to communicate with and use the GSM shield directly from the computer, without using an arduino board?


texts: Seeing consistent serial data loss over USB, have ruled out hardware and rx/tx software. What's left?

texts:
I have a Lasersaur, which is an arduino-based open-source laser cutter. Part of its capabilities is raster engraving, where you etch images based on pixel data, rather than vector data. Recently I started experiencing a weird issue where I am losing some of the data that I am sending over serial to the machine, and the end of the image gets cut off. I don't believe those details are relevant to this question, but you can read my posts here for more info.

Basically, on my old Laptop B, engraving works. If I use the exact same USB hardware connection, firmware, frontend software executable, engraving settings, and image file on my current Laptop A, I see bad results. The last ~20 pixels or so of each image line are not etched in, and the only reason I can think for this is that the color data for these pixels were not sent in the first place. Notably, Laptop A used to work a few months ago when I last tried this out. So I'm pretty confident that I've ruled out hardware and rx/tx software as the possible issues.

The only difference between the two machines that I can think of that has changed since then is that I installed the Windows 10 1909 update, as well as some other software that I would have to dig back through to list out. I'd really like to not do a fresh Windows reinstall on my primary machine, but I'm close to that point.

Could something there be causing an issue? I'm out of my depth at this point, and don't know how either the operating system or another program could be affecting serial data transfer, and wouldn't know the first way to narrow it down.

Some more thoughts which may or may not be important:

There does not seem to be data corruption, only data loss. The rx/tx protocol implements some error detection (sends every byte twice and checks for equality), and I am not seeing error corruption messages that would pop out if that were the case.
There does not seem to be any randomness. The same behavior happens for images of different widths (leading me to think that the tx buffer isn't filling up), is the same for each image line, and has always been consistent.
The Arduino in the machine is an Arduino Uno R3. Compilation is done using the Arduino compiler on some custom C code (not though the IDE).


texts: Any advice on how to repeat the song 6 times instead of infinitely?

texts:
//Here is my code so far
int speakerPin = 9;

int length = 28;

char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc";

int beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8,8, 16, 1, 2,2,8,8,8,8,16, 1,2,2,8,8,8,16 };

int tempo = 150;

void playTone(int tone, int duration) {

for (long i = 0; i < duration * 1000L; i += tone * 2) {

   digitalWrite(speakerPin, HIGH);

   delayMicroseconds(tone);

   digitalWrite(speakerPin, LOW);

   delayMicroseconds(tone);

}

}

void playNote(char note, int duration) {

char names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',

                 'c', 'd', 'e', 'f', 'g', 'a', 'b',

                 'x', 'y' };

int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014,

                 956,  834,  765,  593,  468,  346,  224,

                 655 , 715 };

int SPEE = 5;

for (int i = 0; i < 17; i++) {

   if (names[i] == note) {
    int newduration = duration/SPEE;
     playTone(tones[i], newduration);

   }

}

}

void setup() {

pinMode(speakerPin, OUTPUT);

}

void loop() {

for (int i = 0; i < length; i++) {

   if (notes[i] == ' ') {

     delay(beats[i] * tempo);

   } else {

     playNote(notes[i], beats[i] * tempo);

   }

   delay(tempo);

}

}


texts: Change from using the external crystal to the internal oscillator

texts:
BACKGROUND

I have made my own Arduino PCB based on the circuit of the Arduino Pro Mini (below) (including the external oscillator).

I have already written the firmware and the code is stable. The code uses the millis() function which uses Timer 0. I also have changed the frequency of the PWM output on pins 3, 9, 10, 11, using the clock select bits (bits 2:0 in TCCR1B & TCCR2B). See http://playground.arduino.cc/Main/TimerPWMCheatsheet

I have an ISP 6-pin programming port on the board and this is my only method of uploading code.

I want minimize on components (and avoid EMC issues), so I have been considering removing the external 16MHz crystal and instead using the internal 8MHz oscillator.

QUESTIONS

What do I need to change to use the internal oscillator?

I suspect that I need to change the board.txt file, the clock select bits and the fuses to accommodate for the new frequency.

Can I leave the external crystal in place or do I have to remove it?
If I do leave the external crystal in place and set the fuses to use the internal oscillator, will the crystal continue to resonate or does it get powered down somehow?
(I wish to know this for EMC reasons)


texts: NodeMCU current consumption in all modes

texts:
I am using NodeMCU for my project.I wanted to know how much current it takes in its all modes like sleep mode,deep sleep mode and also in its wifi modes like station and access point mode.

Thanks in advance...


texts: What sensor would I use to get the speed or velocity of my Arduino based nav system?

texts:
I'm building a Arduino Nano based underwater navigation system using an IMU and various sensors. The only problem with this is that I cannot get the speed or velocity(at least reliably) and it would help the accuracy of my navigation system immensely if I had accurate speed to go off of.

Does anyone have any ideas on how I could measure the speed of my Arduino underwater? I've seen some people recommend paddle wheel like sensors but this needs to be accurate for slow movement.


texts:
I am building a box that will start a genset. It has two buttons, run and stop.
I would like button run to be able to start (and remain constant) until pressed a second time, I have sussed this bit so far, but this is where I get stuck.
I would like the stop button to only stop the the engine (as a single function)
So my question is how do I integrate the second button (stop) to carry out this one task?

int LEDYelState=0;
int LEDRedState=0;
int LEDGrnState=0;
int RELAYRedState=0;
int RELAYYelState=0;
int RELAYGrnState=0;
int LEDRedPin=10;
int LEDYelPin=9;
int LEDGrnPin=8;
int RELAYRedPin=7;
int RELAYYelPin=6;
int RELAYGrnPin=5;
int buttonPin=13;
int buttonNew;
int buttonOld=1;
int dt=100;
int buttonOff;
int buttonPinOff=12;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(LEDRedPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode (LEDYelPin,OUTPUT);
pinMode (LEDGrnPin, OUTPUT);
pinMode (RELAYRedPin, OUTPUT);
pinMode (RELAYYelPin, OUTPUT);
pinMode (RELAYGrnPin, OUTPUT);
pinMode (buttonPinOff, INPUT);
}
void loop() {
buttonNew=digitalRead(buttonPin);
buttonOff=digitalRead(buttonPin);
if(buttonOld==0 && buttonNew==1){
  if (LEDRedState==0){
    digitalWrite(LEDRedPin,HIGH);
    LEDRedState=1;
    digitalWrite(RELAYRedPin,LOW);
    RELAYRedState=1;

    digitalWrite(LEDYelPin, HIGH);
    LEDYelState=1;
    digitalWrite(RELAYYelPin, LOW);
    RELAYYelState=1;
    delay (8000);
    digitalWrite(LEDYelPin,LOW);
    digitalWrite(RELAYYelPin,HIGH);

    digitalWrite (LEDGrnPin,HIGH);
    LEDGrnState=1;
    digitalWrite (RELAYGrnPin, LOW);
    RELAYGrnState=1;
    delay(2000);
    digitalWrite  (LEDGrnPin,LOW);
    digitalWrite (RELAYGrnPin,HIGH);
    RELAYGrnState=1;
  }
  else{
    digitalWrite(LEDRedPin, LOW);
    LEDRedState=0;
    digitalWrite(RELAYRedPin, HIGH);
    RELAYRedState=0;
    digitalWrite(LEDYelPin,LOW);
    LEDYelState=0;

  }
}
buttonOld=buttonNew;
delay(dt);

}


texts: Is something wrong with my Adafruit motor shield?

texts:
I think something may be wrong with my shield, as I looked at the other forums related to this question and still can not get help.

I know that I can't run it from a 9V source by itself, as the Adafruit website specifically said I can't. So they said to use a LiPo battery or 8 AA batteries. So I tried powering the shield with 8 AA batteries and the light comes on to confirm that.

I then added a 9 volt battery to power the Arduino itself. My motor is a DC motor from RadioShack that can work at 9V, 12V or 18V. I have the motor connected to M2. What am I doing wrong? Here is the site I am following.

Here is the DC motor.

Again, if anyone knows what I am doing wrong, that would be very helpful to know. Thank you for your time and effort.

Edit 1:

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
  Serial.begin(9600); // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  motor.setSpeed(200); // set the speed to 200/255
}

void loop() {
  Serial.print("tick");
  motor.run(FORWARD); // turn it on going forward
  delay(1000);
  Serial.print("tock");
  motor.run(BACKWARD); // the other way
  delay(1000);
  Serial.print("tack");
  motor.run(RELEASE); // stopped
  delay(1000);
}


texts: How to connect Arduino Nano with ESP8266 and BMP180?

texts:
I have an issue with my application.

Hardware used:

ESP8266 Serial Wi-Fi Wireless Transceiver Module for IOT
Robodyn Micro USB Compatible for Arduino Nano V3.0 ATmega168 CH340G
SENSOR: BMP180

Connections:

Arduino Nano to ESP8266
CH-PD to Vcc
GPIO0 to GND
Rx to Rx
Tx to Tx
3.3v to 3.3v
Reset to GND
GND to GND

Arduino Nano to BMP180

3.3v to VIN
GND to GND
A5 to SCL
A4 to SDA

Sketch used (uploaded in Generic ESP8266 Board):

#include <DHT.h> //  DHT.h library
#include <ESP8266WiFi.h> // ESP8266WiFi.h library
#include <SFE_BMP180.h>
#include <Wire.h>

SFE_BMP180 pressure;

const char* ssid     = "GOPI-LAPTOP";
const char* password = "kcejava123";
const char* host = "api.thingspeak.com";
const char* writeAPIKey = "CQSHDFP4EZFCDWKO";

void setup() {
  // Initialize sensor
  Serial.begin(9600);
  delay(1000);
  if (pressure.begin())
    Serial.println("BMP180 init success");
  else {
    Serial.println("BMP180 init fail\n\n");
  }
  //  Connect to WiFi network
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void loop() {
  char status;
  double T, P, p0, a;
  status = pressure.startTemperature();
  if (status != 0) {
    // Wait for the measurement to complete:
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0) {
      // Print out the measurement:
      Serial.print("temperature: ");
      Serial.print(T,2);
      Serial.print(" deg C, ");
      Serial.print((9.0/5.0)*T+32.0,2);
      Serial.println(" deg F");
    } else
      Serial.println("error retrieving pressure measurement\n");
  }
  status = pressure.startPressure(3);
  if (status != 0) {
    delay(status);
    status = pressure.getPressure(P, T);
    if (status != 0) {
      // Print out the measurement:
      Serial.print("absolute pressure: ");
      Serial.print(P, 2);
      Serial.print(" mb, ");
      Serial.print(P*0.0295333727, 2);
      Serial.println(" inHg");
      p0 = 1013.25; // we're at 1655 meters (Boulder, CO)
      Serial.print("relative (sea-level) pressure: ");
      Serial.print(p0, 2);
      Serial.print(" mb, ");
      Serial.print(p0*0.0295333727, 2);
      Serial.println(" inHg");
      a = pressure.altitude(P, p0);
      Serial.print("computed altitude: ");
      Serial.print(a, 0);
      Serial.print(" meters, ");
      Serial.print(a*3.28084, 0);
      Serial.println(" feet");
    }
  }
  // make TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    return;
  }
  String url = "/update?key=";
  url+=writeAPIKey;
  url+="&field1=";
  url+=String(T);
  url+="&field2=";
  url+=String(P);
  url+="\r\n";
  // Request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
    "Host: " + host + "\r\n" +
    "Connection: close\r\n\r\n");
  Serial.print(String("GET ") + url + " HTTP/1.1\r\n" +
    "Host: " + host + "\r\n" +
    "Connection: close\r\n\r\n");
  delay(30000);
}

Serial Output:

BMP180 init fail

GET /update?key=CQSHDFP4EZFCDWKO&field1=8.04&field2=8.08
 HTTP/1.1
Host: api.thingspeak.com
Connection: close

GET /update?key=CQSHDFP4EZFCDWKO&field1=8.04&field2=8.08
 HTTP/1.1
Host: api.thingspeak.com
Connection: close

Queries:

• How to enable BMP180 to sense? When I configure BMP180 with Arduino (without ESP8266), I get the output in the serial terminal.

• How to send data to Thingspeak.com from BMP180 using the specified hardware?


texts: Is it possible to read extended ASCII from the serial port?

texts:
My project requires that Serial.read() be able to accept extended ASCII characters (0x80 <=> 0xFF). For example, I would expect reading the character ¥ to yield the decimal value 157. Instead, the read() command has two successful reads, with the values: 194 and 165. Of course, I could create a lookup table and convert, but this is not a viable option. I am conforming to the Grbl standard protocol, which uses these single-byte extended ASCII characters as interrupts. Such a two-byte structure precludes a simple peek/read approach necessitated by the protocol.
Edit I tried to simplify the question for this context, but failed to account for the fact that the Arduino IDE will send the input as Unicode. Regardless, it still does not work when sending bytes directly. Namely, if I send the byte 0x93 via C# as Serial.Write("\u0093"), the Arduino's Serial.read() does not see any bytes available. Sending normal ASCII, e.g., Serial.Write("\u0018"), works fine.


texts: Connecting Arduino Uno to a smartwatch via bluetooth

texts:
I have a U80 Smartwatch from Bluetooth Watch International, which has bluetooth function. It is meant to be connected via to my smartphone (and it works perfectly).

I also have an Arduino Uno board and a corresponding BLE ZS-040 bluetooth chip.

I need for my smartphone to be able to detect my Arduino board, so I can send data from a simple circuit connected to the Arduino board to the smartphone.

Basically, my circuit is meant to be a simple push button. When the button is pushed, and the circuit is closed, the Arduino board will send a signal to the smartwatch. This will cause the smartwatch to ring and vibrate, as if it is receiving a call. Then to turn off the ringing and vibrating, the user can simply 'answer the phone call', and it will stop.

From what I understand, (I'm very new to Arduino) I have to connect the Arduino board to the smartwatch first, which means I have to somehow get the board to be detected by my watch, which it's not doing yet, eventhough the bluetooth module is connected to the board.

Then the push button needs to send a signal to the watch. Which means the command {if buttonpush='1', send (receiving call)}, so when the button is pushed, the signal is sent and the watch acts as if it is receiving a call. Basically showing all the physical signs (eg. vibrating and/or ringing based on the watch's setting, showing 'answer/deny call', etc.). Btw, the push button is not to be held down. As long is the button is pushed and released once, the signal should be sent, and the watch will buzz until the 'phone call' is answered or denied.

I have absolutely no idea how to get the board connected to the smartwatch via bluetooth.
And while I have a rough idea on the push button circuit I need, I also need to send the signal for the watch to act like it has received a call.

Mainly, I'm looking for any help with coding here. If anyone can help with the physical circuit connections, that would be awesome too.


texts: Problem with reading series of bytes over serial port

texts:
I'm writing a program to read bytes from serial channel, copy those into an array and then do some verification on those copied numbers.

I'm able to read and copy bytes into an array of bytes.
However, I'm facing an issue with the verification of those bytes.

Here's the code I've written:

#include <SoftwareSerial.h>

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

void loop()
{
    char charRead = 0x00u;
    byte byteArray[10];
    int i=0 , j=0;

    //Clear the array contents
    for(j = 0; j < 10u; j++)
    {
       byteArray[j] = 0x00u;
    }

    //Wait for data on serial channel
    while(Serial.available() > 0)
    {
       //Copy bytes received into array
       charRead      = Serial.read();
       byteArray[i] = (byte)charRead;
       i++;
    }

    //Just for the sake, print the array contents
    for(j = 0; j < i; j++)
    {
       Serial.print(byteArray[j],HEX);
    }

    //Check for first two bytes
    if( (byteArray[0] == 0x31) && (byteArray[1] == 0x32) )
    {
        Serial.println("Verified.");
    }
}

To test this program, I entered "12345" (without quotes) on the serial monitor which gave me an output as "3132333435" since I'm printing the contents of the array in HEX format.

What I'm not being able to understand is even if this output shows that the first two bytes in the array are 0x31 & 0x32 respectively, why not the verification logic of those two bytes is getting executed? If it would, then the string 'Verified' would get printed on the output.

Am I doing something wrong here with Serial.read() or some typecasting?

I'm running this on an Arduino Uno


texts:
I'm a newbee to Arduino programming and hoping someone can help me with this. These are the errors when uploading the proceeding sketch. Thanks in advance!

avrdude: stk500_rcv() : programmer is not
responding

avrdude: stk500_getsync() attempt 10 of 10:not in sync:

Problem uploading to board.

//www.RobotLinking.com
//2015.5.7
/************************************************/
#include <Servo.h>
/************************************************/
Servo myservo;//create servo object to control a servo
/************************************************/
void setup()
{
  myservo.attach(9);//attachs the servo on pin 9 to servo object
  myservo.write(0);//back to 0 degrees
  delay(1000);//wait for a second
}
/*************************************************/
void loop()
{
  myservo.write(15);//goes to 15 degrees
  delay(1000);//wait for a second
  myservo.write(30);//goes to 30 degrees
  delay(1000);//wait for a second.33
  myservo.write(45);//goes to 45 degrees
  delay(1000);//wait for a second.33
  myservo.write(60);//goes to 60 degrees
  delay(1000);//wait for a second.33
  myservo.write(75);//goes to 75 degrees
  delay(1000);//wait for a second.33
  myservo.write(90);//goes to 90 degrees
  delay(1000);//wait for a second
  myservo.write(75);//back to 75 degrees
  delay(1000);//wait for a second.33
  myservo.write(60);//back to 60 degrees
  delay(1000);//wait for a second.33
  myservo.write(45);//back to 45 degrees
  delay(1000);//wait for a second.33
  myservo.write(30);//back to 30 degrees
  delay(1000);//wait for a second.33
  myservo.write(15);//back to 15 degrees
  delay(1000);//wait for a second
  myservo.write(0);//back to 0 degrees
  delay(1000);//wait for a second
}
/**************************************************/


texts: Why can't I use just the digital pins and a ground to use a potentiometer?

texts:
First of all I am a newbie. So please excuse.

After doing the first basic project, in which I had hooked up the positive of a LED to a digital input of the Arduino and the negative to the ground of the board, I am assuming that the digital pins in Arduino are positive (are they 5v?).

So why can't the potentiometer be connected in the same way?

Thank you.


texts: The easiest and most time efficent way to connect to the internet regardless of the cost

texts:
I am working on my graduation Project. I want to use the cayenne (mydevices) platform to control my Arduino. Mainly I want to be able to control a servo Motor through the Cayenne app and I want to use a gyro sensor that would also control the servo using the app after obtaining the readings from the sensor. The Options are:
1- Yun arduino
2- Arduino Ethernet
3- Arduino uno (which I currently have) + Arduino Ethernet shield or arduino wifi shield

Cayenne (mydevices) APP supports all of the above Options

What is the easiest to implement? I have short time period and working on the mechanical design for the Project in the same time.

Your help is appreciated


texts:
I am trying to execute the sweep program but all the servo does is go back and forth in one step. When I tried changing the delay, It behaves erratically.

Servo Specs:

Required Pulse: 3-5 Volt Peak to Peak Square Wave
Operating Voltage: 4.8-7.2 Volts
Operating Temperature Range: -10 to +60 Degree C
Operating Speed (4.8V): 0.18sec/60 degrees at no load
Operating Speed (6V): 0.16sec/60 degrees at no load
Operating Speed (7.2V): 0.14sec/60 degrees at no load
Stall Torque (4.8V): 11kg/cm
Stall Torque (6V): 13.5kg/cm
Stall Torque (7.2V): 16kg/cm
360 Modifiable: Yes
Potentiometer Drive: Indirect Drive
Bearing Type: Double Ball Bearing
Gear Type: All Metal Gears
Connector Wire Length: 12"
Dimensions: 1.6" x 0.8"x 1.4" (41 x 20 x 36mm)
Weight: 56gm

Sweep Code:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

I tried both powering up internally and externally. Internally it responds but externally, arduino's L LED is high all the time and servo does not respond. May I know what is actually going wrong here.


texts: Use ESP-01 with Arduino Uno/Nano, with the ESP8266WiFi library

texts:
There is this library - https://github.com/esp8266/Arduino
That provides a more user-friendly API for WiFi capabilities with the ESP8266.

However, all tutorials that I found so far for this library show how to program the ESP8266 (usually 12) directly. That is not what I'm looking for.

My current setup is having an Arduino Uno/Nano where the ESP8266 is connected to, say, GPIO8 and GPIO9 (RX, TX) and I use SoftwareSerial to communicate with it with AT commands. So I want to keep all the logic in my Arduino, but use ESP-01 only to provide WiFi capabilities to my Arduino.

However in that library I don't see the option to set the serial port pins (RX and TX) so I'm not sure if that's even possible.

In short - I want to use this library, but not program the ESP directly. Also, I'm using an ESP-01 and not 12.

Thanks.


texts: Where is random defined with no arguments?

texts:
I can't seem to find void random() (with no arguments) defined in the library and yet my sketches seem to compile just fine when calling random() with no arguments.

I've found random with 1 argument and random with 2 arguments but no cases of random with no arguments.

Is random() defined in the library with no arguments?

If so, where is it defined?

If it isn't, what could explain how my code compiles despite me not providing any arguments?


texts:
In our college we are using a module developed by IIT Bombay (called FIREBIRD V[ver 5]). It has ATmega2560 and ATmega8 microcontrollers (master and slave) with bootloader.

The staff uses AVR Studio for programming. But since AVR Studio is supported only on Windows (and I have a Mac), I was looking for AVR programming in Mac. I downloaded Crosspack AVR. But I don't know how to proceed after this point. Also I downloaded TextWrangler (because I was told auto-suggestion is not available in TextEdit).

Also I have downloaded the Arduino IDE, and I don't know what is required or how to configure it to program AVR microcontrollers.

I searched on the web and nothing is clear (mostly they all depend on something to do with terminal and the command line).

I don't have Xcode installed in my Mac (I saw a relatively easy tutorial on how to set up Xcode for this purpose) and the file is 4GB. I am trying to work around using Xcode, but if it's the only nice way do let me know!

Pertinent suggestions would be helpful.


texts: Serial.print() is slower than it should be

texts: I'm trying to use Arduino as a DAQ but the Serial.print() is not working as fast as I expected. How many bits are sent if you are using a int, because if I use a uint8_t, it's taking the same amount of time? How I could improve the speed of the Serial.print()? I'm already working at 115200 baud.


texts: getting started with programming Arduino board in C/embedded c

texts: I want to move away from Arduino IDE and start directly working with avrdude. Can anyone tell me some resources and tips on starting and moving forward with using C/embedded C to access more functionality.Would appreciate some help.


texts:
I am using an ArduinoFio and a BC127 (datasheet). I'm having troubles getting the serial connection working properly from the Arduino to the BC127 and viceversa. I wasn't able to communicate with the BC127 and I don't know if is because isn't correctly powered on or something else.

I've connected pin 0 of the BC127 to GND, pin 33 to 3V3 and pin 41,42 (RX, TX) to the TX, RX arduino's pins.

I've tested with the tester that all wires are connected, but the BC127 seems dead.

Any help is appreciated :|


texts: HC-SR505 PIR Sensor only outputting HIGH

texts: I recently bought an HC-SR505 Mini PIR sensor. I connected its positive to my Arduino UNO's 5v, output to digital pin 2, and ground to ground. I used Adafruit's code to test it, but all the serial monitor displayed was "Motion detected", which meant the PIR was always on a HIGH state. I then also tried powering it using 3V3 but the PIR kept on cycling on a HIGH and LOW state. Any help on getting my sensor to actually work would be greatly appreciated.


texts: SPISettings was not declared in this scope

texts:
I'm trying to compile a simple I2C example to read data from an MPU-6050 accel/gyro sensor, but I'm getting the compilation error:

/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:27:8: error: 'SPISettings' does not name a type
 static SPISettings settings;
        ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp: In member function 'void Sd2Card::chipSelectHigh()':
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:167:9: error: 'class SPIClass' has no member named 'endTransaction'
     SPI.endTransaction();
         ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp: In member function 'void Sd2Card::chipSelectLow()':
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:176:9: error: 'class SPIClass' has no member named 'beginTransaction'
     SPI.beginTransaction(settings);
         ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:176:26: error: 'settings' was not declared in this scope
     SPI.beginTransaction(settings);
                          ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp: In member function 'uint8_t Sd2Card::init(uint8_t, uint8_t)':
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:269:3: error: 'settings' was not declared in this scope
   settings = SPISettings(250000, MSBFIRST, SPI_MODE0);
   ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:269:53: error: 'SPISettings' was not declared in this scope
   settings = SPISettings(250000, MSBFIRST, SPI_MODE0);
                                                     ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:275:7: error: 'class SPIClass' has no member named 'beginTransaction'
   SPI.beginTransaction(settings);
       ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:279:7: error: 'class SPIClass' has no member named 'endTransaction'
   SPI.endTransaction();
       ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp: In member function 'uint8_t Sd2Card::setSckRate(uint8_t)':
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:518:14: error: 'settings' was not declared in this scope
     case 0:  settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;
              ^
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp:518:66: error: 'SPISettings' was not declared in this scope
     case 0:  settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;
                                                                  ^
make: *** [.build_ano/uno/SD/src/utility/Sd2Card.o] Error 1
Make failed with code 2

I've commented-out all code until it compiled without error, and I found that the error is caused by the line:

#include <Wire.h>

So my minimal code to reproduce the error is:

#include <Wire.h>

void setup(){
}

void loop(){
}

Why is this include throwing this error? Why is it trying to compile code for accessing an SD card when I have no code that uses that?

I'm using Arduino 1.6.1 and targeting the Uno. I found I can fix this error by copying version 1.0 of the Wire library into my local sketch folder.


texts: Sending data from Arduino to laptop via bluetooth using java

texts:
I intend to establish communication between my laptop and Arduino via Bluetooth. I'm using BlueCove Java API. I'm unable to understand how to send data to Arduino using this. There are no clear examples available on the internet regarding how to establish the communication between these two. Could somebody provide any information on this?
I just want to send some string to Arduino, based on which it must send back something to the laptop. Any help on this would be greatly appreciated. Thank you.


texts: Bluetooth shield/module for file transfer?

texts:
I'm currently working on a project that requires to display images on a touchscreen on my arduino. These images are neither stored in arduino nor any memory card. I want to be able to send the images via Bluetooth from an app and display it on the touchscreen. The problem is I couldn't find a good and solid Bluetooth shield or module that provide file transfer via bluetooth from an iOS app to arduino. If you can name a few bluetooh shields or modules that'd be great. In the thread below, someone claimed hc-05 works. Can anyone support that claim? Thanks.
http://forum.arduino.cc/index.php?topic=208306.0


texts:
I have a value I'm taking from a sensor module, which is 2500 when the sensor is facing a light source. This reads to my code and can be saved perfectly fine. When I try to find the weighted average of a set of values (2500*1000+2500*2000+2500*3000 etc), the Arduino comes out with very weird answers. For example

2500*1000=9632

If I just compute 2500*1000 on its own, the answer still comes out the same! The results come out negative if I use int so I switched to using double (just in case the values created were too big), this stops producing negatives as expected but the result is still like it is above.. I have no idea why.. any ideas?


texts: I'm making a trim wheel using a rotary encoder for flight simulation. Should I have the Joystick library use button presses or make it an axis?

texts:
Title says the majority of it. I'm looking to make a trim wheel for flight sim using a rotary encoder, the Joystick library and an Arduino Leonardo. I wasn't sure if it would be better to make it a button press or have it be an axis, possibly the Rx, Ry, or Rz axis.
Thanks in advance!


texts: How can I drive this LCD TFT with an Arduino?

texts:
As I understand it, the Arduino comes with a TFT library which uses SPI to drive LCD TFTs. I recently bought a TFT labelled "HY-32.TFT" on the front and "HY-TFT320_262k heyaodz111211" on the back.

It uses an XPT2046 touch screen controller, but I'm more interested in just getting something on the screen currently.

To use the Arduino library, I need to connect pins:

SCLK
MOSI
CS
DC
RESET

But I can't see these apart from some similarly named ones associated with TP (touchpad?) and SD (sd card), as the photo shows:

Is it possible to drive this with my Arduino? If so, how?

UPDATE: It looks like the datasheet for the controller and the board can be downloaded from 3.0" 3" TFT LCD Module Display + Touch Panel + PCB adapter.


texts:
I bought an OV7670 camera and I would like to use the following code:
https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno

But I wonder whether it is possible to use SPI instead of I2C when I transfer the image data through Arduino to other breakout boards.


texts: Arduino: put string through variable in array

texts:
I have a problem and I can't fix it.
I'm busy with an java to arduino project.
Java writes a string using writeString();
Arduino reads the serial monitor and put the incoming string into a function.
then I want to put the string into a variable and the variable into a char arr[];
The problem is: When I put the string directly in the arr[]; it works, but when I put first the incoming string in a variable and then the variable in the arr[]; it gives me the next error:

string-parser:44: error: array must be initialized with a brace-enclosed initializer
exit status 1
initializer fails to determine size of 'arr'

this is the code that doesnt work:
input = "2,5>2,6>2,7>4,8";

String splitStringIntoCoordinates(String input){
  char arr[] = input; // Place incoming route in char array
}

This is the code that does work:
String splitStringIntoCoordinates(String input){
  char arr[] = "2,5>2,6>2,7>4,8"; // Place incoming route in char array
}

I hope anyone can help me.
Thanks!


texts:
Yesterday I asked a question about de-bouncing this rotary encoder and Jsotola suggested that I should use a method like This to detect the previous state and then do the counting. using that method each turn is counting twice in one turn so I came up with my version of de-bouncing the rotary encoder:

int s1, s2;
int count = 0;
boolean right = 0;
boolean left = 0;
int rotary = 0;
unsigned long timer = 0;
unsigned int bounce = 50;

void setup() {
  Serial.begin(9600);
  pinMode(6, INPUT);
  pinMode(7, INPUT);

}

void loop() {

  s1 = digitalRead(6);
  s2 = digitalRead(7);
  if (s1 == 1 && s2 == 1) {
    right = 0;
    left = 0;
    rotary = 0;
  }
  if (s1 == 0 && s2 == 1) {
    left = 1;
  }
  if (left == 1 && (s1 == 0 && s2 == 0)) {
    rotary = 2;
  }
  if (s1 == 1 && s2 == 0) {
    right = 1;
  }
  if (right == 1 && (s1 == 0 && s2 == 0)) {
    rotary = 1;
  }

  if (rotary == 1) {
    if ((millis() - timer) > bounce) {
      count++;
    }
    right = 0;
    left = 0;
    timer = millis();
  }
  if (rotary == 2) {
    if ((millis() - timer) > bounce) {
      count--;
    }
    right = 0;
    left = 0;
    timer = millis();
  }
  Serial.print(s1);
  Serial.print(s2);
  Serial.print(", ");
  Serial.print(count);
  Serial.println(" ");
  delay(15);
}

The code is working just fine. When turning the rotary this are the steps that I get:

10-00-01 < (11) > 10-00-01

problem is if I turn the knob quickly rotary encoder will skip one or two steps like: 01-01-01 < (11) or 10-00-00 < (11).

This problem exist in all methods/libraries (I tested them all), is there anyway to fix this with software/hardware or this rotary encoder is just junk and I should get a better one?

Another method of de-bouncing as Jsotola requested:

 int pinA = 3;  // Connected to CLK on KY-040
 int pinB = 4;  // Connected to DT on KY-040
 int encoderPosCount = 0;
 int pinALast;
 int aVal;
 boolean bCW;

 void setup() {
   pinMode (pinA,INPUT);
   pinMode (pinB,INPUT);
   /* Read Pin A
   Whatever state it's in will reflect the last position
   */
   pinALast = digitalRead(pinA);
   Serial.begin (9600);
 }

 void loop() {
   aVal = digitalRead(pinA);
   if (aVal != pinALast){ // Means the knob is rotating
     // if the knob is rotating, we need to determine direction
     // We do that by reading pin B.
     if (digitalRead(pinB) != aVal) {  // Means pin A Changed first - We're Rotating Clockwise
       encoderPosCount ++;
       bCW = true;
     } else {// Otherwise B changed first and we're moving CCW
       bCW = false;
       encoderPosCount--;
     }
     Serial.print ("Rotated: ");
     if (bCW){
       Serial.println ("clockwise");
     }else{
       Serial.println("counterclockwise");
     }
     Serial.print("Encoder Position: ");
     Serial.println(encoderPosCount);

   }
   pinALast = aVal;
 }


texts: Modular Coding - What types of code portions to convert into library files? Rationale and methods?

texts:
I'm working on documentation and combining 2 pieces of code for testing parts of a larger project.

I'm supposed to comment and make the code very clear to people who will use it later and make sure it's modular. I'm supposed to make header files, to reference function chunks in the main code from just the #include(s).

I understand in C++, that the convention is that for each header files(?), .h, there is a .cpp, where the .h is the header file that declares all the content, and that the .cpp is where you define the .h, ie. implementation.

My supervisor told me to put more parts of the code into library files, because additional components will be added in the future -

  but confused because all the length comes from using already existing
  library files, just a specific pattern of calling pre-defined
  functions.

If I put the files into a .h, how do I reference all the calls?
Make a void setup () {}?

The compiled code is 348 lines right now. All it has are some #include(s), code to calibrate and read from 2 different sensors using I2C and SPI protocols, with 1 shared master an Adafruit Bluefruit nRF52832, and comments with links to datasheets.

The bulkiness is in the set-ups and the different ways to  represent data (have 24 lines just to print out data from 1 sensor).

Should the entire code be just calling built in functions from a library file? So people who read the code don't see the details so much?


texts: Increasing payload size above 32 bytes using nRF24L01+

texts:
I tried to modify the example in the following page, by replacing the given string with a 56 bytes one after making all the suitable changes to read(), write() and max_payload_size(increased to 64 bytes), payload_size() parameters/methods in the RF24 library.

http://shanes.net/another-nrf24l01-sketch-string-sendreceive/

The problem is the receiver truncates the string to 32 characters. Is 32 bytes a hard limitation for payload with the nrf24l01+ radio? If so how to I modify the receiver in above example problem to receive the entire string?


texts: Making a current GPS code run once, and only once, after the code is 'activated'

texts:
I have a GPS code that I need to run only once, but every different try gives me errors, including placing the whole code in void setup(). Is there any way that this code can be run just once? As of now, the code repeats itself, putting out data over and over again - I need just one set, right when the code is activated.

Here is the code:

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO  true
boolean usingInterrupt = false;
void useInterrupt(boolean);

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  useInterrupt(true);
  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);
}

SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;
#endif
}

void useInterrupt(boolean v) {
  if (v) {
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop() {                  // run over and over again
  if (! usingInterrupt) {
    char c = GPS.read();
    if (GPSECHO)
      if (c) Serial.print(c);
  }
  if (GPS.newNMEAreceived()) {
    if (!GPS.parse(GPS.lastNMEA()))
      return;

  if (timer > millis())
    timer = millis();

  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
    Serial.print("\nTime: ");
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print("Location (in degrees, works with Google Maps): ");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", ");
      Serial.println(GPS.longitudeDegrees, 4);
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
    }
  }
  }
}

I've been trying to get this for a while, and I'm new to programming!


texts: Increasing the numbers of I/O pins on Arduino Uno

texts: I want to make a game of Tic-tac-toe using an Arduino, LEDs and bouncy buttons. Hence I need nine inputs and nine outputs. But you see that an Arduino only has 13 I/O pins. So is there a way I can use the analog pins or a way to reduce the number of I/O pins using an ingenious way?