texts: Lightweight PWM Servo range modification

texts:
Not having worked with servos on arduino I'm not sure how to go about this or if an arduino is the best solution. I have looked at servo actuation tutorials and can get a servo to move but rather than waste hours on the wrong approach,possibly someone has a suggestion on how best to achieve this? :

I have a tilt rotor quad, and have a mix on the pitch of the craft and the servo, which works quite well and allows some very fast forward flight. The issue is that although I can limit the servo range with trims, I cannot make the servo move full throw in half a stick of movement. Sometimes I wish to just control tilt, and sometimes just pitch. With expos you can almost achieve this but you only get about 50% of the servo movement before pitch sets in and this makes using acro with tilt impossible.

My idea is to use an arduino pro mini, (or something smaller?) to take the incoming PWM signal, and double it, outputting to the servo so that I have the full range of linear motion on half of my pitch stick input, but the servo PWM is not over driven (or doubled) when it goes to full stick.

I would also like the arduino to respond to another PWM high value which would maintain the last set pwm so that I can initiate a 'cruise control' off another switch on my TX.

Summary:

Arduino translates range of input PWM to output pwm
Arduino also maintains last set output PWM, when second incoming PWM
is high.
Nice to have: programmable input to output ranges
Nice to have: Arduino control two input and output pwms with third and fourth input pwm (or a combination of both)

Finally...

Anyone know if the arduino would be fast enough to intercept and relay an s-bus signal? modifying as appropriate... and breaking out the servo channels (s-bus to pwm)... This is obviously more involved, but infinately more camable if I can intercept comms before they get to the flight controller.

Edit:
The closest example of code I can find is as follows, and this will do one side of sbus for me (i.e. i will get sbus in and pwm out, which would work for me. however I cant see in the code any variables I can use to manually manipulate values of channels before they are sent out as PWM?

// Arduino pro mini 16 mhz decode sbus or CPPM
// detects automatically CCCPM  or a SBUS signal.

CODE HERE as I dont have enough space to post:
http://openrcforums.com/forum/viewtopic.php?t=6361

Thanks


texts:
I want to write code for my Arduino in Lua. Where I can find the necessary (pins) I/O lib and examples for Arduino IDE?
UPD: I've got arduino mega with many memory.


texts: Arduino Yun USB host - reading usb MIDI data and passing forward to another device

texts:
I am starting simple, but for some reason I cannot find any examples online and I stuck with my task.

I have a usb midi keyboard, Arduino Yun, and a synthesiser that can accept midi via usb. The problem is that the synth doesn't send a voltage through its usb and the keyboard has only one usb that is used to send midi data and it's powered via it at the same time.

My idea is to use my Yun's USB host (which sends voltage too) to power my midi keyboard and grab all incoming midi data from the keyboard, then simply pass it unchanged through to my synth.

Where do I start? Do I need some python code for it or everything can be done with sketch code? I've done few arduino projects but I am new to usb host functionality  . This is my first step, later I would like to also convert usb-midi to 5-din-midi (old school connection), but that's different story.

Can you guys help me and point into the right direction? Anyone done something similar on Yun? I've seen some examples done on different boards, but it's all overcomplicated, I need simple read/pass usb solution. Thanks!


texts: How can I just wait to receive a UART message on my system?

texts:
I wrote a code for making my steppers and servo motors work to be specific 5 stepper motors and 3 servo motors with some sensors too.
Now I need to receive a feedback from my arduino mega after the particular set of movements have finished so my system can calculate the next set of inputs to feed to the arduino.
The arduino is connected to computer with USB and thus I am using UART.


texts: How to update the character table of MAX7456

texts:
I've got a MAX7456 chip and I am using this library with it.
But the issue is that the character table is not the one the library needs to function like it should. The "Hello world" example is nowhere near to what it should display, because the character table is wrong.

All the instructions that talk about character set updating require a USB FTDI cable (I don't have one), I am able to  program the board with USBASP programmer but that's it. I also have a few Nanos, if that helps.

How could I update the character table to what the library needs (without a FTDI cable) or how to make the sketch included to update the character set work properly?


texts:
I am using millis() to flash some lights (neopixels) on an arduino pro mini. The problem is that I cannot flash the lights for the desired period. More specifically, the lights flash for ~250 ms, whereas I want to flash for 9 seconds! Here is a simplified version of what I am doing.

In loop(), I have a while loop (let's call it loop 1) that should run for 250 ms. Inside loop 1, I call a function flash(), that has to run for 9 seconds! I put another loop (loop 2) after loop 1, that would run for 3 seconds.

Here is the bigger picture...I actually want a radio to wake up for 250 ms. If in that time interval it receives anything, flash() will be called that will flash the lights for 9 secs. If it doesn't receive anything it will simply go to sleep for 3 secs, then come back alive for 250 ms, so on and so on

void loop() {
    previousMillis = millis();
    while (millis() - previousMillis < awake_interval) {  //awake_interval = 250 ms
        flash();  //flash for 9 seconds
    }

    previousMillis = millis();
    while (millis() - previousMillis < sleep_interval);  //sleep_interval = 3 secs
}

The flash() function looks like this,

void flash() {
    unsigned long x = millis();
    while(millis() - x < flash_time){  //flash_time = 9 secs
        lights_on();
        delay(t1);
        lights_off();
        delay(t2);
    }
}

I put loop 2 in there because without it the lights flash forever. This makes sense because all the code is in an infinite loop - void loop().

For debugging, I put serial prints after entering the loops. It seems that nesting two loops (in my case flash() inside loop 1), both of which uses millis() is the source of the problem. If that is true, how else should I do this? If that is not the problem, any ideas will be appreciated.

Edit: The suggestions made by @VE7JRO and @ratchet freak are neat but I was still having problems making my thing work. Turns out it was a problem with one my initializations. I am posting my whole code below (that uses LEDs). I guess I should post the correct code as an answer.

const long sleep_interval = 3000;
const long awake_interval = 250;
const int ledPin = 3;

const uint8_t flash_time = 9000;  //bug
const uint16_t t1 = 5;
const uint16_t t2 = 495;

void flash() {
    unsigned long x = millis();
    while(millis() - x < flash_time){
        digitalWrite(ledPin, HIGH);
        delay(t1);
        digitalWrite(ledPin, LOW);
        delay(t2);
    }
}

void setup() {
    Serial.begin(57600);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    unsigned long x = millis();
    while(millis() - x < awake_interval){
        Serial.println("flash time!");
        flash();  //overflow will occur
    }

    unsigned long y = millis();;
    while (millis() - y < sleep_interval) {  //sleep_interval = 3 secs
        Serial.println("Sleep time!");
    }
}


texts: options for wireless data broadcasting to hundreds of nodes

texts:
I would like to build approx 100 arduino devices that can talk to each other, I have a set of constraints that I'm looking to get some insight on :

all devices would operate within a 300 meter proximity of each other
the devices each need to broadcast some data (their speed and
orientation from a gyro) to the rest of the devices in the group for
storage
They need to update each other roughly every 500ms/1s
Some of the devices need to be added and removed from the pool regularly
The devices need to start broadcasting their data to the rest of the
devices in the pool immediately when added (<1s delay)
The spectrum needs to be public & unlicensed

Which method of communication would you recommend? For the range, it seems like a 433hz RF transceiver and receiver would be appropriate or wifi could work but I have concerns about overloading the channels. Bluetooth seems like it has too long a handshake period and the range is too low.

Are there any other options I'm missing? What would be the best way to implement this?

Many thanks for you answers

Update : Data estimation

So the data payload I estimate consists of :

Speed (km/ph) : ok so this will be max 3 decimal numbers, so one short int should be enough here (2 bytes)

bearing : so this will be a standard bearing, let's assume between 0-360 so another short int should be fine (2 bytes)

Velocity : ok, so also a short (2 bytes)

Long : well this needs to be a 32 bit float so it's going to take 4 bytes

Lat : same as above 4 bytes

It's possible with some hackery I could combine speed, volcity and bearing into one short to only take 2 bytes. But let's assume I'm probably going to need 14 bytes, in best case 9.


texts:
I am trying to read an SD card info by Arduino and an SD card module. But the SD card is not responding. I connected the wires carefully several times but it is not working.

I am using this module :

And the code is :

// include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;

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

  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);     // change this to 53 on a mega

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {

}

The errors are :

initialization failed. Things to check:
* is a card is inserted?
* Is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

The SD card formatted with this software :
https://www.sdcard.org/downloads/formatter_4/

Wiring :

** MOSI - pin 11 on MEGA 2560
** MISO - pin 12
** SCK - pin 13
** CS - pin 4


texts:
I write code to upload to ESP8266. I wish to use time stamp in order to log events. I found an NTP sketch, I can work with ( since it has a wifi connection ), but I wish to keep my code as simple as possible.

So I'm thinking to use my MQTT server to send time updates from time to time ( have a certain topic for that ), and in between updates, use millis() .

Since I'm new here, I want to know from experienced programmer if it makes sense ?
I would love to hear pros and cons ( before I start coding ).

Any help will be appreciated,

Guy


texts:
When I try to upload a script to my Genuino Uno from the Linux ARM distro on genuino.cc/downloads it spits out this during compiling.

avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
ioctl("TIOCMGET"): Inappropriate ioctl for device

Has anyone got any ideas?

Thanks,
Caleb


texts: Selling a product using Arduino microcontroller or bootloader

texts:
I was wondering if I am legally allowed to sell an Arduino based product.  I also want to know if it is easy for people to retrieve code from an Arduino based circuit (reverse engineer it) or upload code from Arduino microcontrollers.

If I'm posting in the wrong please, please let me know. If there is better place to redirect my question, letting me know would be helpful too.


texts: How to communicate with ESP8266 ESP01 by sending data through softwareserial on Arduino Uno?

texts:
I am able to send AT commands when connecting to the software through the TX/RX pins (1, 0) and the ESP01 communicates perfectly. However, as soon as I start doing that same thing with code I can't get the ESP01 to respond whatsoever. All I'm trying to do is get an OK back from the serial monitor. I changed the baudrate on the ESP01 as well as my serial monitor from 115200 to 9600, 19200 using this command:

AT+UART_DEF=9600,8,1,0,0

Troubleshooting steps taken:

Tried upping the voltage in case it wasn't getting enough current.
Tried different ESP01s.
Tried switching TX and RX pins.
Tried using different pins on the Uno (2 and 3, 10 and 11, 7 and 8).
tried changing myESP.println("AT"); to myESP.write("AT\n\r");.

Nothing works. I've done a ton of research and I haven't found anything wrong with what I'm doing, do you guys have any ideas?

#define TX 3
#define RX 2
String ssid = "*****";
String password = "******";

#include "SoftwareSerial.h"

SoftwareSerial myESP(RX,TX);

void setup() {
  pinMode(RX, INPUT);
  pinMode(TX, OUTPUT);
  myESP.begin(19200);
  Serial.begin(19200);
}

void loop() {
  myESP.println("AT");
  delay(5000);
}

Schematic is as follows:
TX -> pin 3
RX -> pin 2
Vcc -> 3.3v
GND -> Ground
CH_PD -> Vcc


texts:
i made a project with arduino in wich I used arduino to activate 18 n-ch mosfet with PWM. I used the softPWM library to use PWM in 18 output pins, I used a nano v3.

The question is about the maximum current a single pin (and a group) can handle. A raw info can be found here http://www.pighixxx.com/test/wp-content/uploads/2014/11/nano.png and it's a 20mA/pin and 200mA/group but it's not explained if that current is a peak current or an average current.

Increasing the load resistor will case a smaller peak current but will increase the time in wich the mosfet is resistive (hence it will heat up the mosfet). Considering that the pwm frequency is lower than the one defined by the resistor-mosfet, the average drained current is related to the PWM frequency and to the mosfet capacitor (NOT to the load resistor).

Is the current defined as maximum peak current or as continuous current (and which is a typical peak time for the CPU)?

Mr google gives me different and contradictory informations, i found people that uses PWM without load resistors and people that limit the peak current to 20mA. In my project i limited the maximum current to 50mA so I'm sure to have the worst performance i can have keeping the risk of burning my small friend.

Thanks


texts: If condition for switch not working as expected

texts:
I am trying to write a simple program to control one LED with two switches.
If any of the switches is pressed, I want to turn the LED on.
My LED however is always ON even when none of the switches are pushed.
Why could this happen?
Thanks!
https://www.tinkercad.com/things/7SRoEXkHRqh-one-led-two-switches-


texts: Blank project gives errors while uploading Arduino Leonardo on Linux Manjaro

texts:
I'm on Linux Manjaro. I plugged my Arduino Leonardo clone (that I know works correctly). And tried to flash a blank project on it:
(My IDE version is 1.8.12)

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

}

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

}

It gives me this error:

Sketch uses 3410 bytes (11%) of program storage space. Maximum is 28672 bytes.
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes.
processing.app.debug.RunnerException
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
    at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
    at processing.app.SketchController.upload(SketchController.java:732)
    at processing.app.SketchController.exportApplet(SketchController.java:703)
    at processing.app.Editor$UploadHandler.run(Editor.java:2047)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: processing.app.SerialException: Error touching serial port '/dev/ttyACM1'.
    at processing.app.Serial.touchForCDCReset(Serial.java:107)
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
    ... 5 more
Caused by: jssc.SerialPortException: Port name - /dev/ttyACM1; Method name - openPort(); Exception type - Permission denied.
    at jssc.SerialPort.openPort(SerialPort.java:170)
    at processing.app.Serial.touchForCDCReset(Serial.java:101)
    ... 6 more


texts:
I want to make a serial program with input from the serial monitor and show each character with its binary and ASCII codes.

At the end of the program, I want to show the whole message sent from the serial monitor but I don't know how to stop the loop. Can someone help me please?

Here's my program:

String dataST;

void setup() {
  Serial.begin(9600);
  Serial.println("Message sent by serial monitor : ");
}

void loop() {
  for (int i = 0; i < 400 ; i++) {
    if (Serial.available()) {
      char dataOK = Serial.read();
      dataST += dataOK;
      Serial.print(dataOK);
      Serial.print(" = ");
      delay(200);
      for (int i = 7; i >= 0; i--) {
        byte bytes = bitRead(dataOK, i);
        Serial.print(bytes, BIN);
      }
      Serial.print(" = ");
      int dataAS = dataOK;
      Serial.print(dataAS);
      Serial.println(" ");
      Serial.println(" ");
    }
  }
  Serial.println("Message : ");
  Serial.print(dataST);
  dataST = "";
}

The result from the program above is:

Message sent by serial monitor :
Message :
Message :
Message :

And the result I want is:

Message sent by serial monitor:
H = 01001000 = 72

e = 01100101 = 101

y = 01111001 = 121

Message :
Hey

Please help me.


texts: ESP8266 - How to recieve UDP multicast packet?

texts:
how can I recieve udp multicast packets in ESP8266? I have this piece of code:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "my_wifi_ssid";
const char* password = "my_wifi_password";

WiFiUDP Udp;
unsigned int multicastPort = 5683;  // local port to listen on
IPAddress multicastIP(224,0,1,187);

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

    Serial.printf("Connecting to %s ", ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
    delay(500);
    Serial.print(".");
    }
    Serial.println("connected");

    Udp.beginMulticast(WiFi.localIP(), multicastIP, multicastPort);
    Serial.printf("Now listening at IP %s and %s, UDP port %d\n", WiFi.localIP().toString().c_str(), multicastIP.toString().c_str(), multicastPort);
}

void loop(){
    int packetSize = Udp.parsePacket();
    if (packetSize){
    Serial.println("RECEIVED!");
    }
}

I wrote it according to this documentation and this addition to that about adding multicast.
It just set server listening on port 5683.
It prints something like:
Now listening at IP 192.168.1.6 and 224.0.1.187, UDP port 5683
But if I send UDP packet to 224.0.1.187:5683 (eg. via Packet sender app), it doesn't print message "RECEIVED!" (which should, look in loop function). Why ESP8266 is not receiving anything? Strange is, that when I send packet to 192.168.1.6:5683 (its local IP), it prints that message ("RECEIVED!").
Why it works only for local message but not for multicast??
Thanks for every help! :)
PS: this advice didn't help me...


texts:
I'm looking for a Normally-Open optocoupler board for arduino. I need to control power of a device (DC 12v, 500mA).
I tried to use TLP281 board, which works, except that it inverts the output: device is powered when there is no control signal (i.e., it is Normally-Closed).

For this reason, the TLP281 board is not useful in my project.

This is picture and schematics for TLP281 board:

I need an optoisolator board which works analogous to normally open mechanical relay: when there is no signal, device must not be powered; and when there is signal, device must be powered.

NOTE: workaround by inverting the control signal in microcontroller firmware is not permitted, as the device must not be powered when microcontroller is off


texts: Attiny : Is it possible to analog read on PB1?

texts:
I'm trying to read an analog input on the Attiny85 physical pin 6 (PB1, PWM), but analogRead(PB1) always returns 1023. Is it even possible to use analogRead on this pin?
I'm fairly new to this so sorry if it's an obvious answer.
Thanks!


texts: how write or change the data on writable tags like tk4100, hitags256, em4305 125khz tags?

texts: I have arduino uno and rdm6300 module with tk4100, hitag s256, em4305, nxp s256


texts: How to merge temperature sensor DHT22, RTC DS3231 and button

texts:
I am currently working on the fan function, which would be able to switch every minute for 10 seconds with RTC DS3231, at the same time I would like to incorporate a temperature sensor DHT22 and button, in the case of program part DHT22 + button , it also works, but if I have a DHT22 + RTC DS3231 + Button, only the temperature sensor and the button work. Thank you for any advice

#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>

#define DHTPIN A2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

DS3231  rtc(SDA, SCL);
Time t;

const int OnSec = 30; //TURN ON

const int OffSec = 50; //TURN OFF

float set_temp_cool = 27.0; //setting max temperature

int relay_1   = 3; //relay pin
int button_1  = 8; //button pin

LiquidCrystal_I2C lcd(0x27, 2, 1,0,4,5,6,7,3, POSITIVE);

void setup() {
 lcd.begin(20,4);
 dht.begin();
 rtc.begin();

 pinMode(relay_1,OUTPUT);           //fan
 pinMode(button_1, INPUT_PULLUP);   //fan - button
}

void loop() {
  t = rtc.getTime();

  Zobrazeni();

  Vetrak();

  lcd.clear();
}

void Zobrazeni(){
  float temp = dht.readTemperature();
  lcd.setCursor(0,0);
  lcd.print(rtc.getTimeStr());
  lcd.setCursor(0,1);
  lcd.print("Tepl: ");
  lcd.print(temp);
  lcd.print(" C");
  }

  void Vetrak(){
  float temp = dht.readTemperature();
  int button_1 = digitalRead(8);
  int timerPhase = ( (t.sec < OffSec) && ( t.sec > OnSec ) ) ? 0 : 1;
  t = rtc.getTime();

  if (button_1 == LOW)      //if button is pressed - trigger relay
    {
    digitalWrite(3,LOW);
    }
  else if (temp < 26)           //if temp is above 27° - trigger relay
    {
    digitalWrite(3, HIGH);
    }
  else               //turn on every minute in 40 sec and turn off at 50 sec
    {
    if (timerPhase == 1)
    {
    digitalWrite(3,HIGH);
    }
    else
    {
    digitalWrite(3,LOW);
    }
    }
  }


texts: Sending JSON message to web api via post. Why does HTTP 1.0 versus 1.1 make a difference?

texts:
I am sending a message to a web api call every xx seconds. I could not get it to work at all until I changed the header from HTTP 1.1 which is what I was using to HTTP 1.0. Then, it started working. Why would this affect things where I could not post and now I can?

This is what it was when it wasn't working:

client.println("POST /BoxLevel/api/BoxMeasurement HTTP/1.1");

And the change that fixed it:

client.println("POST /BoxLevel/api/BoxMeasurement HTTP/1.0");

Thanks!


texts:
I at the moment trying smoothly move a stepper motor. The problem with the stepper motor, is that it makes a high pitch noise while it moves, or sometime a crackling noise from the motor.

So i tried ramping up the frequency of the step signal, which seemed to help a bit but not perfect. Then I tried micro stepping rather than  full stepping, which also helped a bit but still, the noise is very clear.

The motor I am using is a PK244-01A
And the driver it is connected to is this one

I am not at all sure if the ramping I do is either too steep, or completely  incorrect, but here is the code that controls the motor.

void stepper_motor::step_pwm()
{

    digitalWrite(en_pin,HIGH);

    delay(0.005);

    digitalWrite(dir_pin,HIGH);
    //LOW  - Move towards the sensor
    //HIGH -  Move away from the sensor

    delay(0.005);
    int increment = 0;
    int step_count = 0;
    while(step_count <= max_step)
    {
      digitalWrite(step_pin,LOW);
      delayMicroseconds(2000);
      digitalWrite(step_pin,HIGH);
      delayMicroseconds(2000-increment);
      step_count++;

      if(step_count >= 1)
      {
        increment++;
        step_count = 0;
      }
    }

}

Anything I could do to make the noise of the motor less significant?


texts: Why does this not put my Arduino Mega to sleep?

texts:
I have the following program which is supposed to print the words "Program is on" once and then go to sleep. However it doesn't go to sleep and continues to print "Program is on" over and over again.

#include <avr/sleep.h>

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

void loop()
{
  Serial.println("Program is on");
  sleepNow();
}

void sleepNow()
{
  // Choose our preferred sleep mode:
  set_sleep_mode(SLEEP_MODE_IDLE);
  // Set sleep enable (SE) bit:
  sleep_enable();
  // Put the device to sleep:
  sleep_mode();
  // Upon waking up, sketch continues from this point.
  sleep_disable();
}


texts: How to move Servo in between three positions

texts:
I want my tower pro 9g servo to start from pos=0, wait there for 1 second, then reach pos=90 wait for 1 second, then reach pos=180 and wait for 1 second. Now it goes back to pos=0 and repeats this cycle. I have written the following code for this purpose:

#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(12);  // attaches the servo on pin 9 to the servo object
}

void loop() {

  for (pos = 0; pos <= 180; pos += 90) { // goes from 0 degrees to 180 degrees
    // in steps of 90 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(1000);                       // waits 1s for the servo to reach the position
  }

  for (pos = 180; pos >= 0; pos -= 90) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(1000);                       // waits 1s for the servo to reach the position
  }

}

But the behavior of the servo is not correct. It moves few degree from  initial position and then comes back.

What is wrong with the logic in my code ?


texts: Power supply affecting sensor readings ESP8266 and JSN-SR04T-2.0

texts: I have an ESP8266 Wemos D1R2 Board with a JSN-SR04T-2.0 ultrasonic range finder and everything works perfectly when I have the device connected to my computer USB or via a 12V battery into the onboard regulator via the external power jack. However when I use a 240V AC to 12V DC transformer to power the setup my readings become quite erratic. I have checked the voltage coming out of the power supply (12.48v) and the voltage going to the sensor (3.28V,  I have it coming off the 3.3V pin) and it is the same on each type of power supply so the onboard regulator is working. Can anyone advise what might cause this? The transformer provides 1A which is more than enough as I have measured the peak usage at <100ma


texts: What specific type of plastic does the Arduino Braccio arm use?

texts: I've looked all over and I can not find the specific type of plastic that the Arduino Braccio arm uses.


texts: Arduino based SPI programming of LT1257 not working

texts:
I am trying to talk to an LT1257 using an Arduino Nano Atmega328. I am not using the default slave select pin. I am using pin 5 as chip select for the DAC. The LT1257 data sheet shows this timing diagram. What I inferred from this diagram is that SCLK can be used to clock in the data and it remains in the shift register and is loaded into the DAC register only when Load is pulled low.

I wrote this snippet to load a 0x0000 to the DAC. However, when I probe the output voltage it is ~1.02V. The DAC uses an internal reference of 2.048V. So I think this must be the default 1/2*FS output when the DAC powers on.
Please review my code and point the errors. (At the DAC output I have a 1k resistor connected to ground).

#include<SPI.h>
#define SCLK 13
#define MISO 12
#define MOSI 11
#define DAC_LOAD 5

#define DAC_SPI_CLOCK_SPEED 1000000 //Upto 1.4MHz

void setup()
{
Serial.begin(9600);
init();
SPI.begin();
dac_write();
}

void init()
{
pinMode(SCLK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(DAC_LOAD, OUTPUT);
digitalWrite(SCLK, HIGH);
digitalWrite(MOSI, HIGH);
digitalWrite(DAC_LOAD, HIGH);
}

void dac_write()
{
SPI.beginTransaction(SPISettings(DAC_SPI_CLOCK_SPEED, MSBFIRST, SPI_MODE0));
delay(10);
SPI.transfer(0x0000);
delay(10);
digitalWrite(DAC_LOAD, LOW);
delay(10);
digitalWrite(DAC_LOAD, HIGH);
delay(10);
SPI.endTransaction();
}

void loop()
{
while(1)
{
Serial.println("Ping!");
delay(1000);
}
}


texts:
I just purchased this Grove RTC. It includes a cable presumably to connect it to a breadboard and/or Arduino, but the pin holes on this cable are much smaller than those on a breadboard or Arduino.

How/where would I connect this in the case of using an Arduino Uno?


texts:
This might be a very simple question but I don't know which key represents KEY_LEFT_GUI on my keyboard. I thought it was the windows key but when I program Arduino Micro to execute it. Run does not open and it prints powershell on the "Search Programs and Files" section in Windows7 VM.

  Keyboard.press(KEY_LEFT_GUI);
  delay(1000);
  Keyboard.press('r');
  delay(1000);
  Keyboard.releaseAll();

  delay(500);

  Keyboard.print("powershell");
  typeKey(KEY_RETURN);


texts: Wemos: relay shield doesn't work on top of the stack

texts:
I connected a SHT30 shield to a Wemos D1 mini (one on top of the other) to measure temperatures.

Wemos D1 mini (2.3.0):
SHT30 shield:

It works great but when I added a relay on the top of the stack it doesn't work anymore.

Relay shield:

Maybe there are a conflict with their pins. So these are their schematics:

This is the solution that I made but I don't know why this works instead of inserting the relay shield on top of the SHT30 shield:


texts:
I am reading sensory data that comes from the digital inputs(two DHT11 Humidity sensors using adafruit library.) and I would like to add a hh:mm:ss real time counts next to them. I try to use the time.h library but could not understand how to worked it in that way.

My code is;

#include "DHT.h"

#define DHT1PIN 4
#define DHT2PIN 7

#define DHT1TYPE DHT11
#define DHT2TYPE DHT11

DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("Humidity sensors DHT11 tests!");

  dht1.begin();
  dht2.begin();
}

void loop() {

  delay(2000);

  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
  float h2 = dht2.readHumidity();
  float t2 = dht2.readTemperature();

  if (isnan(t1) || isnan(h1)) {
    Serial.println("Failed to read from DHT #1");
  } else {
    Serial.print(h1); Serial.print(" \t");
  }

  if (isnan(t2) || isnan(h2)) {
    Serial.println("Failed to read from DHT #2");
  } else {
    Serial.print(h2);
    Serial.print(" \t");
  }
  Serial.println();
}

and my serial port out is;

and I want it to be like that;

Any help will appreciated.


texts: An Input device to enter ssid and password NodeMCU

texts: I'm doing a Node MCU based project to control small leds and stuff like that the problem is i neet to take it to many places and i cannot change the network ssid and password through the Arduino IDE and flash the program all over again again all the time. furthermore my arduino IDE crashes all the time when i'm working with Node MCU so it is also unreliable. so can anyone suggest me a way to implement this feature where i can connect any kind of input device like laptop or phone or a keyboard or anything else that i can use to enter the ssid and password into the NodeMCU whenever needed.


texts: How can I make my arduino start when a magnet is sensed, and stay running until the application determines it was to shut down

texts:
My thought was to use a magnetic reed switch to turn on the arduino.  But how do I keep it running if the magnet is moved?  The idea is that the application will determine when it is ok to shut off the power to the arduino.

I don't want any power usage when the system is dormant since it could be weeks between magnetic triggers.

Doug


texts: What is the purpose of the howMany integer in the wire.onReceive() function from the example code?

texts:
In the master write/ slave read example for the wire library, there is an integer declared howMany that is never used.

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

void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
   char c = Wire.read(); // receive byte as a character
   Serial.print(c);         // print the character
}
 int x = Wire.read();    // receive byte as an integer
 Serial.println(x);
}

As the function does not work without it, i would like to know what is its exact purpose.I would imagine that is something regarding the buffer size.


texts: send more than one integer on serial between Mega and nodeMcu

texts:
i have 2 integers i want to send them from Mega to nodeMcu
i get them to talk to each other
by this one on Mega :-

#include <DHT.h>

#define DHTPIN 2      // Selecting the pin at which we have connected DHT11
#define DHTTYPE DHT11 // Selecting the type of DHT sensors

DHT dht ( DHTPIN, DHTTYPE ) ;

        void setup() {
      // initialize both serial ports:
      Serial.begin(9600);
      Serial1.begin(9600);
      dht.begin ();

    }

    void loop() {
      //==========// DHT part
   humidity = dht.readHumidity ( ) ;  // Declaring h a variable and storing the humidity in it.
   temp = dht.readTemperature ( ) ; // Declaring t a variable and storing the temperature in it.
  // Checking if the output is correct. If these are NaN, then there is something in it.
   if ( isnan ( humidity ) || isnan ( temp ) ) {
     Serial.println ( " Sensor not working " ) ;
   }
   else
    Serial.println(humidity);

//========// Send to wifi
 if (Serial1.available()) {

    itoa(humidity,str1,10);
    Serial1.write(str1,2);
    itoa(temp,str2,10);
    Serial1.write(str1,2);
    }

and this on on nodeMcu :-

#include <SoftwareSerial.h>

SoftwareSerial swSer(14, 12, false, 256);
char str1[10],str2[10];
int i,j;

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

  Serial.println("\nSoftware serial test started");

}

void loop() {
  while (swSer.available() > 0) {

    Serial.println("Humidity is");
    for (i=0; i<3; i++){
    str1[i]=(swSer.read());
    }
    Serial.println (str1);
    Serial.println("Temp is");
    for (j=0; j<3; j++){
    str2[j]=(swSer.read());
    }
    Serial.println (str2);

  }

}

But i  get the  result on nodeMcu not in right order (sometimes humidity printed in place of temperature and verse vise and sometimes i get no.2

can some one help me please to figure what is wrong ?


texts:
I recently bought an Arduino Nano ( a clone actually), I installed the CH340G drivers for it and got it working perfectly fine... Played around with it for a while and then kept it aside...

Now after sometime I get time to play with it again, I was actually trying to power it with my 11.1V 2200mAh 8C LiPo battery. So I plug the JST connector to the Vin and GND pin and the LED doesn't light up. I noticed that I had plugged it in the wrong way and I immediately unplugged it. Next I make another attempt and this time I plugged the pins entirely somewhere else, again I disconnect quickly. The third time I connect it properly and the power LED lights up (phew...)

Now I move on to my computer to program it but the Arduino IDE is stuck at uploading. It was working fine before, when I hit upload, the RX LED glows VERY dimly and the board just stays like that. Only the power LED glows up, not even the LED on pin 13 glows up.
Uploading to a UNO works perfectly fine.

This is the error I get after a while-

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

Did I burn my board? Or is it just a bootloader issue?


texts: Take an Arduino or Teensy prototype to Mass production - Loading software onto microcontroller

texts:
I am developing an educational product that I would like to mass produce. I am not sure of the quantity yet, but I imagine we will make a few hundred PCBs at least to begin

I spoke with an electrical engineering about how to take an Arduino prototype to mass production, and he warned me that the code written in the Arduino IDE cannot be fused onto the processor. (He used the term "fuse", although I don't see this elsewhere in the forum. is this the right term?)

He said that I would probably have to take each product, and load the Arduino code on manually, plugging in each one to a computer and upload like one would when prototyping. Also, he said the other option would be to recode my Arduino sketch from scratch using an AVR code.

Can someone shed some light on this for me? How can I take Arduino prototyping code and use it in mass production?


texts: Can't get Ubuntu to see FTDI cable for breadboarding Arduino project

texts:
I am in the process of breadboarding an Arduino for a project and am using my FTDI Serial cable Adafruit FTDI Cable (tested working on Windows 7). I have also tested the breadboarded Arduino successfully on Win7.

When I plug the FTDI Serial cable into my Linux (Ubuntu 14.04 with Mint Desktop) laptop and the other end to my project (exactly as I did for Windows and it works for Win7), the Tools, Port is grayed out when in Linux.

I have tried running Arduino as root, with no success.

The output of : dmesg | tail is

sudo dmesg | tail
[  729.069015] usb 4-1.2: New USB device strings: Mfr=1, Product=2,     SerialNumber=3
[  729.069019] usb 4-1.2: Product: TTL232R-3V3
[  729.069022] usb 4-1.2: Manufacturer: FTDI
[  729.069024] usb 4-1.2: SerialNumber: FTF50VXW
[  729.487689] usb 4-1.2: USB disconnect, device number 4
[  729.615330] usbcore: registered new interface driver usbserial
[  729.615384] usbcore: registered new interface driver usbserial_generic
[  729.615432] usbserial: USB Serial support registered for generic
[  729.621997] usbcore: registered new interface driver ftdi_sio
[  729.622057] usbserial: USB Serial support registered for FTDI USB Serial Device

When I type "lsusb" into the terminal, there is no difference between when the FTDI is plugged in and not plugged in.
I have tried switching ports with no success.

Any suggestions?


texts: How do you program to make a random timer to start and stop to music?

texts: I need to program a timer that will work randomly to any music playing in the background.  The timer starts when the music starts and timer stops when the music is stopped.  How do I do this?


texts: Do we have to calibrate LDR before using it in a project?

texts:
I am doing a project with Arduino, making a synthesizer, in which an LDR is used.

Before connecting the Arduino to a power source and use the project, do I need to calibrate the LDR like it is explained in Arduino website ?


texts: Can I use a MCP23017 to connect multiple RC522 modules?

texts:
I want to connect multiple (exactly 64) RFID-RC522 modules to one Nodemcu ESP8266.
I already know, that it is possible to connect multiple RC522's by just using different pins for the SDA pin, while the rest of the RC522 pins can be connected to the same pins on the ESP8266. But not that many, of course.
My research on "how do I get more pins", got me to the MCP23017 port expander.
Further research is not exactly clear, if I can use these pins as ChipSelect/SlaveSelect pins for the RC522.
The two libaries I found for MCP23017 (blemasle/arduino-mcp23017 and Adafruit-MCP23017 seem not to support this, when I use miguelbalboa/rfid (which I have to use, as there seems to be no alternative), because the MCP-Libs do not provide a "Pin Number" for the MFRC522 constructor(?).
So, is this just a "software" thing, or a technical limitation, and what I want is simply not possible? My research was not exactly clear about this, but I'm also very new to electronics and might be researching in the wrong direction.


texts: Changing Uid Using MFRC522 Via Arduino Error

texts:
Well, I' ve just bought and recieved a MFRC522 rfıd module and done to much research on it. After watching several videos, I sorted out a library for using this module via arduino.
You can click the first link below to be navigated to Miguel Balboa' s github page including the library that I mentioned and example codes written by him using that library. Though I' ve downloaded the zip file, ran such codes as dumpInfo, read and write, unfortunetely I couldn' t made "changeUid" example work. U can reach this example code via the link below as well. My connection is true, I' m sure bout' that  If anybody had faced this kind of problem or knows the solution, their answers will be enough satisfying for me I guess... (By the way, error was this sentance: Are you sure this is a uid changeable card -I was sure, my card was a Mifare 1K card- failure, the card responded as NAK)

link: https://github.com/miguelbalboa/rfid


texts: I2C connection freezes Master if Slave disconnects

texts:
I am using I2C to successfully request critical data from a Slave device (I have to use requestFrom() in the Master) but if, for some reason, the power disconnects from the Slave device then the Master freezes altogether. I didn't realise I2C was so problematic in this regard and I have been a number of weeks trying all types of alternative setups to try and avoid this situation. I can't seem to find a way for example, to simply check if a Wire() connection exists before requesting data and freezing everything. Both devices are Arduino Uno r3.
Any ideas I may not have tried yet? Any way to send a single value to the Master and update it every 30 secs would do. Actually the data comes from a capacitive sensor, so would it be possible to just have both arduinos read from the same sensor?

In response to Nick Gammons suggestions (below):
I have edited the examples you gave to try and fit in with what I am trying to achieve. I would like to do the following. Catch a situation where the Master (Arduino Yun Shield) cannot communicate with the Slave ( Arduino r3 - with sensor) due to its power supply and/or sensor reading failing. In other words, an Arduino monitoring another Arduino. Here is my edited versions, however I am still not able to catch the "else" condition of the Slave being unreachable:

SLAVE

#include <Wire.h>

const byte MY_ADDRESS = 42;

// various commands we might get

enum {
    CMD_ID = 1,
    CMD_READ_A0  = 2
    };

char command;

void setup()
  {
  command = 0;
  pinMode (A0, INPUT);

  Wire.begin (MY_ADDRESS);
  Wire.onReceive (receiveEvent);  // interrupt handler for incoming  messages
  Wire.onRequest (requestEvent);  // interrupt handler for when data is wanted

  }  // end of setup

void loop()
  {
  // all done by interrupts
  }  // end of loop

void receiveEvent (int howMany)
  {
  command = Wire.read ();  // remember command for when we get request
  } // end of receiveEvent

void sendSensor (const byte which)
  {
  //int val = analogRead (which);
  int val = 125;//test only
  byte buf [2];
    buf [0] = val >> 8;
    buf [1] = val & 0xFF;
    Wire.write (buf, 2);
  }

void requestEvent ()
  {
  switch (command)
     {
     case CMD_ID:      Wire.write (0x55); break;   // send our ID
     case CMD_READ_A0: sendSensor (A0); break;  // send A0 value
     }
  }

MASTER

#include <Process.h>
#include <I2C.h>
#include <Bridge.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C  lcd(0x27, 16, 2);

const int SLAVE_ADDRESS = 42;

// various commands we might send
enum {
  CMD_ID = 1,
  CMD_READ_A0  = 2,
};

void setup ()
{
  Bridge.begin();
  Console.begin();
  //while (!Console);
  I2c.begin ();
  I2c.timeOut(100);  // milliseconds

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

void loop()
{
  int value = getA0();
  Console.print("A0 value:");
  Console.println(value);
  lcd.setCursor(0, 0);
  lcd.print("A0 value:");
  lcd.print(value);//displays first '0' reading then freezes code
  delay (5000);
}

int getA0() {
  if (I2c.write (SLAVE_ADDRESS, CMD_READ_A0) == 0) {
    byte buf [2];
    int val;
    if (I2c.read (SLAVE_ADDRESS, sizeof buf, buf) == 0)
   {
      val = buf [0] << 8 | buf [1];
      return val;
    }
    else {
      return 0;
    }
  }
  else {
    return 0;
  }
  delay(500);
}


texts: How do voltage and resistance work for two 5v servos when using an external 12v power supply?

texts:
I have a 12v/1.5 amp barrel plug power supply on my Arduino Uno. I have two servos that say they are rated for 4.8v to 6v, but no amps are specified. When my circuit is configured as it is in this image, it appears to work fine. (In my test sketch, I'm constantly and simultaneously rotating them from 0 - 180 degrees and then in reverse.)

But I don't understand why it works. I assumed the 5v pin can only supply 5v of total power to the whole configuration. Is it instead supplying a regulated 5v at as needed between both servos from a total pool of 12v (presumably up to 10v at once)? Do I need voltage regulation? Shouldn't I have to know the amps for the servo(s) and use some sort of resistance?

Thanks for any information and advice you can share on learning about the concepts underlying a situation like this.

Update: I ultimately modified my approach based on the feedback received here by wiring a separate 5v/2a power supply to the breadboard for the two servos, and wiring the rest of the circuit appropriately (using a common ground, etc.).


texts: Soft debouncing from an interrupt during stand-by

texts:
My current setup has the arduino in 'stand-by' power saving mode, therefore i am unable to use any means of a traditional soft debouncer, such as Bounce2, as far as I know.

I went ahead and attached the buttons to pin change interrupts, since I have one button on each bank, i.e. pin 7 and pin 11.

The technique I'm using doesn't seem to be behaving since the routines are being fired too regularly (inconsistently), and at the rising edge too.

I have the pins set to use their internal pull-ups.

Using the PCI library:

void pciSetup(byte pin)
{
  *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
  PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
  PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the

pciSetup(POWER_SWITCH);
pciSetup(SELECTOR_BTN);

// check if IR IN or Power switch
ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
{

  if (digitalRead(POWER_SWITCH) == LOW)
  {
    noInterrupts();
    unsigned long last_millis = millis();
    while (millis() - last_millis >= 500);
    ir_power_pressed = true;
  }
  interrupts();
}

ISR (PCINT2_vect) // handle pin change interrupt for D0 to D7
  noInterrupts();
  unsigned long last_millis = millis();
  while (millis() - last_millis >= 500);
  ir_selector_pressed = true;
  interrupts();
}

Am I doing something silly?

Update 1

As suggested in the comments, i've adjusted the code, but it still triggers on the rising edge, and a few times rapidly at the falling edge.

ISR (PCINT2_vect) // handle pin change interrupt for D0 to D7 here
{
  if (digitalRead(SELECTOR_BTN) == LOW)
  {
    noInterrupts();
    static unsigned long last_millis = millis();
    if (millis() - last_millis >= 500)
    {
      ir_selector_pressed = true;
      interrupts();
    }
  }
}


texts: Convert character to Integer while leaving encoded

texts:
I have two characters, that I get by Bluetooth.
char a = SerialBT.read();
char b = SerialBT.read();

According to the Arduino Reference, decoded data stored in a char gets encoded to ASCII text.
I want to combine them in an Intenger, but the following methods don't work:
int c = a + b;

int c = (int)a + (int)b;

int c = (a - 48) + (b - 48);

and

String c;
c.setCharAt(0, a);
c.setCharAt(1, b);

Thank you


texts: How to connect L298N motor driver to 5v input supply?

texts: I'm trying to connect 5v supply to a L298N motor driver at it's 12V-35V input pin but it's not working. If I'm connecting to 7.2V supply it's working. Is there any way to connect 5v supply? I want a constant 5v at output pins for motors.


texts: How to document a custom library in Arduino

texts:
I have created my own library and it is working flawlessly. Now I want to add some documentation to it that the Arduino IDE can understand.

For the functions from the Arduino IDE itself like delay(ms) you can right click them and then select Find in Reference. How can I add this feature to my own library?


texts: Arduino nano getting powered through analog input?

texts:
I noticed something today. I am powering the Arduino Nano from a battery and a 5v step up converter. That works just fine and I'm getting a stable 5v output. I have a second cable coming out from the battery which plugs right into analog input A0 set as input so I can measure the battery voltage. However when I disconnect the battery from the usb plug and leave the voltage sensing cable connected to the analog input the power led stays on. I want it to shut down and be disconnected from the power source and have the voltage sensing cable still connected.
How can I fix this?


texts: How does measuring angled surfaces using ultrasonic distance sensors affect the readings?

texts:
I've read online that ultrasonic distance sensors do not work well when measuring surfaces that aren't close to perpendicular to the sensor (read something like 5 degrees from perpendicular).
I was wondering what kind of reading would occur if a surface is say, 10 degrees from perpendicular, or more? Would it give a reading that's close but with a greater amount of error, or would it give completely wacky readings? Is there any way to overcome this? Thanks!
(Visual: Imagine there's a wall at the red line, what would the reading say?)


texts: Problem reading in Arduino serial port with 5K potentiometer

texts:
I have written code to see values of a 5K potentiometer from 0 to 1023. Whenever I rotate the knob, the value should change from 0 to 1023. I have connected the potentiometer to the Arduino's pin A1, but there is a problem with readings. Whenever I am rotating the potentiometer's knob, the serial port is only showing 1023. Please help.

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

void loop() {
  int sensorValue = analogRead(A1);
  Serial.println(sensorValue);
  delay(500);
}


texts: Ams1117 worked fine on battery, up in smoke with 12v power supply

texts:
I have a circuit that worked fine on a a 12v lead acid battery for a day. Once connected to a 12v 3a power supply it didn't work properly and then the ams1117 5v burned up and so did a 3.3v one within a few minutes.
The 12v power supply is a cheap Chinese model from eBay. My meter shows 12.3v but I don't have a scope.
I understand that ripples in the output of the power supply have probably caused this but what does that mean and how has it exceeded the rating of the converter? Is there a simple fix so I can use the power supply?
Would a 12v motor or relay be susceptible to the ripples?
I'm going to run my esp8266 from a different source but I'd like to keep using the power supply for the motor and 12v relays.


texts:
I was able to use USART without interrupt driven and it worked perfectly! However, when I tried adding interrupt on USART_RX_vect, the program does not work as expected anymore.

Below is my small program. The expected behavior of this program is everytime I press a button the LED should toggle its state, but also by default the LED will toggle its state every 500ms. Right now, the LED toggles every 500ms but
 the moment I press a button on my machine keyboard to send data to the ATmega328p, the program stops (the led freezes on its last state).

I am not using an external clock, but I wonder if that could be the problem or I am missing something in my code that I can't figure out.

I appreciate any help. Thank you.

#ifndef F_CPU
#define F_CPU 1000000UL
#endif

#define FOSC F_CPU
#define BAUD 4800
#define MYUBRR FOSC/16/BAUD-1

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

void USART_Init(unsigned int ubrr) {
   UBRR0H = (unsigned char)(ubrr>>8);
   UBRR0L = (unsigned char)ubrr;
   UCSR0B = (1<<RXEN0) | (1<<RXCIE0);
   UCSR0C |= (1<<UCSZ00 | (1 << UCSZ01));
}

IRS(USART_RX_vect) {
    PORTC ^= (1 << PC5);
}

int main(void) {
    USART_Init(MYUBRR);
    DDRC |= (1 << PC5);
    sei();
    while(1) {
        PORTC ^= (1 << PC5);
        _delay_ms(500);
    }
    return 0;
}

Edit#1: I modified IRS handler:
Code:

IRS(USART_RX_vect) {
    while(!(UCSR0A&(1<<RXC0))){};
    unsigned char received = UDR0;
    PORTC ^= (1 << PC5);
}

Status: Program does not work.

Edit#2: Fixed typo ISR instead of IRS (pffff)

Solution: I was missing the code for consuming the RX buffer and I had a typo: IRS should be ISR. Thanks for @Edgar Bonet and @Majenko for the help!


texts: How can you turn off the LEDs on a SparkFun AS7265x Spectral Triad (Spectroscopy Sensor)?

texts:
I'm a newbie to program an Arduino but I need to turn off a LED from a external Spectroscopy Sensor.
This is the Sensor:

There are three LEDs on this sensor and they're turned on automatically when the Arduino is plugged in. Can someone perhaps explain in general how to address a LED mounted on something like that ?


texts: I'm working on the wifi uploading to Arduino over ESP shield (eg. ESP-12). When uploading over USB Arduino IDE resets the boards first (using DTR) and then interacts with the bootloader. How can i control ESP's GPIOs to reset Arduino board with ESP?


texts: DHT11 not giving correct value if I attaching a servo motor

texts:
So I am using a servo motor and 2 DHT11s in my Uno, when I attach them separately it works well. But when I try to attach both, servo working correctly but DHT11 giving weird number(DHT11 was side by side, one gives 22oC and another gives 30oC sometimes -999).

I am powering both devices by using 5V and GND from arduino to a breadboard and then DHT11 and Servo power pin to the breadboard. All signal pin are direct from devices to arduino.

Am I power both devices wrong? or is there's a way to solve this?

Thanks

EDIT:
this is the code

#include <Servo.h>
#include <dht.h>

dht DHT;

#define DHT11_PIN 7
#define DHT11_PIN2 6
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() {
  Serial.begin(9600);
  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
  }

  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  int chk2 = DHT.read11(DHT11_PIN2);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}

For the servo, I used GWServo S03N STD.


texts:
I plan to use a single address LED (SK6812 or WS2812) to indicate controller status.

The goal is to include colors: Green / Blue / Red.

There are libraries like Neopixel, Fastled, and others, but I don’t have much space to include them in the program.

How difficult is it to implement color inclusion without the use of libraries and interrupts?


texts:
I have the following code:

#include <SPI.h>

void initChips(){

    SPI.begin();
    SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));

    pinMode(SS, OUTPUT);
    digitalWrite(SS, LOW);

}

void setup() {

  Serial.begin(1000000);

  initChips();

  delay(1000);
}

void loop() {

  //Perform read and write

  digitalWrite(SS, HIGH);
  SPI.endTransaction();
  SPI.end();
  pinMode(MOSI, OUTPUT);
  digitalWrite(MOSI, LOW);

  Serial.println("Done\n");

}

The MOSI pin does not go low even when I turn off SPI and manually turn the pin low through digital write.

I saw a similar post Cannot set MOSI pin low even after ending SPI but the accepted solution (if I am understanding it correctly) is by changing the SPI library itself which I do not want to do.

What is correct sequence of SPI commands to turn the MOSI pin low after SPI has finished?

Solution:
As one of the comments mentioned, the fix is to use SPCR &= ~_BV(SPE); after SPI.end();.


texts: Need to read/send both values of a button push

texts:
I'm trying to use a float switch to receive alerts via Blynk when a water level drops, and when it rises again. The code I have been using has been working for when the float drops (button pressed) and I could get it to work when the water comes back up, but it gets stuck in a loop. I'm new to Arduino programming and I'm sure it's some simple error in the way I'm writing/modifying this code...

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;

char auth[] = "710a4af9b1d82412fa477705bf642c634";
char ssid[] = "SSID";
char pass[] = "PWD";
int flag=0;
void notifyOnButtonPress()
{
  int isButtonPressed = digitalRead(D1); //assignment here for pin
  if (isButtonPressed==1 && flag==0) {

    Blynk.notify("Alert : Water Level has dropped");
    flag=1;
  }
  else if (isButtonPressed==0 && flag==0)
      Blynk.notify("Alert : Water level has risen");
  {
    flag=0;
  }

}
void setup()
{
  // Debug console
  Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
  // Setup notification button on pin D1
  pinMode(D1,INPUT_PULLUP);
 timer.setInterval(16000L,notifyOnButtonPress);

}
void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

I believe the problem is in function notifyOnButtonPress.


texts: What datatype is the names of the analog inputs?

texts:
I am writing a code for an automatic garden, and for this, I will use an array of sensors. I want to represent each plant as a class, and so one of the private variables will then be the sensorID, the name of the input on the analog inputs. But these are called 'A0' 'A1' and so forth, so I am wondering what datatype they are?

class Plant{
private:
String name;
??? sensorId;
...
public:
readSensor(??? sensorId);
...
};

I want to standardize this so I don't have to physically write 'A0' or 'A1' each time I need to read the sensor.


texts: Question about include statements and details in Arduino.h file from core library

texts:
This is more of a C/C++ question. However the files I am asking about are a part of the Arduino library.

In /arduino-1.6.5-r5/hardware/arduino/avr/cores/arduino/Arduino.h :

#ifndef Arduino_h
#define Arduino_h

#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>

#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>

#include "binary.h"

#ifdef __cplusplus
extern "C"{
#endif

How are these blocks found at compile time in the main sketch?

#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>

Does #include <avr/somelibrary.h> mean that this is a standard library from either avr-g++ or avr-gcc? As opposed to a standard g++ or gcc compiler?

One last question, how can there be an Arduino.h without an Arduino.c? I searched through the project but could not find an Arduino.c. All of these are probably stupid questions, as I am in the process of learning C/C++. I am completely new to it.


texts: How do I resolve "avrdude: stk500_recv(): programmer is not responding"?

texts:
Whenever I try to program my Arduino UNO Rev.3, I'm seeing the following error

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00

When I plug this in, I do see a power light. There are no cables whatsoever connected other than the USB. I have another Arduino UNO which works fine when I upload the sketch (I'm using the basic blink sketch). How do I resolve this? What kind of problem can it be?


texts: How to prevent breaking my Arduino by mistake?

texts: What is the best practice to make my Arduino circuit more robust against prototyping mistakes (like shorting pins)? I don't want the controller to release its blue magic smoke while experimenting with it, what precautions can I make while designing a circuit?


texts: I'd like to make RC car and remote controller via bluetooth (HC06)

texts:
At first, I tried to make whole code for an RC car and remote controller, but I realized that it's difficult for me since I have few ideas about C++. So, I changed a few things like turning on the LEDs with switches and servomotors with potentiometer. Here are my code.

Remote controller

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2,3);
int sw1=13;
int sw2=12;

void setup() {
  BTSerial.begin(9600);
  Serial.begin(9600);
  pinMode(sw1, INPUT_PULLUP);
  pinMode(sw2, INPUT_PULLUP);
}

void loop() {
  int a = analogRead(A0);
  int map_a=map(a,0,1023,0,255);
  int state1=digitalRead(sw1);
  int state2=digitalRead(sw2);

  BTSerial.print('S');
  BTSerial.print(map_a);
  BTSerial.print(',');
  BTSerial.print(state1);
  BTSerial.print(',');
  BTSerial.print(state2);
  BTSerial.print('E');
  delay(100);
}

< RC CAR >

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2,3);

byte buffer[255];
int bufferPosition;

void setup() {
 BTSerial.begin(9600);
 Serial.begin(9600);
 bufferPosition=0;

}

void loop() {
  {
    if(BTSerial.available()>0){
    unsigned char data = (unsigned char)BTSerial.read();
    buffer[bufferPosition++]=data;
    Serial.println(data);
    delay(100);
    }
}
}

When I checked the result from Serial.println(data) from RC car code,
it was trash...

Can you instruct me what's wrong with this code?


texts: Using two input methods to control one motor shield (bluetooth and pushbuttons)

texts:
since an Arduino cannot run two programs simultaneously, I have been struggling a lot to get my project working - basically it is a motorized desk which is supposed to take input either from a BLE controller app or a pushbutton in order to move the linear actuators. However these inputs should work SIMULTANEOUSLY, I have failed to make both of them work together, after countless hours of prototyping, code provided below, please help me out.

    #include <AFMotor.h>

    AF_DCMotor motor1(1, MOTOR12_64KHZ);

    AF_DCMotor motor2(2, MOTOR12_64KHZ);

    int command;

    int forwardButton = A3;

    int backwardButton = A4;

    void setup() {

      Serial.begin(9600);

      pinMode(forwardButton, INPUT_PULLUP);

      pinMode(backwardButton,INPUT_PULLUP);

      motor1.setSpeed(255);

      motor2.setSpeed(255);

    }

    void forward(){

       motor1.run(FORWARD);

       motor2.run(FORWARD);
    }

    void backward(){

       motor1.run(BACKWARD);

       motor2.run(BACKWARD);
    }

    void stopMotor(){

       motor1.run(RELEASE);

       motor2.run(RELEASE);
    }

    void loop() {

      if (Serial.available() > 0) {

        command = Serial.read();

        stopMotor();

        switch (command) {

          case 'a':
            forward();
            break;
          case 'c':
            backward();
            break;
          case 'e':
            forward();
            break;
          case 'g':
            backward();
            break;
          case 'b':
            forward();
            break;
          case 'd':
            backward();
            break;
          case 'f':
            forward();
            break;
          case 'h':
            backward();
            break;
        }

      }
        else {

          stopMotor();

      }

    while(digitalRead(forwardButton) == LOW)

    {

      forward();

    }

    while(digitalRead(backwardButton) == LOW)

    {

      backward();

    }

    if(digitalRead(backwardButton)== HIGH)

    {

      stopMotor();

    }

    if(digitalRead(forwardButton) == HIGH)

    {

      stopMotor();

    }

    }


texts: Reed Sensor matrix for chess board query

texts:
NOTE:
This is not a question that has been answered previously in similar questions.
I am using an arduino Mega

I have gone through Bergers Blog(schematic is in this link), but have been breaking my head on the logic of your sensor matrix, I have been breaking my head for the past few days on this one thing.

Initially he set all rows to HIGH then reset the 1st row to LOW to scan the reed sensors, let's assume that all the sensors in the 1st and 2nd row are closed.

My question is that since the 1st row is set to LOW won't it get shorted because the second row is initially set to HIGH?

Also, I used the same matrix as berger but instead I enabled the internal Pull up pins of all the 8 input pins, but yet again I faced the same problem of getting a short , since if a row 1 is set to LOW and row 2 is initially set to HIGH then One sensor in row 1 is closed and a reed sensor in row 2 below the sensor mentioned in row 1 is also closed. Then won't we get a short and random values show on the arduino.


texts: How to use Honeywell NBP Series Sensor with Arduino

texts:
I am trying to use a HONEYWELL NBPDANN100PAUNV Pressure Sensor.

I found an example here http://www.circuitstoday.com/interfacing-pressure-sensor-arduino

As this example says as instrumentation amplifier based on quad op-amp LM324 is used for conditioning the output voltage from the pressure sensor.

int sensor=A0;
int dig_out;
void setup(){
  Serial.begin(9600);
  pinMode(sensor,INPUT);
  pinMode(2, INPUT_PULLUP);
}

void loop(){
  if (digitalRead(2) == LOW) {
      dig_out=analogRead(sensor); // reads the input voltage
    Serial.print("Pressure Sensor "); // prints "Pressure Sensor"
    Serial.print(dig_out);
    Serial.print("\n");
    delay(1000);
  }
}

But when I make this circuit and connect to Arduino it just give output about 5, I give the external air pressure but value not change.

Can any one help me Interfacing this type of sensor to Arduino.


texts: Using TXD1/RXD1 on ATmega1280 for USB communication

texts:
I have a few MakerBot Mightyboards running off ATmega1280 chips that can no longer use their standard USB port to connect to a computer (to make a long story short, there's a little inductor that blew up between the USB port and the 8u2 chip and it is essentially impossible to replace). I have noticed, however, that they have headers for the RXD1 (PD2) and TXD1 (PD3) pins on the 1280 as seen in this picture:

Would it be possible to hook up an external 8u2 (or similar) chip programmed as a USB to serial converter (something like this) and use it as if it were the normal USB port (e.g. for uploading firmware)?

(I wanted to add atmega1280 as a tag, but it doesn't seem to exist)


texts: Arduino IDE programs Leonardo but cannot open serial terminal

texts:
I'm using Arduino: 1.6.7 (Mac OS X 10.11.3), Board: "Arduino Leonardo".

When I try to program my code, it works without problems.
When I want to open the built-in Serial Monitor or Serial Plotter, it says "Board at /dev/cu.usbmodem1421 is not available".

The board is available and my simple code even works using "SerialTools" from Mac App Store. So there must be some problem with the Arduino IDE.

No serial related messages on dmesg. Comically it mounts and umounts my Boot OS X and Recovery HD partitions every time I unplug the Leonardo.

hfs: mounted Recovery HD on device disk0s3
hfs: unmount initiated on Recovery HD on device disk0s3 hfs: mounted
Boot OS X on device disk2s3 ioqueue_depth = 64,   ioscale = 2 hfs:
unmount initiated on Boot OS X on device disk2s3

Any ideas?

int inByte = 0;         // incoming serial byte

void setup() {

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

}

void loop() {

  if (Serial.available() > 0) {
    inByte = Serial.read();
    Serial.println("Hi");
  }

}


texts: Maintain constant PWM voltage with changing Vcc

texts: I am making an arduino project with a single lithium ion battery, and want to be able to maintain a constant PWM voltage, even when the battery goes from 4.2-3.2v. I have been able to read the Vcc using the internal 1.1v reference, so I am wondering if I can make some sort of feedback system to increase the duty cycle when the battery discharges, in order to keep the same average voltage on the PWM. I want to be able to make it 3.2v constant, which should be attainable on Vcc from 4.2-3.2, with 100% duty cycle when the battery is at 3.2v.


texts:
So basically I'm trying to create a device where when I push a button it starts a loop. When I push this button again, it stops the loop. Right now I have it logged to serial. It starts up correctly with no output. When I press the button the loop begins and it spits out "toggled on" continuously. When I press the button again... nothing happens. What should happen ideally is that it should stop spitting out "toggled on" and just go back to doing nothing.

#include <Bounce2.h>

Bounce bouncer = Bounce();
const int W = 10;
bool wOn = false;

void setup() {
  Serial.begin(9600);
  pinMode(W, INPUT_PULLUP);
  bouncer.attach(W);
  bouncer.interval(5);
}

void loop() {
  bouncer.update();
  if (bouncer.read() == LOW) {
    wOn = !wOn;
  }

  if (wOn > 0) {
    Serial.println("toggled on");
  }
}


texts: STM32 "Blue Pill" Serial.print freezes Serial Monitor

texts:
I am having difficulties when printing any type of variable using the Serial.print(ln) command.

The Serial Monitor becomes inactive after printing for approximately 7 - 15 times.

I currently have the STM32 Blue Pill Board, running Mac OS Mojave and Arduino IDE v 1.8.9

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

}

void loop() {
  float raw = analogRead(PA0);
  float voltage = (raw * 3.3) / 4096;
  Serial.println(voltage);
  delay(500);
}


texts: When reading the MPU 6050 has accelerometer and gyro, I assumed it was linear acceleration, but now I second guess that.  From this video https://www.youtube.com/watch?v=qmd6CVrlHOM it seems like they are using acceleration and gyro to make one rotation direction.  I need to know what direction the mpu is moving, not just a rotational value.  Is there a way to extract this information?


texts: Strange issue with FHT library for sound-reactive LED project

texts:
I have been playing with the FHT library and have run into an interesting issue with fht_mag_octave() disrupting the output of my ADC actions.  Running on a MEGA ADK.

The idea is that I'm using FHT to read in the microphone input into A0, but also occasionally checking A2 pot to adjust the volume/brightness of the of the overall FastLED strip.

Here is the code in question...  it's barebones.  Just the standard FHT loop and then, every 100 loops, it checks A2 for the brightness setting.

#include <FastLED.h>

#define LED_PIN     6
#define BRIGHTNESS  200
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 16
CRGB* const leds(NUM_LEDS);

#define LOG_OUT 1 // use the log output function
#define OCTAVE 1 //   // Group buckets into octaves  (use the log output function LOG_OUT 1)
#define OCT_NORM 0 // Don't normalise octave intensities by number of bins
#define FHT_N 128 // set to 128 point fht
#include <FHT.h> //

void setup() {
  Serial.begin(9600);
  delay(1000);
  FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness (BRIGHTNESS);

  // TIMSK0 = 0; // turn off timer0 for lower jitter (commented this out b/c I think this interferes with FastLED)
  ADCSRA = 0xe5; // set the adc to free running mode (0b11100101), prescalar=32 for higher ADC clock freq
  ADMUX = 0x40 | (0 & 0x07); // use adc0 (0b1000000)
  DIDR0 = 0x01; // turn off the digital input for adc0

}

int counter = 0;

void loop() {

  while (1) { // reduces jitter

    cli();  // UDRE interrupt slows this way down on arduino1.0

    for (int i = 0 ; i < FHT_N ; i++) { // save 128 samples
      while (!(ADCSRA & 0x10)); // wait for adc to be ready  in binary 0010000 (look for ADC Interrupt flag to be set to 1)
      ADCSRA = 0xf5; // restart adc (in binary 11110101...http://www.robotplatform.com/knowledge/ADC/adc_tutorial_2.html)
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fht_input[i] = k; // put real data into bins

    }

    fht_window(); // window the data for better frequency response
    fht_reorder(); // reorder the data before doing the fht
    fht_run(); // process the data in the fht
    fht_mag_octave();
 //   fht_mag_log();

    // every 100th loop, adjust the volume accourding to the value on A2 (Pot)
    if (counter > 10) {

      ADMUX = 0x40 | (2 & 0x07); // set admux to look at Analogpin A2

      while (!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int brightness = (j << 8) | m; // form into an int

//      brightness = map(brightness, 0, 1023, 0, 255);
      Serial.print("b: ");
      Serial.println(brightness);

      FastLED.setBrightness (brightness);

      ADMUX = 0x40 | (0 & 0x07); // set admux back to look at A0 analog pin (to read the microphone input
      counter = 0;
    }

    counter++;
    sei();

  }
}

Here's the output as shown (basically, it's outputting nonsense, non-int values):

b: ⸮
b: ⸮
b:
b:
b: ⸮
b: ⸮
b:
b: ⸮
b: ⸮
b:
b: ⸮
b: ⸮
b: ⸮
b:
b: ⸮
b: ⸮
b:

b: ⸮
b: ⸮
b:

If I comment OUT the fht_mag_octave line and uncomment fht_mag_log(), here is the output (which looks right as I turn the Pot pin):

b: 0
b: 0
b: 0
b: 0
b: 0
b: 9
b: 35
b: 38
b: 48
b: 85
b: 143
b: 171
b: 188
b: 204
b: 224
b: 245
b: 280
b: 332

The issue is that the A2 value "brightness" does not read properly if I use fht_mag_octave().  If I comment out only the fht_mag_octave() line, it works perfectly.  I can also use fht_mag_log instead, and it works fine.

This makes me think that there is something that fht_mag_octave() does something that interferes with the ADC registers.

Any ideas?


texts:
In my code I need to set five pins to output mode. I have the pinMode() statements in my setup.

I am trying to make my Arduino code run a bit faster, and I came across a tutorial which swaps digitalWrite() for PORTB &= _BV(PB6) (high), and makes it run ~25 times faster.

I'm wondering if there's a similar type of substitution I can do for pinMode(), that will make it run faster as well? Or is pinMode() already a fast command, so I shouldn't worry about it?

Thanks


texts:
Is it safe to use PROGMEM variable like dynamically allocated memory (a pointer to PROGMEM variable which is out of scope).

I need this so I can generate a variable size (before compilation), constant values, lookup array stored in flash.

Working example:

class Ex_class {
  public:
    Ex_class(int table_size, int value_range) {
      int flash_table[table_size + 1] PROGMEM;
      _ex_table = flash_table;
      for (int i = 0; i <= table_size; i++) {
        _ex_table[i] = random(value_range);
      }
    }

    int get_value(int index) const { return _ex_table[index]; }

  private:
    int* _ex_table;
};

void setup() {
  randomSeed(analogRead(0));
  Serial.begin(9600);
  Ex_class ex_object(5, 50);
  for (int i = 0; i <= 5; i++) {
    Serial.print(i); Serial.print(": "); Serial.println(ex_object.get_value(i));
  }
}

void loop() {}


texts: How do I connect a vibration motor to Arduino?

texts:
I'm trying to figure out how to connect a vibration motor to my Arduino.  I've come across this resource and it seems pretty straightforward though for a while my eye glazed over at how complicated the circuit was (do I really need all of that to run my vibration motor?).

My real question is that I have a vibration motor similar to the picture in the link and I'm trying to figure out how to actually connect it to my breadboard.  Do I have to solder wires onto those flimsy ends or is that a better way to get this to work?

Thanks!


texts:
So I decided it would be a good idea to flash a firmware onto my mega 2560 for a project. I ended up flashing the wrong side of the ICSP header (one near the usb plug/ M16U2) and killed my arduino for the most part. I'm a newb for the most part when it comes to this. I plug it in and the 'L' light is on with the 'ON' light as well. Wont show up in device manager, can't load sketches and can't get into DFU mode.(REV3 has DFU right?)

I have both a usbasp and USBtinyisp programmer and have tried 5 - 10 firmwares on both sides of the headers in hopes I can get it to work again.Literally almost tried everything I could find to get it to flash back. One guide I did find that got me somewhere was this though:

http://forum.arduino.cc/index.php?topic=96706.0

It appears to flash correctly with whatever firmware I use, but cannot pull the firmware off it to check or do the rest of what it says.My guess is that 1 or 2 of the firmware's are gone. Have erased the firmware/relfashed and tried to flash in the IDE with no luck in it working.

I did use this command to read the firmware(or lack of) on both sides of the header to get a better idea of what might be going on:

M16U2/M2560

I don't know if I'm supposed to flash one side first then the other or flashing one will be able to do both at the same time. Here is an example of how I would flash from avrdude:

avrdude -C avrdude.conf -P usb -p m16u2 -b 1200 -c usbasp flash:w:Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m

With each side I would set the correct the fuses from what that file pulled up. So if anyone knows what I'm doing wrong for why it is not working I'd appreciate the help. Just don't know if I can save this or it's gonna end up in the garbage.Thanks


texts:
So, I managed to fry my cheap servo/ESC (electronic speed controller) and decided to make my own using an ATTiny13A on some perfboard. But, I have run into some issues getting the servo to respond.  I'm assuming the servo.h library is not compatible with the ATTiny13A because of incompatible internal clock speeds not creating the right PWM signals. And I haven't found a solution for this.
I have messed around with the Servo8Bit.h library, but this also doesn't seem to work (as its designed for the ATTiny45 and the ATTiny85 ). Is the ATTiny13A even able to produce the needed PWM signals?
Any help/links to documentation would be appreciated!
Thanks in advance.
Code:
#include <Servo.h>

Servo myservo;
int potpin = A3;
int val;    // variable
int Toggle = 2;

void setup() {
  Serial.begin(9600);
  pinMode(Toggle, INPUT);
  myservo.attach(1);  // Servo/ESC is attached to pb1
}

void loop() {
  int ToggleState = digitalRead(Toggle);
  Serial.println(ToggleState);
    val = analogRead(potpin);

  if (ToggleState == 0) {
  val = map(val, 0, 1023, 0, 180);  //Servo motor
   myservo.write(val);
  delay(15);
}
else {
  val= map(val, 0, 1023,1000,2000); //ESC
  myservo.write(val);
  delay(15);
 }
}


texts:
I'm working with a very simple circuit to understand push buttons. The code in the tutorial uses the INPUT_PULLUP pinmode. I understand the idea of the pinmode, but I have two questions:

There must be a difference between a LOW reading and no connection, correct? How does the arduino differentiate between the two?

I tried to experiment with this idea. So my thought was that you could create a circuit where the LED only stays lit when you hold the button down. In this setup, I used just normal INPUT for pinmode. So the logic was: if LOW then turn light on, else light off. The turnout was the light was almost always on and just really finicky when i moved the board. Why?

Thanks!


texts: Why am i getting "phantom" readings from a flowmeter?

texts:
I have 2 flowmeters hooked up to my arduino uno.  They're set to read beer volume as beer flows through them.  Everything is working great, except i'm getting phantom readings.  I have the arduino communicating w/ a raspberry pi over USB, and i set my python script on the pi to start logging when reads are taking place.  i'm getting reads of 1-3ml every 15-30 mins (with 1 fluke of 16ml).  i have 2 flowmeters connected, but only 1 is sending these pulses.

there is nothing coming out of the taps, and everything inside the kegerator is bone dry.  i don't know what to look for...


texts: I am performing basic analogue read like temperature and LDR, reading the data serially, but I would like to deploy it online to cloud platforms like (Plotly, Xively, ThingSpeak, or DataSparkFun). Is that feasible? Thank you in advance.


texts:
I'm trying my best to understand and utilise questions that already exist as well as other websites, however I just wanted to check the circuit I've come up with (which is a very simple switch circuit) will work.

I plan on using a BD139 transistor, although I haven't purchased anything yet, so can change to anything really.

The fans are each 0.09A at 12V. I've calculated that R1 should be 360ohms. The 5V control will be coming from an Arduino. I believe it's within the specs of the transistor. Ic max is 1.5A.

Does the circuit look correct? Are there any changes I should make?


texts: How can I connect an OLED display to arduino

texts:
I'm new on this!

So I want to know if is it posible to connect this oled display: oled display to arduino nano and if is it posible where can I found information of how to learn about connect this type of mini display.

And if you can share some links about good learning site would be cool too!

Thanks!


texts: which is the most efficient way to save power with battery using Arduino UNO?

texts:
I am working with a ArduinoUNO - 2100 mA battery, and a solar Charger shield. I use a temperature reader that sends info every half hour with GPS-GSM shield called LONET (http://www.seeedstudio.com/wiki/LoNet_-_GSM/GPRS/GPS_Breakout for more info).

I want to save all the energy i can, i am trying to put Arduino UNO and LONET on Sleep mode.

LONE has its own mode via “AT+CSCLK=1”.

But for Arduino UNO i haven seen a library called Narcoleptic (https://code.google.com/p/narcoleptic/ for more info) wich can solve the problem.

My question is:

Is there any other method that can help me to save Battery with Arduino uno? is it a good approach to use Narcoleptic or there is another method to do it?

Thanks for your time/help and sorry for my English.

Any feedback could be welcome.


texts: Can I set pin 13 to output 5v, then put arduino mini pro to sleep?

texts:
Can I set pin 13 to output 5v, then put arduino pro mini to sleep and it maintains 5v going through pin 13 while in sleep mode?

I know there are various "levels" of sleep - can a voltage be maintained on a pin for all/any of the sleep modes?


texts:
I, like many others, have encountered the avrdude error. However, I am not sure how to go about fixing mine after looking at numerous forums, etc.

avrdude: verification error, first mismatch at byte 0x0002
     0x74 != 0xe6
avrdude: verification error; content mismatch

I am simply trying to upload a simple sketch, but right when it seems it is about to finish, I get this error and the uploading loading bar simply never finishes...

Thanks for the help!


texts: Using Arduino to control a high voltage DC device

texts: I am an amateur hobby electronics enthusiast , and given the situation , I too am trying to make a contactless hand Sanitizing system like everyone else. My project requires a 36V DC solenoid valve to be actuated through the arduino momentarily for the sanitizer to drop. Obviously I will be using a relay module to electrically isolate both the circuits. But I don't have a 36 V DC adapter . So what is the best way to power up the solenoid valve? Batteries are available to me right now? How do I calculate how many 9v batteries do I need ? How many AH would they require ? Would they get drained too fast?


texts: Safely powering a relay from same source as attiny/arduino?

texts:
My project involves using ATTINY to control a 5v relay (specifically JZC-11F and will be ground triggered) in an automotive setting.

I keep seeing the warnings of powering a relay from the same source as the ATTINY (or arduino), everything I can find says you need a completely separate source.

I'm still working on a 12~v to 5v power circuit that is safe from the issues that arise from being in an automotive setting (load dumps, noisy, reverse polarity protection..etc) but saying I have that figured out and I have a clean 5v source for power, do I have to duplicate that circuit just for the relay? or are there a ways of preventing the relay from eventually shorting out the ATTINY?

Plan B:
What if I scratch the whole 5v relay and set it up to trigger an external standard 12v automotive relay (this is probably more ideal)? Is the ATTINY capable of triggering a 12v relay via ground? if not what are the recommended ways of making this happen?

side note: I'm know code I don't know EE but I'm trying. The end goal is to combine everything onto a custom pcb, so any suggestions about the 12v-5 using an off the shelf car usb adapter or a premade board are unnecessary (seems to be the go-to answer on that subject). I have a separate post regarding that circuit so if at all possible please stick to the relay questions.


texts: send configuration commands with arduino

texts: I am using ublox zed F9P multi GNSS module. I have to program it for its configuration messages. Like I have to run a specific configuration of my receiver with the help of Arduino. I know arduino parse the GNSS sentences but can anyone tell me how to write code for ublox configuration commands such that that command can change setting of the receiver upon burning it in Arduino. Also, that code should retain in the receiver even if arduino is disconnected (closing arduino IDE console). Please help


texts: Arduino mini requires uploading on every power up?

texts:
My Arduino mini is experiencing some really strange problem.

I'm using the BlinkWithoutDelay example sketch for testing:

const int ledPin =  13;
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

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

void loop()
{
    unsigned long currentMillis = millis();

    if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
        ledState = HIGH;
    else
        ledState = LOW;

   // set the LED with the ledState of the variable:
   digitalWrite(ledPin, ledState);
  }
}

The program basically turns pin 13 on and off every 1000ms.

When I uploaded this sketch into the mini (via Arduino Uno board, sans Atmega chip), the scope reading of pin 13 shows nice square waves (1s pulsewidth, 2s period), as expected.

I then unplug the USB cable powering the mini through the Uno board, wait for a few seconds for the scope traces to settle (I only have an old analog one at hand), and then plug it back in to turn on the board. However, the pin output is different - I now get a train of three pulses (60ms wide, 60ms between pulses) at sporadic intervals.

Uploading the sketch then yields the desired square waves again.

What is going on here? I'm fairly sure the mini has nonvolatile memory and it's intact (otherwise the bootloader through which I upload the sketch would not work).


texts: UNO's digital pin continue to read 1 for a while

texts: I'm doing some tests and I notice a bad things with digitals pins. I have a wire that sends 1 signals. If i connect it to a reading pin, I read 1 - and it's ok. But if i disconnect it, for 5-6 seconds Arduino continues to read 1 instead of 0! How can I stabilize it more quickly?


texts: Arduino: Sending SD CSV file online at specific time of the day

texts:
I intend to perform data logging from sensors and store it on SD card as CSV format. The data is related to weather and I would like to send it at the end of the day/
Any available codes how to deploy the SD files from Arduino to the cloud/online at specific time of the day?
Thank you in advance.


texts: Best approaches to reading a high-count quadrature encoder?

texts:
I have a 24v servo motor coupled to a 2,000 segment optical encoder that runs on 5v.

That's 2,000 "ticks" per revolution at it's base resolution. (Full quad reading allows 8,000 ticks per revolution, which I have no idea how a person could really USE! Egads that's tiny slices of a circle.)

It ALSO has a 'full-circle' index, a "Z" line.

That Z SEEMS to be coincident with A. Meaning that the clear slot in the rotor seems to be in the same place for both ONE of the A ticks and the only Z tick. I do not have an oscilliscope to verify this, but timestamping two different interrupts makes it seem like they do line up (one on A one on Z).

The motor runs at max 1075 RPM. So if I did the maths correctly that means there are 2,150,000 ticks per minute on the A/B lines plus 1075 ticks per minute on the Z line.

35,833.33-ish ticks per second on the A line.

17.9166-ish ticks per second on the Z line.

I have used sample code from a number of sources on both a Nano v3 and an Uno r3. I can't get counting to be accurate on either device, both lose ticks counting the A trigger and the coincidence of the A and Z ticks makes the interrupts 'stack' (both trigger almost instantaneously, but whichever was first gets processed and THEN the other gets processed...)

I do know that I can get IC's that will count for me, but there are MANY models and I do not have the ability to determine which would suit this situation the best.

Despite reading a great number of posts about encoders and the Arduino code to read them I still don't understand if the Nano or Uno COULD do this on their own at this speed.

GOAL:

Accurately track all 2000 pulses per revolution at 1075 RPM.
Accurately track FULL rotation pulses at 1075 RPM.
Use full rotations as error-checking against the 2000 count.
Provide error-checked count as an absolute count to external device.
Provide resettable zero-point to external device (remotely reset the count).

So please, if you would, inform me about or direct me to proven methods and resources for achieving the above goals?


texts: Connecting two sensors to one analog pin

texts:
I am completely new to programming with Arduino so please bear with me if this seems stupid.

I am using an Arduino Uno R3.
I have two sensors, a Soil Moisture sensor and an LDR Light Sensor. Both of them have one pin marked as A0 on them. So now, do I connect them both to A0 using a breadboard (Like how I am connecting multiple sensors' VCC to the 5V pin currently) OR do I use a different analog pin say A0 for one and A1 for the other? Will it make a difference?


texts: How do you make a stepper motor move at decimal (such as 0.5) steps?

texts:
if I were to use a code with the following format,

//some loop
digitalWrite(STEP_PIN,HIGH);
digitalWrite(STEP_PIN,LOW);
//

each loop would make the motor move at one step. With this loop I can also make the motor move at 200 or other integer steps. However, is it possible to make the motor move at decimal steps such as 0.4?


texts:
I'm trying to measure kWh with an Arduino that I have connected to a ESP8266 that communicates this value to a web server I have. And I've been trying to find the best and easiest way to go about this.

I'm thinking that I can hook a PMAC903 up to the Arduino using the interrupt pins and measuring the pulses, but I don't really know how I'm supposed to do that? Will it even work? Is this the way it's normally done? I can't really say I've found an easy solution to measure current.

You can find documentation for the PMAC903 here and I'm currently in possession of an Arduino Uno that I'm using.


texts: 2.8" TFT Touchscreen Prohibits Access to Unused Pins

texts:
This is probably a beginner question. You've been warned.

I recently purchased a touchscreen (http://www.adafruit.com/products/1651#tutorials) specifically because it left so many pins open to work with and I needed to hook up one, possibly two more items to my Arduino. However the touchscreen fits over the Arduino and covers all the pins.

How do I access the pins that the LCD isn't using?

To be specific, I will be adding a Galvanic Skin Sensor on two analog pins.


texts:
I received my NRF24L01 Module today but I'm having a hard time finding any resources about this particular combination of modules!
https://imgur.com/a/HrzpvdR
I tried searching up the v200 1812A but no results...You would think the seller would have some documentation on his page but nothing.
Does anyone know what I'm dealing with here?
Thank you!


texts: Controlling lights by XBee S1+ ESP32 without bridge

texts:
I need some help with my ideas please, I have a smart home system and I am trying to control the Philips hue light but without the bridge.
I want to do that by XBee S1 + FURTHER ESP 32.
so, who did that or have any ideas about how that can possible.
Any links, Videos, tutorials will be greater.
thanks all.


texts:
I have this microphone (http://www.digikey.com/product-detail/en/CMA-4544PF-W/102-1721-ND/1869981) and an Arduino Uno board. I'm trying to read audio values off of my microphone (to test the noise of something (in dB)). I'm very new at this kind of stuff so keeping it simple would really help me out! I have a bunch of different capacitors, LM386N op amps, a bread board, and many resistors. Could someone provide a code and schematic that could help me get data off of my mic? I've tried using this schematic: http://wiring.org.co/learning/basics/microphone.html
but couldn't get the code to download onto a Wiring S board due to a "timeout" error and it not being able to "connect with the programmer".

Any and all help would be much appreciated!!