texts: Light sensor acting up when used with other code

texts:
I have a light sensor that works fine and outputs the correct data to the serial monitor when I only upload the following code to the nano:

const int lightSensorPin = A0;
int lightSensorValue = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  lightSensorValue = analogRead(lightSensorPin);
  delay(100);
  Serial.println(lightSensorValue);
}

Now when I upload it with all of my other code, which includes lighting up about 6 LED's at one time and getting readings from two rangefinder sensors, the light sensors no longer output expected data, instead spewing out a bunch of random numbers, 0 to over 3000.

Could sharing the ground with all the LED's and rangefinders be causing interference for the light sensor? Or could it be a code optimization issue? Here's my entire code if it helps at all:

int trigPin1 = 5;
int echoPin1 = 6;
int blue1 =  7;
int green1 = 8;

int trigPin2 = A3;
int echoPin2 = A4;
int blue2 =  A2;
int green2 = A1;

int redLED = 10;
int greenLED = 3;
int yellowLED = 9;
int blueLED = 4;

const int lightSensorPin = A0;
int lightSensorValue = 0;

int securityLength1 = 28;
int securityLength2 = 28;

int frontEyes(11);
int backEyes(12);

const char* front = "front";
const char* back = "back";

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

  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);

  pinMode(blue1, OUTPUT);
  pinMode(green1, OUTPUT);
  pinMode(blue2, OUTPUT);
  pinMode(green2, OUTPUT);

  pinMode(frontEyes, OUTPUT);
  pinMode(backEyes, OUTPUT);

  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);

}//end setup

void loop(){

  digitalWrite(redLED, HIGH);
  digitalWrite(greenLED, HIGH);
  digitalWrite(yellowLED, HIGH);
  digitalWrite(blueLED, HIGH);

eyeballs(trigPin1, echoPin1, securityLength1, green1, blue1, front);
eyeballs(trigPin2, echoPin2, securityLength2, green2, blue2, back);

  lightSensorValue = analogRead(lightSensorPin);
  delay(100);
  Serial.println(lightSensorValue);

}//end loop

void eyeballs(int trigPin, int echoPin, int securityLength, int green, int blue, const char* frontOrBack){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  long duration = pulseIn(echoPin, HIGH);
  long distance = (duration/2) / 29.1;

  Serial.println(distance);

 if (distance >= securityLength || distance <= 0) {
  digitalWrite(green,HIGH);
  digitalWrite(blue,LOW);
  if (frontOrBack == "front") {
    digitalWrite(frontEyes, LOW);
  }//end if
  else if (frontOrBack == "back") {
    digitalWrite(backEyes, LOW);
  }//end else
  }//end if

  else if(distance < securityLength) {
  digitalWrite(blue,HIGH);
  digitalWrite(green,LOW);

  if (frontOrBack == "front") {
    digitalWrite(frontEyes, HIGH);
  }//end if
  else if (frontOrBack == "back") {
    digitalWrite(backEyes, HIGH);
  }//end else

 }//end else if

}//end function


texts: How can I upload .hex files to a Pro Micro using Linux?

texts:
I have a hand-wired keyboard that uses a Pro Micro board, with an ATmega32u4 chip. I can't seem to flash firmware on it. The commands I've been trying are variations of:

avrdude -p m32U4 -P /dev/ttyACM0 -c avr109 -U flash:w:atreus62.hex

The errors I've been getting begin:

Writing | #######avrdude: error: programmer did not respond to command: set addr
####avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: write block
 ***failed;
 ***failed;
 ***failed;
 ***failed;

And end:

#avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
#avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
avrdude: error: programmer did not respond to command: set addr
# | 100% 0.16s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x0d != 0x0c
avrdude: verification error; content mismatch
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: error: programmer did not respond to command: exit bootloader

I'm on Arch Linux. Any ideas?


texts:
I am not able to initialize the SD card. Can't find figure out what the issue is. It fails at the condition

if (!SD.begin(D8)) {
Serial.println("initialization failed!");
return;
}

I am using D1 Mini V2 board and standard SD card module. Pin configuration attached with images below.

Connections are -

GND => GND

VCC => 3.3V

MISO => D6

MOSI => D7

SCK => D5

CS => D8

Code is -

#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);

  Serial.print("Initializing SD card...");

  if (!SD.begin(D8)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}


texts: Why call a USB connection a serial connection?

texts: Does anyone know why Arduino calls a USB connection a serial? When I hear a serial connection I automatically think of a male pin connection and not a USB connection. Also not sure if this a Linux term or just an Arduino thing.


texts:
I used to use Arduino on Windows but I changed to Linux last week and I was wondering how to have a maintained version of the Arduino terminal:

Indeed, I'm not sure my version is quite recent:

The icon seems to have lived ages without a little lifting...

Maybe I'm wrong but it seems so when I open the "Tools" option for instance...

Furthermore I tried to copy and paste this code:

//ONG LIT YIT 2013-07-20
//This following code plays happy birthday melody on Arduino
//Put Piezo Buzzer on GDN and 9 (Positive and negative are reversible)
//this project requires a Piezo Buzzer and

// an Arduino board and

//jumper wires to connect Buzzer's (+) to ~9 and (-) to GND (any GND)

//HAVE FUN

//this project requires a Piezo Buzzer and

// an Arduino board and

//jumper wires to connect Buzzer's (+) to ~9 and (-) to GND (any GND)

//HAVE FUN

int speakerPin = 9;

int length = 28; // the number of notes

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

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

int tempo = 150;

void playTone(int tone, int duration) {

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

   digitalWrite(speakerPin, HIGH);

   delayMicroseconds(tone);

   digitalWrite(speakerPin, LOW);

   delayMicroseconds(tone);

}

}

void playNote(char note, int duration) {

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

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

                 'x', 'y' };

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

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

                 655 , 715 };

int SPEE = 5;

// play the tone corresponding to the note name

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

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

   }

}

}

void setup() {

pinMode(speakerPin, OUTPUT);

}

void loop() {

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

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

     delay(beats[i] * tempo); // rest

   } else {

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

   }

   // pause between notes

   delay(tempo);

}

}

And not all of it appeared in the Arduino terminal.


texts:
So I've tried this a few times and I always get the same issue. When I try to run the sweep example the servo goes round 180 degrees but only in steps. Anyone know a way to fix this?

The servo I'm using is a Tower Pro Micro Servo 9G SG90

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

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

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

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

Video: http://vidd.me/A40


texts: Best way to make an Arduino switch 8 12V LED's

texts:
I'm trying to switch multiple 12V LED's with my arduino, based on the input of a (serial-in parallel-out) shift-register.

The 12V comes from a separate battery, so I can use 8 mosfets to get my 12V, and I might even put a parallel-in serial-out shift register in between.

But I'm hoping that there is a cleaner way of doing this.
Is there some kind of component that combines a shift register and a mosfet?

Any ideas on the best way to solve this?


texts: Guys i have been tring to make the finger sensor for my inmoov arm but i have recently run into a speed bump. So i am quite a newbie at these things so please help me out. Do you know where should i hook up the electrical cables? I know its in analog but where? I am using an arduino mega, and does anyone have a test code for it? I have tried using a voltmeter it works but i just cant seems to find a way to display it.


texts: Make an Arduino board act as both a usb storage device and a keyboard?

texts:
I am making an interface project that, when plugged into a computer, shows up as both usb flash storage and can type like a keyboard when some physical buttons on the board are pressed.

I have seen projects that do one or the other, but not both at the same time.

I have gotten it to work using a usb hub and two chips that are sharing the same storage (since I want the hot-key buttons to type out information stored in the flash drive side as well), with one acting like a HID and one acting as usb storage, but this has a few problems. First, it feels redundant. Second it's difficult to program since every time I plug the mess in it randomly assigns a name to each chip with no easy way of telling which to send the HID code to and with to send the USB Drive code to. I have to plug them in one at a time which wont work once this project is all on the same board. The last problem is the buttons work inconsistently since, im assuming, the two chips are not doing a nice job of sharing access to the text file it's trying to read for the text to 'type out' on the computer.

Is there a nicer way of doing this that uses one arduino acting in both roles accessing the one flash storage? Thanks!


texts:
I'd like to get a word of advice regarding the subject. Basically there's a COM port based device which I need to connect to an Android tablet via USB. The tablet will be exchanging data packages with the COM device, but a) Arduino may need to do same transformation of the packages b) the tablet should not leverage OTG feature and shouldn't be a master itself.

So, my questions are

1) Which Arduino board is the best fit?
2) Is it an option to use Chinese boards for the sake of cost optimization?
3) Do I need separate RS232 and USB shield or it's ok to leverage built in USB and data pins?

Apology for this quite a noob question but that's exactly who I am for Arduino platform. Appreciate any answers.


texts: How can i connect 01 ESP8266 to a shift register?

texts:
I am connecting this shift register to my esp8266 01 for more GPIO options.
it appears there is a GPIO 16 but it's tied to a RESET pin. I checked both datasheets :
i checked the esp8266 01 datasheet
http://www.microchip.ua/wireless/esp01.pdf

i checked the datasheet for the shift register for more information on what kinds of pins can be hooked to each of the input pins.
https://www.sparkfun.com/datasheets/IC/SN74HC595.pdf

also thinking whether it's viable to connect one of the other available pins of the esp8266 and use it for this connection with the shift register. (either RX or TX)

My understanding is need to connect 3 pins of the ESP8266 directly to the shift register for its latch, clock , serial pin.

also wondering if can connect the serial pin of the ESP8266 to the serial pin of the shift register?


texts: How can I get analog-in reading from Digital-PWM-out on the same board?

texts:
I have a wire going from PWM4 to A0 but I don't dare turn on my Arduino Mega in case this is incorrect.

PWM4 will eventually go to an analog device but I want to make sure the read value is what I expect it to be. Am I okay to proceed with my current setup or do I need to throw in a resistor / conversion?


texts: Why can I power an SD card reader from a digital pin?

texts:
I'm trying to understand the power requirements of an SD card. I have a cheap breakout board from eBay that includes built-in level shifters, so I can plug it in directly to my Arduino. I provide power from one of the digital pins, and it works. This doesn't make sense to me, as I thought an SD card reader should draw upwards of 50-100 mA, well over the capacity of an individual digital pin on the Arduino. However, at least one SD card manufacturer does this as well, so I'm not making this up.

I have checked, and the data is written no problem. I have connected an ammeter between the Arduino and the SD reader, and it never jumps above 3 mA? The only problem I have is when I switch from using the USB cable (connected to my computer) for power to a battery pack, the SD card starts acting erratically. Which makes sense, if it's not getting enough current.

What I'm wondering is why it ever works when connected to a digital output pin? Clearly I'm missing something important.

Edit: The reason why I thought they required a lot of current: I've seen comments like this on a number of tutorials:

  One is that they are strictly 3.3V devices and the power draw when writing to the card can be fairly high, up to 100mA (or more)!

Edit2: @dlu answer lead me to investigate the voltage I was sending to the SD card reader, which turns out to have been the problem. I was supplying the Vin pin with 5.2V, which was regulated down to 4V, presumably too low for the 5V-3.3V step-down at the SD card. Moving the battery power to the 5V pin corrected this. This also introduces some new risk, as the board is now receiving unregulated power. But that is another problem.

Edit3: And finally, answering my original question: I found a note on the Adafruit product page for a similar breakout that indicates:

  Onboard 5v->3v regulator provides 150mA for power-hungry cards

So despite only drawing 3mA of current from the Arduino pin, the actual SD card is supplied with > 100mA from the regulator.


texts: printf spacing using array variables in unix shell script

texts:
I'm trying to use printf with a dynamic spacing but I'm not able to do that.
I have this array containing the desirable spacing for each coloumn:
Max_num=();

then I am trying to use numbers inside this array to space between the words:
printf '%s %s%-${Max_num[0]}%s%-${Max_num[1]}%s%-${Max_num[2]}%s%-${Max_num[3]}%s%-${Max_num[4]}%s' "${array[0]}" "${array[1]}" "${array[2]}" "${array[3]}" "${array[4]}" "${array[5]}" "${array[6]}"

But in gives me an error:
$': invalid format character

So what can I do in this case?


texts: Can I use a mobile charger (output 5V) to power an Arduino Uno?

texts: I have made a home automation Arduino project using an HC-05 Bluetooth module. I want to power my Arduino from the main AC supply. Can I use a mobile charger/adapter to power it? Or should I buy a 12v adapter, and solder it to a barrel connector that fits the Arduino input?


texts: Is it possible to generate an exact 15 kHz clock pulse using an Arduino?

texts:
I want to generate a 15 kHz pulse with an Arduino using Timer1, but the problem is that if we want a 15000 Hz clock we need to initialize the timer with 1/15000 seconds or 66.66 microseconds, but we can only pass integers without any decimal precision in the Timer1.initialize(66); function which generates a frequency of 15155 Hz.
So is it possible by any other means to generate an exact 15000 Hz or frequencies between 15000 Hz - 15155 Hz?
#include <TimerOne.h>

void setup() {
  pinMode(9,OUTPUT);
  Timer1.initialize(66);  // Frequency, 100 µs = 10 kHz
  Timer1.pwm(9,255);
}

void loop() {}


texts: I'm planning my first Arduino project which involves a MPU-6050 accelerometer(3.3V) and a RGB led(5V). I've found this Arduino Clone but i'm not sure if it has 3.3V and 5V outputs that I can use. The pins do exist on the original Leonardo board but i'm not sure if the clone contains them as well.


texts: Arduino 1 can somehow support 32-bit audio?

texts: I wanted to take the audio from a device such as the PC, insert it through different ADC in arduino, processing them with DSP and DAC REnter all through to the other speakers, reading here and there on the internet but some people were put in difficulty because Arduino has a data bus to 10 bits. What problems can cause this? I can not send the same 10 bits at a time, until you arrive at 32?


texts: How do I use RFID-RC522 with an Arduino?

texts:
I am working on a project for my local Makerspace, we have limited budget so I was hoping to use the RFID-RC522 el'cheap'o RFID/NFC readers on eBay, I received a couple of SPI based boards, they work, however the code examples for them are limited.

I have found several different libraries and settled on this one: https://github.com/ljos/MFRC522

The trouble is that all the code available online seem to spawn from some Chinese guys Python code that people have translated, and hacked into an Arduino library.

The code works, but Mifare cards are meant to have 4, 7 or 10 byte UIDs and the example/library is returning a 5 byte serial number.

There is no documentation and the NXP datasheet is incomprehensible... Additionally it seems to work with most cards, but it doesn't work with Mastercard PayWave cards which conform to the ISO 14443 standard. The more expensive RDM880 reader which is based on the MFRC500 works fine and has a nice library but the cost makes the implementation impossible.

So, can someone help me to get this NXP MFRC522 based unit reading the UID from all ISO 14443 cards.

#include <SPI.h>
#include <MFRC522.h>

#define RFID_SS  10
#define RFID_RST 5

MFRC522 rfid( RFID_SS, RFID_RST );

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

void loop() {
  byte data[MAX_LEN];
  byte uid[5];

  if ( rfid.requestTag( MF1_REQIDL, data ) == MI_OK ) {
    if ( rfid.antiCollision( data ) == MI_OK ) {
      memcpy( uid, data, 5 );
      for ( int i = 0; i < 5; i++ ) {
        Serial.print( uid[i], HEX );
        Serial.print( ' ' );
      }
      Serial.println();
    }
  }
}


texts: What is difference between analog and digital input and output, and when should i use anlog or digital (input or output)?

texts: How should i determine whether to use input as analog or digital and same for output too?


texts:
I want to send 4 float numbers from Python code to an Arduino; I was trying to send it via serial and I have some problems.
here is my Python code:
import time
import serial
import struct

data = serial.Serial('COM6', 9600, timeout=1)
time.sleep(1)

while True:
   a = str(47.256*1000)
   data.write(a.encode())

Here is my Arduino code :
String msg;

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

void loop()
{
  if (Serial.available()) {
    msg = Serial.readString();
  }

  if (msg.toInt()>30){
    digitalWrite(13, 1);
  }
}

end of code
Thanks in advance.
My problem is that it does not work (LED does not turn on while I send data from the Python code in a while loop; when I remove the while and make it send data 1 time it works (LED turns on). Any ideas why this could be happening?


texts: Is it possible to connect the nine pins from a USB 3.0 memory drive to the corresponding GPIO pins of the arduino (intel Galileo is what I am using, but it is very similar) and access the drive's memory through the implementation of the USB's protocol? I have searched around and have not been able to get a clear idea on how to do this or if it is even possible.


texts:
I declared my enum and called it Dir. I wanted to use value of that type in my function Move(). Here's the code:

enum Dir
{
  forward = 1,
  backward = 2,
  left = 3,
  right = 4
};

void Move ( Dir direction , int distance )
{
     direction = forward;
}

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

}

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

}

Unfortunately i get the following errors:

V2.ino:23:13: error: variable or field 'Move' declared void
V2.ino:23:13: error: 'Dir' was not declared in this scope
V2.ino:23:29: error: expected primary-expression before 'int'

What's wrong?


texts:
I've looked in several places, and so far can not understand to want to be the GND who is on the board.

There is this documented anywhere?


texts:
After reviewing similar topics I've decided to ask this question below in the Security Stackexchange forum about 11 days ago.
https://security.stackexchange.com/questions/235423/is-arduino-mega-hackable-over-the-air
No one gave an answer yet, perhaps I was wrong about the medium that's why I am also posting the question here.
I am collecting data (by reading input registers) from a machine by RS-485 protocol and Arduino Mega 2560 hardware.
I am also sending this data from Arduino Mega to a NodeMCU which is connected to the internet over WiFi.
I made 100% sure that no physical interference can be performed on the hardware I setup.
But since this machine, I collect data from is controllable (by writing holding registers) over RS-485 (I've tested it) I have to make sure that Arduino's software cannot be changed/re-programmed/flashed over the air by someone.
There is no other device than NodeMCU which is open to the Internet and can be the source of vulnerability. And the only physical connections between Arduino & NodeMCU ar TX3+RX3 pins and power+ground pins.
I do not really care if the data or WiFi password or cloud server credentials are stolen. The only thing I care about is that Arduino is not flashed over the air which can ultimately damage the machine I am taking data from. Do you think this setup is safe regarding the information I present to you?


texts:
I am a newbie to using arduino.

I am using an arduino NG  (using an atmega8). One of the pins is a button that triggers an interrupt.

The problem I am trying to solve is that I want an arduino NG to store the timestamp (we are using mills as a timer -no need to consider the 50 day rollover error here) when the interrupt pin is pressed.

The timer of the interrupts in milliseconds is stored in an array and there are up to 100 such interrupt button presses.

After searching around I didnt find any information for using interrupts with atmega8 on arduino NG (though there is information of how to use interrupts on atmega168 with arduino NG ).

So my question is: Is this problem solvable with an atmega8 arduino NG? Does the atmega8 arduino NG have interrupts? Just need one interrupt. And what would be the code to read an interrupt on atmega8 version of arduino NG?


texts: Using same pins number in different arduino?

texts: I'm new beginner in programming arduino, and I want ask a question about arduino code, this is the problem " i used two arduino to build a robot, but i don't know how to set the code that for two arduino uno that pins in first arduino i used them all and now i wanna use the pins in second arduino, and how write code for the second arduino, which it is the same pin number i used  in first arduino, how to creat a code? thanks a lot guys for answer my question... (sorry for my bad english)...


texts: Software reset on Micronucleus possible?

texts:
I'm wondering if anyone knows if it's possible to do a software reset using the watchdog timer on a microcontroller using the Micronucleus bootloader.  When I try it, it doesn't fully reset, as in when connected with USB to a computer, it doesn't appear as a libusb device for a short period of time.

I'm suspecting a watchdog timer reset isn't as early in the boot process as necessary for Micronucleus to wait for programming.

I'm using an ATTiny841 to make a small wrist watch for my son, and I wanted to keep it to a single button.  I've been resetting for programming with a pair of tweezers grounding the reset pin side of a pullup.  Not a huge deal if it's not possible, once I have the code set, there won't be much need to re-program.

Here's the watch so far:  https://www.youtube.com/watch?v=lkH16xzkSJM

Thanks in advance!


texts: Which is RX and TX pin of the HM-10 module?

texts:
i recently bought hm-10 ble module which works using cc2541 ti SOC but problem is there are many ports the the bluetooth module but the seller has not mentioned which is rx and tx pins so...
I wanted to connnect it with Arduino uno and use AT commands but now i am stuck can anyone in this community help me finding which pin is Tx and Rx and the data sheet of the module is difficult to find on the net .....


texts:
I'm very new to the Arduino platform and micro-controller projects in general, which is why I'm still learning about all the parts needed for circuit creation. There is one particular part that I would need for my current project but I'm having troubles figuring out what exactly this "thing" is ...

Please take a look at this picture: https://i2.wp.com/makezine.com/wp-content/uploads/2015/08/rolljam-hardware.jpg?fit=929%2C724

I need to know, please, what exactly these dual row female headers are called that are placed right to the Teensy board and are holding the two CC1101 units (so I can find them on Amazon or in other shops).
Obviously, they are spanning the gap on the breadboard but is there something you can buy like this? Or are these common dual row headers that have had their pins bent and put into single row headers?
I can't quite tell. The whole thing looks custom made though (to me it even looks like some hot glue was used, but I might be entirely wrong about that).

^^ And if my assumption is right, what might be the purpose of doing this? From my understanding this would create a full row for the power (instead of having two shorter rows), which the gap on the breadboard is meant to prevent?!

Thank you for suggestions.


texts:
I am trying to create a project which involves getting latitude and longitude via GPS Module and send it via GSM Module. My problem here is that individual code is working perfectly. However, if am to initialize both together, none will work.

#include "GSM.h"//wrapper class for Sim800l library
#include "GPS.h"//wrapper class for TinyGPS library
GSM *gsm;
GPS *gps;
void setup()
{
    Serial.begin(9600); // Debugging only
    gsm = new GSM();//initializes SIM800l
    //gps = new GPS(11,10 );//initializes NEO6MV2//uncommmenting this line won't make both modules work
}
String telNum;
int i = 1;
void loop()
{
    /*
    Serial.println(gps->getLongitude(),6);
    Serial.println(gps->getLatitude(),6);
    */

    Serial.println(gsm->read(i,telNum));
    Serial.println(telNum);
     ++i;
}


texts: Setting up 433 MHz Transmitter and Receiver in the same Arduino sketch using Radiohead

texts:
I have set up a 433 MHz transmitter and receiver pair on one Arduino Uno board. Using the RCSwitch library, I could successfully send and receive signals. Using the Radiohead library however, I could only send and got no reception. I am curious why and grateful for any help.

Here is the sketch. Both receiver and transmitter draw power from Arduino 5V and GND. The DATA pin of transmitter is attached to pin 12 of Arduino. The DATA pin of receiver is attached to pin 11. These appear to be "hard-coded" in the Radiohead library. My reciever has an additional chip select (CS) pin which I have wired to pin 10.

Using the serial monitor, it looks like transmitter and receiver are initialized without problem and message is sent. I have used the RCSwitch library with transmitter and receiver on the same board and that worked, (i.e. messages sent were received correctly) so I am curious why the issue with Radiohead.

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependent SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object
RH_ASK rf_receiver;
RH_ASK rf_transmitter;

void setup()
{
    // Initialize ASK Object
    if (!rf_receiver.init())
        Serial.println("Failed to initialize receiver.");
    if (!rf_transmitter.init())
        Serial.println("Failed to initialize transmitter.");

    Serial.begin(9600);

    digitalWrite(10, HIGH);   // enable CS on some receiver devices
}

void loop()
{
    const char *msg = "Hello world!";
    rf_transmitter.send((uint8_t *)msg, strlen(msg));
    rf_transmitter.waitPacketSent();
    Serial.print("Message sent: ");
    Serial.println((char*)msg);

    uint8_t buf[12];
    uint8_t buflen = sizeof(buf);

    if (rf_receiver.recv(buf, &buflen))
    {
      Serial.print("Message received: ");
      Serial.println((char*)buf);
    }
    else
    {
      Serial.print("No message rec'd: ");
      Serial.println(*&buflen);
      Serial.println((char*)buf);
    }

    delay(1000);
}


texts: NRF24L01+ changing configuration after startListening

texts:
I have been trying to get two Arduino UNO talk to each other via NRF24L01's with TMRH20's NRF24 library. I tried many tutorials and examples and none of them worked. Most of them prints some error messages that's due to radio.write returning false.

After some troubleshooting I saw something weird. I set up the configuration (e.g. data rate) and when I call startListening it seems to be changed back.

This code:

void setup() {

    Serial.begin(9600);
    printf_begin();

    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.printDetails();
    Serial.println();

    radio.startListening();
    radio.printDetails();
}

Outputs:

STATUS       = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xe7e7e7e7e7 0x4141417852
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR      = 0xe7e7e7e7e7
RX_PW_P0-6   = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA        = 0x3f
EN_RXADDR    = 0x03
RF_CH        = 0x4c
RF_SETUP     = 0x27
CONFIG       = 0x0e
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 250KBPS
Model        = nRF24L01+
CRC Length   = 16 bits
PA Power     = PA_MAX

STATUS       = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xe7e7e7e7e7 0xc2c2c2c2c2
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR      = 0xe7e7e7e7e7
RX_PW_P0-6   = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA        = 0x3f
EN_RXADDR    = 0x03
RF_CH        = 0x02
RF_SETUP     = 0x0f
CONFIG       = 0x08
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 2MBPS
Model        = nRF24L01+
CRC Length   = 8 bits
PA Power     = PA_MAX

You can see that the address was set up correctly before startListening (0x4141417852) but after it reverted back to what I assume is the default value (0xc2c2c2c2c2). Data rate has also changed.

Is this normal?

The other Arduino UNO doesn't have startListening or stopListening, but if I print the configuration after openWritingPipe I see the correct configuration.


texts:
I am trying to blink an LED with PWM on Arduino.

I don't know what is wrong but my LED is not fading as expected. What is wrong?

I think that I have bad registers settings, but I am not sure.

LED is connected to Arduino pin 9.

Here is my code:

#include <avr/io.h>
#include <util/delay.h>
const int delay=1000;
void initialize_PWM()
{
    TCCR0A|=(1<<WGM00)|(1<<WGM01)|(1<<COM0A1);
    TCCR0B=1;
    DDRB|=(1<<PB1);
}

void set_pwm(uint8_t data)
{
    OCR0A=data;
}

int main (void)
{
    initialize_PWM();
    uint8_t brightness=200;
    while(1)
    {
        for(brightness=0;brightness<255;brightness++)
        {
            set_pwm(brightness);
            _delay_ms(1);
        }

        for(brightness=255;brightness>0;brightness--)
        {
            set_pwm(brightness);
            _delay_ms(1);
        }
    }
    return 0;
}


texts: Why doesn't the Ethernet W5100 shield work on Gigabit switch?

texts:
I have an Arduino Uno with an Ethernet Shield based on the Wiznet W5100 chipset :

It worked like a charm until I had to move it to another location and plugged it to a Gigabit switch. I had no link, the plug LEDs were off, or just on for a fraction of a second then off again.

I tried several switches, router and Internet boxes (french Freebox), and I ended up with the conclusion that it doesn't work when plugged onto a Gigabit switch. On every 10/100 switches, it works.

BUT

I also have a W5100 small module not designed like the shield :

This one is working on Gigabit switches !!!

I did see another post here : WizNet W5100 not connecting to modern switches and routers, where someone told the lower bits of the first MAC Address byte should be 00. So I changed the MAC address to 08:af:01:00:00:03 with no more luck, the shield still doesn't get connectivity.

I googled for this but didn't find any resources. I'm surprised this hasn't come over, knowing that so much ethernet shields are out on the market!

I tried a second shield (like the first picture), same issue : no connectivity on Gigabit switches.

I know other old NICs or laptops that don't support Gigabit are working correctly with Gigabit switches that should "pull down" the port to 100 instead of 1000.

Does anyone have an answer about why it doesn't work and how we can have an Arduino work when connected to a Gigabit switch? (other shields?)


texts:
I want to use CapacitiveSensor library in order to make my own aluminum keys piano. I have seen many videos online showing projects like the one I'm trying to do, but for some reason mine doesn't work.

Here's my cuircit:

Here's my code:

#include <CapacitiveSensor.h>

CapacitiveSensor   cs_7_6 = CapacitiveSensor(7,6);  // 10M resistor between pins 7 & 6, pin 6 is sensor pin

void setup()
{
   //cs_7_6.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
}

void loop()
{
    long start = millis();
    long total1 =  cs_7_6.capacitiveSensor(5);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing

    Serial.print(total1);                  // print sensor output 1
    Serial.println("\t");

    delay(10);                             // arbitrary delay to limit data to serial port
}

This happens whenever I touch the aluminum foil:

First nothing happens (for ~1 sec), then it prints -2 as the capacity value, and when I release my finger from the foil it prints a very high value.

Anyone knows the reason for it? I'm searching for an answer for a long time and still can't find a solution...


texts:
SparkFun sells an FM Tuner Board (here) and provides code to work it.  However, neither libraries that I found in other places, nor the example code that they provided, worked.  I have checked the wiring multiple times and I am nearly certain that the fault is in the code but I can't find it.  Thanks...

ECC


texts:
I'm currently working on nodeMCU and need to use interrupt pin. I find out there are bouncing problem when using interrupt thus i use capacitor 100uF to solve this problem. The question is by using multiple interrupt pin, do i need multiple capacitor (one for each pin) or only one for all pin? The question arise because if I parallel the capacitor it would increase the capacitance and perhaps would create a problem(?)
I using interrupt pin for LM 393 speed encoder like this one
(for simplicity, i use switch to describe the encoder pin on schematic)
Basically work like switch but no floating pin since it is a comparator, always between high or low.
Schematic :


texts:
I'd like to be able to upgrade software on an arduino without physically touching the device or stringing a cable. Can it be done?

Will pick wireless protocol that makes that easiest.


texts: What is the easiest way to count how many global variables are in your sketch code?

texts:
I have a fairly complicated sketch with about 1k lines of code. I should also say that I'm not a programmer by trade...

As I go over my code and try to make it more efficient, it'd be good to know how many global variables are in my code and whether/if all of them are necessary as global. So:

1 - Is there an easy way to count how many global variables you've used (again, imagine complex code by a non-coder), and

2 - Is there an easy way in the Arduino IDE to jump to it?


texts:
I checked several related posts but couldn't solve my problem.

I have Antergos Linux :

# uname -a
Linux biutitude 4.14.11-1-ARCH #1 SMP PREEMPT Wed Jan 3 07:02:42 UTC 2018 x86_64 GNU/Linux

The board is a Seeeduino Lorawan.

The problem is that the menu to select the port is greyed, and when I check in /dev I don't see any new tty when I plug the card. However the card blinks.

I tried :
- adding myself to lock + tty + uucp (and restarted my session)
- created a dialout group because I didn't have one, added myself to it
- loading cdc_acm module but got the following error :

# modprobe cdc_acm
modprobe: FATAL: Module cdc_acm not found in directory /lib/modules/4.14.11-1-ARCH

Thus I tried :

[root@biutitude biu]# depmod -ae
depmod: WARNING: -e needs -E or -F
depmod: ERROR: could not open directory /lib/modules/4.14.11-1-ARCH: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
[root@biutitude biu]# depmod
depmod: ERROR: could not open directory /lib/modules/4.14.11-1-ARCH: No such file or directory
depmod: FATAL: could not search modules: No such file or directory

I'm clearly out of ideas. The weirdest is that a few months ago, I was able to use a RFduino card without any trouble.


texts: Switch on the piezo emitter for a short time

texts:
I need a short beep for every minute of change. I wrote a separate function. The signal duration should be 50 ms, the rest of the time the emitter connected to the A1 contact should be silent.
A really working sketch is shown below:
uint32_t mysound; // Variable for storing time (duration of the sound signal)
uint32_t myTimer1;
uint32_t t; //Time that always increases
byte seconds; // Seconds
byte minutes; // Minutes
int k = 1;
void setup()
{
  DDRC = B00000010; // Set pin A1 as output
  //      76543210
  Serial.begin(9600);
  myTimer1 = millis();
}

void loop()
{
  t = (millis() - myTimer1) / 1000; // Time in seconds
  seconds = t % 60; // when 60 seconds are reached, it is reset to zero
  minutes = t / 60 % 60; // Counts the minutes and drops to zero when 60 minutes are reached
  Serial.println(seconds);
  if (seconds == 0 && k)
  {
    sound();
  }
  if (seconds > 0) k = 1;
}

void sound()
{
  mysound = millis();
  while (millis() - mysound < 50)
  {
    PORTC = B00000010; // We set high voltage on pin A1 for a time of 50 ms
  }
  k = 0;
  PORTC = B00000000;
}


texts:
Can anyone point me towards whats best for relatively low cost distance measuring in the 0-36" range (or 0 - 1m range) with 1/16"/1mm accuracy.  My initial approach was going to be to hack a laser tape measure, but wanted to know if that was the best in cost vs accuracy.

Essentially looking to measure how close I am to a stationary metal plate.

Thanks for any help.


texts: Servo starts spinning 360 degrees after a few minutes

texts:
I'm using my ESP8266 as a web server to tilt a camera with the servo Tower Pro Micro Servo 9G.
#include <Servo.h>
#include <ESP8266WiFi.h>

const char* ssid     = "SSID";
const char* password = "password";

Servo tilt;

WiFiServer server(8082);

void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
  server.begin();
  Serial.println("Server started");
  tilt.attach(2);
  tilt.write(100);
}

void loop() {
  WiFiClient client = server.available();
  if (!client)
  {
    return;
  }
  Serial.println("Waiting for new client");
  while(!client.available())
  {
    delay(1);
  }
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  int value = LOW;

  if(request.indexOf("/SERVO=UP") != -1){
        int t = tilt.read();
        if(t <= 125) {
          delay(10);
          tilt.write(t+8);
        }
  }
  if(request.indexOf("/SERVO=DOWN") != -1){
        int t1 = tilt.read();
        if(t1 >= 75) {
          delay(10);
          tilt.write(t1-8);
        }
    }

  client.println("HTTP/1.1 200 OK"); //
  client.println("Content-Type: text/html");
  client.println("");
  client.println("<!DOCTYPE HTML>");
  client.println("");
  client.print(" CONTROL Servo: ");

  if(value == HIGH)
  {
    client.print("ON");
  }
  else
  {
    client.print("OFF");
  }
  client.println("

");
  client.println("<button>ON</button>");
  client.println("<button>OFF</button>
");
  client.println("");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
}

The first minutes it works fine but after a few minutes it starts turning 360° nonstop. Although, you can't turn this servo over 180°?!
Does anyone of you know what is going on here?
Thanks!


texts:
I am using the File/Examples/Adafruit MQTT Library/mqtt_ESP8266 example as a model for my code.  In the example, the mqtt object is created as a global variable, and everything works fine.  However, I need to create the mqtt object in setup(), because the constructor parameters are not known until then.  If I move the constructor call

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

from the global namespace to inside setup(), I can no longer see it from inside loop().

I have tried declaring a pointer to mqtt in the global namespace, but don't know how to change it to point to the mqtt object that is created in setup().  How can I do this?

David


texts:
I'm fairly new to working and programming with arduinos. The project I am working on is a digital clock which uses a string of WS2812 leds to light up the correct numbers. Each digit consists of 7 leds and there are two 'colon' leds between the second and third digits. I am using the FastLED library to try to program the code. I am able to make the leds light up such that all four digits are the same number (four consecutive 5's). However, the second I try to have it display multiple different numbers, everything goes south quickly. Here are some pictures of my current results:

55:55. I can create this with any number 0-9.

Should be 12:34.
Here is the code that I'm working with so far:
#include <RTClib.h>

RTC_DS3231 rtc;
DateTime now;

#define NUM_LEDS 30
#define LED_PIN 6

CRGB leds[NUM_LEDS];

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

  Serial.begin(57600);

  FastLED.addLeds<WS2812, LED_PIN>(leds, NUM_LEDS);

  FastLED.clear();
}

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

  const int ZERO[]={0,1,2,4,5,6};
  const int ONE[]={2,6};
  const int TWO[]={0,1,3,5,6};
  const int THREE[]={1,2,3,5,6};
  const int FOUR[]={2,3,4,6};
  const int FIVE[]={1,2,3,4,5};
  const int SIX[]={0,1,2,3,4,5};
  const int SEVEN[]={2,5,6};
  const int EIGHT[]={0,1,2,3,4,5,6};
  const int NINE[]={2,3,4,5,6};

  for(int i=0; i<sizeof(ONE);i++){
        leds[ONE[i]]=CRGB::Red;
        FastLED.show();
      }

  for(int i=0; i<sizeof(TWO);i++){
        leds[TWO[i]+7]=CRGB::Red;
        FastLED.show();
     }

  for(int i=0; i<sizeof(THREE);i++){
        leds[THREE[i]+16]=CRGB::Red;
        FastLED.show();
      }

  for(int i=0; i<sizeof(FOUR);i++){
        leds[FOUR[i]+23]=CRGB::Red;
        FastLED.show();
      }

Can anyone explain what's going wrong? Any help would be greatly appreciated. Let me know if you need clarification!


texts: Arduino Mega 2560 from .org- which IDE works?

texts:
My personal choice is to purchase from the .cc (or adafruit) for new boards. YMMV.  Craigslist locally of course has generic and .org boards now and then.

If I get a .org board on craigslist, will I need to use their fork of the IDE for the board to be recognized by the IDE?

My feeling is "yes" but I wanted to confirm.

A board there just now is Arduino mega 2560 from the .org.  Would I have to use their flavor of the IDE?

Thank you for your thoughts- photo of the board I am considering is attached.


texts: Well, first of all hello to everything and thanks for reading my question. I am designing a board with STM32F730R8T6 MCU, and I want to connect MT48LC16M16A2P-6A to it which is 4MB SDRAM chip. The connections are pretty basic from what I saw, the thing is, how can I access that memory from my MCU? I mean there is a library or something to use it? and, if someone can send me an example schematic, to connect the memory I would appreciate it. Greetings.


texts: Can a Ethernet USB Dongle be instead of ethernet shield for arduino?

texts: Can a Ethernet USB Dongle be instead of Ethernet shield for arduino in order to cut costs?


texts: Is it possible for Arduino firmware to recognise only one computer?

texts:
Is it possible to adjust the Arduino firmware to recognise only one PC computer? On other computers it would show driver not recognised or driver not found.

E.g.: My computer should see the Arduino normally, and it should not work if I connect the same arduino to other computers.


texts: afmotor saying "servo does not name a type"

texts: I have made a sumobot with an arduino, an afmotor shield and a 4-pin ping sensor when I upload my code it keeps giving me this error: "'Servo' does not name a type" here is my code.


texts: analogRead() takes >400 us on Arduino Zero but ~100 us on Uno, why?

texts:
I've been trying to figure out why the analogRead() function takes about four times as long on an Arduino Zero than on an Uno, when the Zero has a faster clock than the Uno.  Arduinos website says that it should take around 100 microseconds, and it does on the Uno, but it takes a little over 400 microseconds on the Zero. To time it, I've been setting a digital pin high immediately before the function call and low immediately after and measuring the period on a digital osscilloscope.  I'm just trying to test analogRead, so I'm not doing anything else in this code.  I've tried putting the ADC in freerun mode, and it trims ~15 us off of the ~415 us it currently takes.  I've also used the on-chip debugger to look at the disassembly, and the line that takes too long is always the line waiting for the conversion to complete.  I was also wondering if other ARM-based Arduinos (like the Zero) take over 100 us.  Thanks!

int   sensorPin = A1;
int      ledPin = 11;
int sensorValue = 0;

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

void loop() {
  digitalWrite(ledPin,HIGH);
  sensorValue = analogRead(sensorPin);
  digitalWrite(ledPin,LOW);
}


texts:
I'm making an RC car with the Arduino Nano. I'm using RF433 as  wireless communication with 2 motors and L293D as the motor driver. I use 4 1.5V batteries to power the Arduin and another 6V battery pack to power the motors, and a joystick with an Arduino Mega to send commands through the RF433 to the Arduino Nano.

I've written a program that sends specific digits when the joystick is in a certain position, i.e. when the joystick is "bent" to the front it sends a "1", a "2" is sent when the joystick is bent towards the back, and so on.

My problem is this:

When I bend the joystick towards a certain direction, the RC car moves accordingly without problem; However, when I bend the joystick towards another direction the RC car doesn't respond.

I took a look at what the RC car was receiving, and I've noticed that after the first command was sent (when I bend the joystick towards a certain direction), no more commands get to the RC car (in other words the Arduino Nano), and this occurs occasionally. I think this means the Arduino Nano "froze" after the first command.


texts:
I just have a question regarding Arduino output-pins and Voltage divider, because I am getting other results than what my calculations are giving me.

I have measured the output-pin (from the Arduino) at 4.74V, according to my caulculations I will have and output voltage of 3.39V, with R1 = 4k ohm and R2 = 10k ohm, but when I use my multimeter to measure I read a voltage of 0.97V.

I have tested with a 9V battery, measured to 8.72V. With the same resistors, the calculations gives me 6.23V as output, when I use my multimeter I can read a output of 6.21 which I consider as ok.

So my question is, why is my output from the Arduino only 0.97V with the voltage divider?

For information: I am using Arduino OSEPP Uno R3 Plus.

Hope someone can give me helpfull information.

***************************************update********************************************

My code:

int echoPin = 7;
int trigPin = 6;

int SignalPin = 10;

void setup(){

  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);

}

void loop(){

  float distanceCentimeters;
  int pulseLenMicroseconds;

  digitalWrite(trigPin, LOW);
  delayMicroseconds(20);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin, LOW);

  pulseLenMicroseconds = pulseIn(echoPin, HIGH);

  distanceCentimeters = pulseLenMicroseconds / 29.387 / 2;

  if(distanceCentimeters <= 35 && distanceCentimeters >= 10){

      digitalWrite(SignalPin, HIGH);

  } else {

      digitalWrite(SignalPin, LOW);

  }

  delay(400);

}

Image of the setup (not with Raspberry Pi).


texts:
I am trying to make my small stand-allone programmer to work using this code:
https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer

But when I hookup everything and press button to flash my IC, I get this:

AdaBootLoader Bootstrap programmer (originally OptiLoader Bill Westfield (WestfW))

Type 'G' or hit BUTTON for next chip
Starting Program Mode [OK]

Reading signature:200
Searching for image...
 Not Found
Image fail

When I try to flash the same IC (just to make sure that IC is fine) via Arduino, there's no issues.

Any idea what can be wrong with this?


texts:
I'm trying to dim a 10w LED via Arduino PWM.

This is the LED that I have: http://www.banggood.com/10W-Warm-Pure-White-High-Brightest-Save-Power-LED-Light-Lamp-p-88169.html

Without knowing much about this stuff, I bought this (namely because it had LED, DIM, and PWM in its name): http://www.ebay.com.au/itm/121437119430?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I can't get the eBay dimmer to work for love or money.  When I connect it to ground directly on the battery terminal, it goes off, which means the dimmer circuit is working.  I don't even know where to start with MOSFET dimming solution, but I think that the IRFZ44N MOSFETs are the wrong ones because they won't turn on with 5v power (they need 10v or something, but those are the ones I have on hand).

I can't seem to find any good guides on how to do this after stacks of googling, and to be honest, I don't even know if those LED's can be dimmed in the first place.

What do I need to make this happen?


texts: My brand new LCD screen doesn't display anything, even though there is no code errors?

texts:
I have a LCD screen, and I wanted to use it with a Simon Says game that I am making. I tried the tutorial on the Arduino website, but it doesn't work. Then I tried another tutorial on Adafruit. On this one, the LCD screen seemed brighter which is good, but it also doesn't work.

What it is supposed to look like:

My code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  lcd.begin(16, 2);
}

void loop() {
  lcd.print("Test!");
  delay(500);
  lcd.clear();
  delay(500);
}

I have verified that the wiring is correct on the official version and the Adafruit version, and my screen is brand new from the kit, so what is wrong?

Edit 1:

Let me define "doesn't work." I can turn the potentiometer, but nothing changes. I can't even see white rectangles or even a single pixel on the display. It is blank. Absolutely nothing to see other than the blacklight, which does work.

Edit 2:

Turns out that the diagram was wrong. Needed to move the potentiometer 1 pin to the right, now it works!


texts:
Apologies if this has been discussed before but I couldn't find anything.
I have written a simple LED class. For illustration (it is actually a bit more complex) but it goes something like;
class LED {
    LED(byte pin);
  private:
    int _pin;
};

And the constructor is simply;
LED::LED(byte pin) {
    _pin = pin;
};

and I create a global instance of this class at the top of my code thus;
LED redLED(5);

It is necessary to create this as a global object because (a) I can't create the object in the setup() function because it would go out of scope and (b) I can't create in the loop() function because I don't want to create an infinite number of these objects.
This all seems to work OK but it just leaves me wondering exactly when this constructor gets executed? I suppose that it must be before setup()?
Answered!
Many thanks to all the respondents. So when using the Arduino IDE the build process must silently insert the main() procedure. I was not aware that it did this. I guess that most of the time you can get away with not knowing when the global constructors are called.
It is good practice (I think) to create a "wrapper" class for all/any external (or perhaps internal) hardware devices that are connected to your arduino. And it is thus perhaps tempting (but risky) to do initialisation work in the constructor.
So given what I now know, it is better to create an "init()" method for such classes that can be called from setup(). Even if just to do the the pinmode() call.
Thanks again.


texts: What is Clock pin and Data pin, Orientation in Grove LED bar

texts:
I'm trying to use Grove LED Bar with Arduino

  Grove – LED Bar is comprised of a 10 segment LED gauge bar and an
  MY9221 LED controlling chip. It can be used as an indicator for
  remaining battery life, voltage, water level, music volume or other
  values that require a gradient display. There are 10 LED bars in the
  LED bar graph: one red, one yellow, one light green, and seven green
  bars. Demo code is available to get you up and running quickly. It
  lights up the LEDs sequentially from red to green, so the entire bar
  graph is lit up in the end.

In the github example there are Clock pin, Data pin and Orientation.

// Arduino Clock pin, Data pin, Orientation
// Grove_LED_Bar bar(7, 6, 0);

https://github.com/Seeed-Studio/Grove_LED_Bar/blob/master/LP%20examples/BasicControl/BasicControl.ino

But I have no idea what are they. Where can I find the documentation for them?


texts:
I'm trying to program an ATtiny85, using an AVRISP mkII programmer (this one: https://www.amazon.de/dp/B00IYNAXUC/ref=cm_sw_r_sms_c_api_i_VXOWDb3H3N5ND) with the Arduino IDE (version 1.8.10 on Ubuntu 18.10). For the ATtiny, I've installed https://github.com/damellis/attiny using the board manager, as recommended in countless tutorials.

Now, everything seems to be recognized fine, and I've selected the programmers port in the IDE: /dev/ttyACM0.
But when I try to upload a sketch, the IDE instead trys to pass usb as the port to avrdude. This is only visble when enabling verbose output: (paths abbreviated)

/home/[...]/avrdude -C/home/[...]/avr/etc/avrdude.conf -v -pattiny85 -cstk500v2 -Pusb -Uflash:w:/tmp/arduino_build_728460/sketch.ino.hex:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/[...]/avrdude.conf"
         User configuration file is "/home/[...]/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : stk500v2
avrdude: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2104)

avrdude done.  Thank you.

usb isn't even a selectable port in the IDE!

Simply pasting the avrdude command (first line in the output above) to a terminal and changing usb to /dev/ttyACM0 makes it program the IC perfectly (but of course, that's a rather cumbersome workaround).

Also, selecting another programmer in the IDE (like AVR ISP, without the mkII) makes it use the correct port (but of course it won't work, since it's the wrong programmer).

Am I doing something wrong, or is this an actual bug in the Arduino IDE?


texts:
I am a little confused on how exactly VirtualWire's "send" function works. After looking at the code, the process I gathered is the following.

In the Arduino IDE, call vw_send() with the right parameters.
Inside this method, it will start to encode the message and create the packet.
Then before the function returns, it calls vw_tx_start().
Inside that function, it enables the transmitter hardware and sets the variable "vw_tx_enabled" equal to true. Then this function returns, followed by the immediate return of vw_send(). So there is no where in this flow where the message is actually being sent.

However, the actual transmission of the message happens inside vw_Int_Handler(). But this function is never called in vw_send() or vw_tx_start(). So the only way this could be happening is if there was some sort of multi-threading correct? Because by setting vw_tx_enabled to true, the transmission process would begin inside vw_Int_Handler.

Can someone explain/clarify this?

Moreover, this library uses digitalWrite to transmit the bits. Wouldn't it just be faster to toggle the bits at the registry level?

Lastly, in VirtualWire, they send a 36 bit preamble, I assume this is for synchorinzation purposes. So if I want to send 128 byte packet length, how much of a preamble should I use? I believe the reason for VirtualWire only transmitting 27 byte packet length is because the 36 bit preamble will only keep the data synchronized for that long. So is there a certain formula used to determine the preamble size?


texts: object with multiple instances with internal data store separate for each instance

texts:
I'm trying to keep track of a timer, and the internal variables seem to be overrun by one another.

I just want two instances of the Output class, which can keep track of the _elapsed_time so I can check if the time elapsed. It's a poor-man's real-time for a game. I know there are libraries available and I'm planning to use them, but I would really appreciate knowing what's going on here: I want a buzzer pin, and status led pin to 'blink' at different intervals. They both work individually, but when I have them both uncommented they work somewhat serially...

#include "Arduino.h"

#include "MTC.h"

#include <SoftwareSerial.h>   //Software Serial Port

//HARDWARE SETTINGS
#define PIN_STATUS                  13
#define PIN_BUZZER                  A2

Output *STATUS(0);
Output *BUZZER;

void setup()
{
    Serial.begin(9600);
    STATUS = new Output();
    STATUS->Begin(PIN_STATUS, STATE_OFF);
    BUZZER = new (Output) Output(3);
    BUZZER->Begin(PIN_BUZZER, STATE_OFF);
}

void loop()
{
    static bool run_once = true;

    if (run_once == true)
    {
        run_once = false;
        Serial.print("Running");
        Serial.flush();
    }
    delay(250);

    //Serial.println("still running");

    STATUS->SetStrobe(3000);

    //BUZZER->SetStrobe(4000);

}

and class:

#ifndef MTC_h
#define MTC_H

typedef int OUTPUT_STATE;
OUTPUT_STATE STATE_OFF = 0;
OUTPUT_STATE STATE_ON = 1;
OUTPUT_STATE STATE_STROBE = 2;

class Output
{
private:
    int _pin;
    OUTPUT_STATE _last_state;
    unsigned long _cycle_duration;
        unsigned long _last_elapsed;

public:
    Output();                                           //constructor: set pin data store
    void Begin(int pin, OUTPUT_STATE state);                                //set hardware to output and defaul state
    void Set(OUTPUT_STATE state);                               //toggle operability
    void SetStrobe(unsigned long duration);                     //strobe operability
};

Output::Output()                                    //constructor: set pin data store
{

}

void Output::Begin(int pin, OUTPUT_STATE state)
{
    _pin = pin;
        _last_elapsed = millis();
    pinMode(_pin, OUTPUT);
    digitalWrite(_pin, state);
    _last_state = state;
}

void Output::Set(OUTPUT_STATE state)
{
    if (_last_state != state)
    {
        digitalWrite(_pin, state);
        _last_state = state;
    }
}

void Output::SetStrobe(unsigned long duration)
{
    static OUTPUT_STATE _last_strobe_state = STATE_OFF;

    unsigned long elapsed = millis() - _last_elapsed;
    if (elapsed >= duration)
    {
        if (_last_strobe_state == STATE_OFF)
        {
            digitalWrite(_pin, STATE_ON);
            _last_strobe_state = STATE_ON;
        }
        else
        {
            digitalWrite(_pin, STATE_OFF);
            _last_strobe_state = STATE_OFF;
        }
        _last_state = STATE_STROBE;
        _last_elapsed = millis();
    }
}
#endif


texts:
So i have a D1 mini that I want to connect to the wifi.
I found the following code on the internet that is supposed to start a web server, that you can visit and then connect to the chosen wifi through the website. It will then remember the settings and try to connect to that wifi next time before it starts a web server - which is just what I need!
The problem is that when I connect to the wifi the d1 mini thinks it did just than - but when I visit my router and check it is not connected.

I cannot figure out why it thinks it's connected but is not, can anyone help me?

#include <FS.h>                   //this needs to be first, or it all crashes and burns...
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager

void setup() {

  Serial.begin(115200);
  Serial.println();

  //WiFiManager

  WiFiManager wifiManager;

  //reset settings - for testing
  wifiManager.resetSettings();

  IPAddress _ip = IPAddress(192, 168, 0, 35);
  IPAddress _gw = IPAddress(192, 168, 0, 1);
  IPAddress _sn = IPAddress(255, 255, 255, 0);

  wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);
  if (!wifiManager.autoConnect("WemosAP", "ConfigureMe")) {
    Serial.println("failed to connect, we should reset as see if it connects");
    delay(3000);
    ESP.reset();
    delay(5000);
  }
  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
  Serial.println("local ip");
  Serial.println(WiFi.localIP());
}
void loop() {
}

btw: the ip 192.168.0.35 is free, and I have checked both the gateway and the subnet mask from my laptop by running ipconfig in cmd.


texts: How to connect ESP8266 12e directly to Arduino Uno (without shields)

texts:
I have an ESP8266 12E module and I'm trying to connect it to arduino, without any shields or whatsoever. I've looked everywhere but all I can find is about ESP-01 or with a NodeMCU. I'd like to do the bridge manually, but I don't know which pins I should ground and which pins I should power.

This is my current setup:

And the following sketch:

#include <SoftwareSerial.h>

//RX pin 2, TX pin 3
SoftwareSerial esp8266(2, 3);

#define DEBUG true

void setup() {
  Serial.begin(9600);
  esp8266.begin(115200);
  sendData("AT\r\n", 2000, DEBUG);
  delay(1000);
  Serial.println("Firmware version:");
  delay(3000);
  sendData("AT+GMR\r\n", 2000, DEBUG);
  Serial.println("** End **");
}

void loop() {}

String sendData(String command, const int timeout, boolean debug) {
  String response = "";
  esp8266.print(command);
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (esp8266.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      response += c;
    }
  }
  if (debug)
  {
    Serial.print(response);
  }
  return response;
}

When run, I get the following output:

Firmware version:
** End **

On the module, the led flashes when I power it up, but after that it remains off. I've already tested the voltage regulator with ReadAnalogVoltage, and the output was 3.33v, so it is working.


texts: I'd like to use Arduino libraries installed in C:\Users\Username\Documents\Arduino\libraries in a PlatformIO project. Is it possible? if so, how?


texts:
I am using Arduino environment 1.6.17 on OS X, 10.12.2. In this version, all of the core avr library stuff is located in ~/Library/Arduino15.

I was told by a vendor that in order for their program to compile properly, I needed to compile it under 1.6.4 of the Arduino environment. I dowloaded that version and compiled the program again. I could tell though, by the compiler messages, that while the IDE may be version 1.6.4, the program was still compiling with version 1.6.17 tools and avr libraries. Is there anyway to change that so I can get it to actually compile with all tools and libs from 1.6.4?


texts:
I use Fedora 24/25 and now Ubuntu 17.04 Gnome on my Lenovo Yoga 900, which has an extremely high pixel density display. For these situations on Mac and Windows, I find a gui.scaling option in the Arduino settings. However, on Linux there is no such option, and entering it in ~/.arduino15/settings.txt does not have any effect.
The version I use is Arduino 1.6.4 (now 2.1.0.5) from the Fedora (Ubuntu) repos. Is the scaling gui option not implemented on linux? Or is there some fix for this?
On the physical display the following screenshot has an approximate width of 4cm -> the green buttons are not usable at all!


texts: Send big amouts of data to PHP script via gsm module SIM800L

texts:
I'm looking for a way to get lots of sensory data from my Arduino Micro to a PHP script.
My current attempt is using the following AT-commands:

Sent: [AT+HTTPPARA=URL,www.example.com/newData.php?data=t0_20.75,l_0.00,m_584,h_42,td_22,d_21x44x54]
Res: [AT+HTTPPARA=URL,www.example.com/newData.php?data=t0_20.75,l_]

As you can see I send a long GET-parameter to my server with shortened parameter Names like t0 for temperature sensor number zero, l for light and so on.

In the response from my SIM800l I get back a string with exactly 63 characters, so I assume there's some lenght limitation there on the SIM-module.

After that command when it tries to finish the HTTP request I get a lot of errors as AT-command responses and no GET data arrives on my script.

I check wheter or not data has arrived with the following function on my server:

ob_start();
echo "Var_dump of GET\n";
var_dump($_GET);

echo "Var_dump of POST\n";
var_dump($_POST);
$vd_res = ob_get_clean();

file_put_contents('postdump.log', $vd_res."\n",FILE_APPEND);

When typing some data directly into the browser it saves my sent data in postdump.log so I'm pretty sure the SIM-module can't handle the given amount of data.

Do you have any idea how I can send bigger amounts of data all at once? For energy saving purposes I would prefer if it would be possible in only a single request.


texts:
I'm thinking about making a custom Arduino-based mouse and I expect not to be the first one to have the idea. Does anybody know what speed I can expect to achieve? Suppose I use a mechanical mouse as a base, meaning I'll have to monitor 3 buttons and 3 axes (X, Y and wheel), debounce the signals coming from the buttons and transmit all that data via USB. How many times per second will I be able to do this, theoretically? Are there any projects which did something similar, and if so, what speed were they able to achieve?

To make a good mouse, I suppose I should at least beat my display's refresh rate which is 60 Hz, otherwise pointer movement won't be smooth. My current (commercially produced) mouse runs at 100 Hz.


texts: Arduino GSM receiving text and then storing value as a variable in code

texts:
I am using an Arduino Mega board with a SIM900 GSM.

My goal is to be able to text the GSM with a value of two digits (ex: 79) and then store that value as a variable in the code. I know how to set up the Mega and the GSM in terms of wiring and initialization of ports, but how would I write a short function to test the incoming values and save them to a variable?

I thought about testing each bit individually, storing each one as a separate variable, and then adding them for the total. For example, if the GSM received "#79" as a text I stored the value 7 as an integer variable named One and the value 9 as an integer variable named Two. Then I did

Total = (One*10)+Two.

I am posting my code below that used this method, although it has not proved to be useful. If anyone has any suggestions I would greatly appreciate it.

#include <SoftwareSerial.h>   //GSM Library

int Max_temp;
float threshold;

SoftwareSerial SIM900(18, 19);
String destinationNumber = "+17186578989";
String outMessage1 = "Please enter the maximum desired room temp";
char inchar; // Will hold the incoming character from the GSM shield when user texts it
int M_one;
int M_zero;
void GSM_SEND_MAX();
void GSM_RECEIVE_MAX();

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

//GSM setup:
  Serial1.begin(19200);  // wake up the GSM shield
  delay(20000); // give time to log on to network.
  Serial1.print("AT+CMGF=1\r"); // set SMS mode to text
  delay(100);
  Serial1.print("AT+CNMI=2,2,0,0,0\r"); // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
}// end void set up()

void loop()
{
  GSM_SEND_MAX();
  GSM_RECEIVE_MAX();
}// end void loop ()

/////Functions
void GSM_SEND_MAX()
{
  Serial.println("sending text");
  Serial1.begin(19200);
  delay(20000); // give time to log on to network.
  Serial1.print("AT+CMGF=1\r");
  delay(1000);
  Serial1.println("AT + CMGS = \"" + destinationNumber +"\"");
  delay(1000);
  Serial1.print(outMessage1);
  delay(1000);
  Serial1.write((char)26); //ctrl+z
  delay(1000);
  Serial.println("send text");
}//end GSM_SEND_MAX funtion

void GSM_RECEIVE_MAX()
{
  //If a character comes in from the cellular module...
 while (Serial1.peek() != '#' )
   {
    inchar=Serial1.read();
    Serial.print("bad char ");
    Serial.println(inchar);
    delay(500);
   }// end while #1

 inchar=Serial1.peek();
 Serial.println("out of loop 1");
 Serial.println(inchar);

 while (Serial1.available() != 0) //While #2 reads incoming char
 {
    Serial.println("in loop 2");
    inchar=Serial1.read();

if (inchar=='#')
  {
  delay(10);
  Serial.print("got #");
  M_one=Serial1.read();

  if (M_one >= 0 )
  {
  delay(10);
  Serial.println();
  Serial.print("got M_one");
  Serial.print(M_one);
  M_zero=Serial1.read();

      if (M_zero >= 0)
      {
          Serial.println();
          Serial.print("got M_zero");
          Serial.print(M_zero);

       }//end m_zero

  }//end m_one
  Max_temp = (M_one *10) + M_zero;

  Serial.println();
  Serial.print("Max_temp=");
  Serial.print(Max_temp);

  } //end if (inchar==#)

 }// end while #2 loop
}//end GSM_RECEIVE_MAX function


texts:
I am currently building a MultiWii based drone, I have built the emisor-receptor that interface 4 analog signals(4 potentiometers to control the drone) and it works perfect, the receiver(arduino Nano, receives correctly the signal and parses it on 4 diferent integrers as expected (values between 1000 and 2000 because the MultiWii software expects that value range), but the problem is when I connect the receiver Nano to the MultiWii controller(Arduino UNO) the Arduino UNO receives incorrect values from the PPM signal(the four channels gets crazy unless the four potentiometers are turned full) so I think that the problem is the PPM generation process.

The problem is that I have taken code from internet to do that signal generation (because I don't know how to do it), and I don't know how to solve it.

Here I paste the NANO receiver to PPM code:

#define channel_number 4
#define sigPin 2
#define PPM_FrLen 27000
#define PPM_PulseLen 400

#include <SoftwareSerial.h>

int ppm[channel_number];

struct Received_data {
  byte ch1;
  byte ch2;
  byte ch3;
  byte ch4;
};

Received_data received_data;

String input;
int throttle, th;
int aileron, ail;
int elevator, el;
int rudder, rud;

unsigned long lastRecvTime = 0;
int boundLow;
int boundHigh;
const char delimiter = ',';

SoftwareSerial hc12(9, 10);

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

  pinMode(sigPin, OUTPUT);
  digitalWrite(sigPin, 0);

  cli();
  TCCR1A = 0;
  TCCR1B = 0;

  OCR1A = 100;
  TCCR1B |= (1 << WGM12);
  TCCR1B |= (1 << CS11);
  TIMSK1 |= (1 << OCIE1A);
  sei();

  reset_received_Data();
}

void reset_received_Data()
{
  received_data.ch1 = 0;
  received_data.ch2 = 127;
  received_data.ch3 = 127;
  received_data.ch4 = 127;

  PPM_width_Values();
}

void PPM_width_Values()
{
  ppm[0] = map(received_data.ch1,   0, 255, 1000, 2000);
  ppm[1] = map(received_data.ch2,   0, 255, 1000, 2000);
  ppm[2] = map(received_data.ch3,   0, 255, 1000, 2000);
  ppm[3] = map(received_data.ch4,   0, 255, 1000, 2000);
}

void receive_the_data()
{
  if (hc12.available())
  {
    input = hc12.readStringUntil('\n');
    if (input.length() > 0)
    {
      //Serial.println(input);

      boundLow = input.indexOf(delimiter);
      ppm[0] = input.substring(0, boundLow).toInt();

      boundHigh = input.indexOf(delimiter, boundLow + 1);
      ppm[1] = input.substring(boundLow + 1, boundHigh).toInt();

      boundLow = input.indexOf(delimiter, boundHigh + 1);
      ppm[2] = input.substring(boundHigh + 1, boundLow).toInt();

      ppm[3] = input.substring(boundLow + 1).toInt();

      Serial.print(ppm[0]); Serial.print("   ");
      Serial.print(ppm[1]); Serial.print("   ");
      Serial.print(ppm[2]); Serial.print("   ");
      Serial.print(ppm[3]); Serial.print("\n");
      delay(10);
    }

  }
}

void loop()
{
  receive_the_data();
  digitalWrite(13, HIGH);

}

#define clockMultiplier 2

ISR(TIMER1_COMPA_vect) {
  static boolean state = true;

  TCNT1 = 0;

  if ( state ) {
    //end pulse
    PORTD = PORTD & ~B00000100;
    OCR1A = PPM_PulseLen * clockMultiplier;
    state = false;
  }
  else {
    //start pulse
    static byte cur_chan_numb;
    static unsigned int calc_rest;

    PORTD = PORTD | B00000100;
    state = true;

    if (cur_chan_numb >= channel_number) {
      cur_chan_numb = 0;
      calc_rest += PPM_PulseLen;
      OCR1A = (PPM_FrLen - calc_rest) * clockMultiplier;
      calc_rest = 0;
    }
    else {
      OCR1A = (ppm[cur_chan_numb] - PPM_PulseLen) * clockMultiplier;
      calc_rest += ppm[cur_chan_numb];
      cur_chan_numb++;
    }
  }
}


texts: It seems as if there is a 220K pull-down resistor on analog pin 0

texts:
So I am building a project that uses the analog pins for precise measurements of resistance through a voltage divider and I have been having some seemingly unsolvable problems with nonlinear response to linearly changing resistances when using the A0 pin to measure.

I first realized this was the problem when I had a voltage divider consisting of a 76.8K and 100K 1% resistors with Vout connected to A0, and I was consistently getting wrong values. I measured the output voltage of the voltage divider and got 1.7V, instead of the ~2.7 volts I should be getting with my supply. When I disconnected the wire to A0, the voltage rose to the expected level.

I disconnected power and measured resistance between the analog pins of the Atmega328 I was using and ground and found that A0 had 220K of resistance, while all other pins measured as infinite. When using the other pins, the voltage divider returned the expected values and was able to measure a wide range of resistors with values just as accurate as my multimeter. I know I have changed a lot of low-level things with code (analog reference, the comparator, ADC clock prescalers, using analog pins as outputs, etc.) but I don't think any of this could persist while the chip is not powered on. Does doing any of these things connect a resistor in the way I was describing, and is there anything that could cause this to stay "stuck" this way?


texts: What design patterns can I use to handle user input and display updating?

texts:
I've used enough products with embedded microcontrollers and unresponsive UIs to know that it can make or break a product. Even a slight delay or lag between the button presses and the display updating, or button presses being ignored or double counted, can be extremely frustrating.

What design patterns can be used to deal with user input (from buttons) and updating displays without causing these issues?

I currently use the following kind of pattern (this is simplified down to the bare minimum):

#include <Bounce.h>

#define GREEN_LED       6 // Pin for green LED

#define BUTTON_PIN      15 // Pin for button - uses external pull down so active high

#define DISPLAY_REFRESH_INT 100 // How many MS between display updates

Bounce button = Bounce(BUTTON_PIN, 5);

// To signal between the button read and the display update
bool ledState = false;

// Used to keep track of last display update
long displayUpdate = 0;

void setup()
{
    pinMode(GREEN_LED, OUTPUT);
    pinMode(BUTTON_PIN, INPUT);
}

void loop()
{
    // Read the button status
    if (button.update())
    {
        if (button.risingEdge())
        {
            ledState = !ledState;
        }
    }

    // Update the display periodically
    if (millis() - displayUpdate > DISPLAY_REFRESH_INT)
    {
        displayUpdate = millis();

        digitalWrite(GREEN_LED, ledState);
    }

}

What other options are there? Is it ever worth using pin change interrupts to read buttons (if we are not considering battery life!).


texts: Leonardo (32u4): ways to brick it programmatically

texts:
When the Leonardo was introduced, I think, I've read some articles about being cautious to do some things, that could cause it to not load any new sketches any more, so one has to rewrite the bootloader. Because I plan to use power-saving options, e.g. to disable unused hardware components like USB port, I fear to do something wrong.

One Leonardo-delicacy I've found so far:

if interrupts are disabled, uploading new sketches fails unless one presses the Reset button as soon as the Arduino IDE is showing "Uploading..."

What stuff (except of the usual hardware-related thinks like connecting output-configured pins to fixed potentials) could damage the controller or require to reflash the Leonardo with a fresh bootloader?


texts: Multiple Interrupt Pins Generates Wrong Pulses

texts:
On MKR WAN 1300 board I added pulldown resistors to 0,1,4,5,6,7,8 pins to count pulses.I can catch interrupts, but sometimes pulses occur on other pins even though they are not touched. For example, button pulses are generating on pin 2 but shows pins 3 is also triggered , it shows like
pin 2=1
pin 2=2
pin 2=3
pin 2=4
pin 2=5
pin 2=6
pin 3=1
pin 2=7

What can be the reason ? How can I solve it ?

#include <MKRWAN.h>

#define debugSerial Serial
#define loraSerial Serial1

int DEBUG = 0;

/* Pins of External Interrupts */
const byte WATER_METER_1 = 0;
const byte WATER_METER_2 = 1;
const byte WATER_METER_3 = 4;
const byte WATER_METER_4 = 5;
const byte WATER_METER_5 = 6;
const byte WATER_METER_6 = 7;
const byte WATER_METER_7 = 8;

volatile int watMeterPulseArray[7] = {0, 0, 0, 0, 0, 0, 0};

unsigned long pulseTime[7] = {0, 0, 0, 0, 0, 0, 0};
unsigned long lastTime[7] = {0, 0, 0, 0, 0, 0, 0};
const long interval = 2000;// interval for next pulse

int  watMeterPulseArraySize = sizeof watMeterPulseArray / sizeof watMeterPulseArray[0];

void checkAndVerifyPulse(int pin) {
  pulseTime[pin] = millis();
  if (pulseTime[pin] - lastTime[pin] > interval ) {
    lastTime[pin] = pulseTime[pin];
    watMeterPulseArray[pin] ++;
    printlnToScreen("pin " + String(pin) + "=" + String(watMeterPulseArray[pin]));
  }
}
void incrementWatMeter1() {
  checkAndVerifyPulse(0);
}
void incrementWatMeter2() {
  checkAndVerifyPulse(1);
}
void incrementWatMeter3() {
  checkAndVerifyPulse(2);
}
void incrementWatMeter4() {
  checkAndVerifyPulse(3);
}
void incrementWatMeter5() {
  checkAndVerifyPulse(4);
}

void incrementWatMeter6() {
  checkAndVerifyPulse(5);
}

void incrementWatMeter7() {
  checkAndVerifyPulse(6);
}

void setup() {
  debugSerial.begin(115200);
  // If debugSerial is available(device connected to PC) set debug
  while (!debugSerial && millis() < 10000) ;
  if (millis() < 10000) {
    DEBUG = 1;
  }

  delay(100);

  pinMode(WATER_METER_1, INPUT_PULLDOWN);
  pinMode(WATER_METER_2, INPUT_PULLDOWN);
  pinMode(WATER_METER_3, INPUT_PULLDOWN);
  pinMode(WATER_METER_4, INPUT_PULLDOWN);
  pinMode(WATER_METER_5, INPUT_PULLDOWN);
  pinMode(WATER_METER_6, INPUT_PULLDOWN);
  pinMode(WATER_METER_7, INPUT_PULLDOWN);

  attachInterrupt(digitalPinToInterrupt(WATER_METER_1), incrementWatMeter1, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_2), incrementWatMeter2, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_3), incrementWatMeter3, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_4), incrementWatMeter4, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_5), incrementWatMeter5, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_6), incrementWatMeter6, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_7), incrementWatMeter7, RISING);

  delay(100);
}

void loop() {

}

// If Serial port is available on PC, print message to screen
void printToScreen (String message) {
  if (DEBUG) {
    debugSerial.print(message);
  }
}
void printlnToScreen (String message) {
  if (DEBUG) {
    debugSerial.println(message);
  }
}```


texts:
When powering up my WeMos D1 ESP8266, I suddenly find this hotspot named "FaryLink". What is this? I programmed the ESP to work as a web server, thus connecting to an existing hotspot and not providing any beacons or acting as an access point.

Google could not provide any information to this behaviour.

What is the purpose of this AP and how can I use / disable it?


texts: Atmega328p with arduino without the board

texts:
Perhaps this is a beginners question and I am not sure. I currently have a custom made circuit with an atmega328p chip connected to an mpu6050. However, when I program in Arduino I am not sure what to do? I can't pick a "board" as the atmega328p doesn't belong to a board? (from what I'm aware at least)
How in Arduino do I choose to program for my atmega328p chip? Without having to pick a board such as Arduino Uno etc. As I don't have any board for this. Or does the atmega328p chip always belong to a certain board?
I have a fully working circuit with a cyrstal (16MHz), battery sources, atmega328p etc. But I don't know how to program it with Arduino? I can program it in C, but would like to use Arduino due to certain libraries.


texts:
I am using both Arduino nano and Arduino mega boards in my projects.  I got a nasty surprise the other day when I learned that, on the nano, Analog pins 6 and 7 can not be used as digital pins.

Are there any Analog pins on the mega that can not be used as Digital?


texts:
I've taken apart an old range finder (see photo here). It uses a circular, seemingly gold-plated, two-wire sensor that I'd like to re-use in an Arduino project.
I'm looking for a datasheet of the sensor and/or a circuit-diagram. Any help is welcome.


texts: Charlieplexing 30 LED sections with a max of 27 LEDs at the same time?

texts:
So basically, I'm trying to make a digital wall clock and using digital numbers, I have 7 sections of LED's per number, 4 numbers and one section for the colon in between them. A total of 30 sections. The colon will toggle every second so the the most possible simultaneously glowing sections is 27. That's because of the time 08:08.
Is there any way to make this work with an arduino? Possibly by Charlieplexing the arduino into 30 sections, using 6 pins. Or is there something out there that has 30 pins!?

The problem of course with charlieplexing, is that you need it to become rapid pulses. I'm sure I'm going to need some help with this, and also with laying out a schematic.

To be clear, this is how the led sections are going to be laid out. I also know I'm going to need an npn transistor for every single one of them. the biggest section uses 20 LEDs.

Thanks!


texts: What is the frequency of PWM output on Arduino

texts:
What frequency do Arduinos use for normal PWM when you use analogWrite()?

And is it different for different Arduino model? I'm interested specifically in the Mega 2560, but also want to know if it's consistent between models.

I've seen a passing references to the Arduino using 500 Hz, which seems really slow.


texts:
Coming from a C# background where I do logs for every application, and given that I will be using the Mega for most projects and therefore have the memory available to do so, I want to incorporate error logging in my projects.

What is the best way to do so? Writing to an SD card? Writing via Wi-Fi or Ethernet to a networked storage or PC? Writing to a USB thumb drive?

The current project I am working on uses the Adafruit Music Maker shield so has the SD card reader incorporated into it, so the easy choice there would be to use that but I like creating solutions that are portable to multiple projects so writing via Wi-Fi or Ethernet seems to be the preferred method?

Since I am not fully up to speed with C++, and I see there are various ways to write to text files in C++, are there any preferred ways to do so depending on which storage route I take?


texts: Any problems taking arduino(esque) devices through airport security?

texts:
I'm flying out for vacation, and I want to take some of my half-done arduino projects with me to work on.  I'm concerned that aiprort security might mistake my devices for something sinister or at bare minimum 'suspicious' and be confiscated.

Has anyone ever had any negative experiences taking arduino-esque wiring projects through airport security?


texts: How can I automatically start a LAN connection?

texts:
I have a Samsung Galaxy Note 10.1 with JuiceSSH installed. I also have Debian Linux installed via chroot. I'll be ordering an Intel Galileo to use as a portable compilation server. I have an attachment for the Note 10.1 that serves as a USB and an ethernet adapter. I figure I could power the Note 10.1 with the USB port and connect to it via SSH through the ethernet port.

Unfortunately, this post notes that in order to connect the Galileo via ssh, the LAN connection must be started manually through Arduino Sketch.

I'd like to install Debian Linux on the Galileo, get rid of my chroot Debian on my tablet, and have that LAN connection started automatically when the Galileo boots so that I can just connect to it through JuiceSSH on my tablet. This is so I can do everything without depending on WiFi and compile "offline". How do I automatically start the LAN connection and avoid having to use Arduino Sketch?

Also, does anyone know if ArduinoDroid works on the Galileo?


texts: I'm working on a project where I need to control the light of 5 buttons as well as listen when each button is switched on/off by the user. I would furthermore like to provide feedback on an OLED display. It looks like I'm running out of pins. This https://arduino.stackexchange.com/a/22689/69029 provides several options for that. I would specifically like to explore the option to have several arduinos connected to each other in a master/slave configuration. Where can I learn more about my option to build stuff using several Arduinos connected to each other? I can also forsee scenarios where I could use 3.3V devices as well as 5V devices.


texts: My question is about the arduino Nano or Micro and the smallest and cheapest way to control a bigger power source. I would wire it with a socket so that I could send a command from the board and a light would turn on for example.


texts:
The arduino website states that the operating voltage of an arduino is 7-12V.

Why does the arduino work powered on just usb then? As usb only outputs 5V and 500ma.

Is it preferable to say run the arduino on an external 9V dc power source, or does it make no difference?


texts: Why doesn't this debounce function work?

texts:
Edit 2
I made a function that works, but I'm still confused about just one thing...

I'm very confused about how variables work in C++.

In this program...

  boolean debounce(void)
{
  static boolean buttonState=LOW;
  static boolean lastButtonState;
  boolean currentState = digitalRead(4);
  static unsigned long lastDebounceTime;
  if (currentState != lastButtonState){ //if the button state has changed
    lastDebounceTime=millis();  //reset timer
    }

  if ((millis()-lastDebounceTime) > 50)  //if 50 milliseconds has passed since last bounce
  {
    buttonState = currentState;  //read value again now that bouncing is over

    }
  lastButtonState = currentState;
  return buttonState;
}

Why does changing this

lastButtonState = currentState;

To this

lastButtonState = buttonState;

Make any difference in the program?

When I try the latter line of code, the whole function stops working and I don't understand why.


texts:
I am working on a project where I need the Arduino to 'sense' at what direction its moving. For example, I want the Arduino to 'sense' that it
is moving towards 'forward' direction, 'backwards' direction etc.

Is that possible using an Arduino? Can I use a motion sensor to do this (probably not)?

Can any one please help me to find the right 'direction'?


texts: SIM900 module not responding on hardware COM port

texts:
I've got my sim900 module working with arduino by using their software serial library, however, I want to eliminate arduino from the equation and have serial communication directly to sim900 module.

I'm using putty as my terminal emulator. It's serial is configured to COM1 19200 8 N 1 the same as device manager configuration for this port.

I connect straight from hardware serial on my PCs motherboard into serial-to-ttl interface board which connects to sim900 module. The board has 4 pins - VCC GND TX RX. They're all connected to my sim900 hardware serial as follows: VCC=5V GND=GND TX=TX RX=RX (Yes I know that it's always actually TX=RX and RX=TX, but when I connect it that way my interface board doesn't blink any led to indicate a transfer whereas it does when I connect TX=TX and RX=RX). The switch on the module is set to hardware serial pins as well.

So the only thing that happens when I send AT commands such as AT or ATI and press enter is that puttys cursor comes back to the beginning of command that I typed. No response.

I'm thinking that I'm not doing something that the arduinos software serial port is doing when it sends commands to sim900.

Can anyone help please ? It's literally been days of trying different configurations with no results.

In that time besides getting sim900 working with arduino software serial I verified that the hardware serial port on my motherboard is working correctly and the interface board is working correctly as well.


texts: Convert Hex to Decimal from signed 2's complement

texts:
I am reading data from a meter over dlms protocol and I am getting hex values from there. I want to convert that hex string to signed decimal value. For example - ff9d denotes a value of -99 [reference].
My hex to decimal code is:
unsigned int hexToDec(String hexString)
{
  unsigned int decValue = 0;
  int nextInt;

  for (int i = 0; i < hexString.length(); i++)
  {
    nextInt = int(hexString.charAt(i));
    if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
    if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
    if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
    nextInt = constrain(nextInt, 0, 15);
    decValue = (decValue * 16) + nextInt;
  }
  return decValue;
}

Can anyone please help me how to do it in Arduino IDE?


texts: 8 bit arduinos: What happens to the data in registers during a function call? During an interupt?

texts: If I have one function that uses registers heavily calling another that does the same thing, what happens?  Does the data get destroyed?  What, then, would happen on return to the first function?  Is this different for interrupt handlers?


texts: Detect where pressure is being applied by using force resistors

texts:
I have 3 force resistors in a row, on top of which I have placed a board. I read values from the resistors through analogue ports. My goal is to be able to detect whether someone is pressing on the top, middle, or bottom of the board.

So far I can easily detect the left and right, like this: I first calibrate the 3 sensors for 2 seconds. Then I detect if pressure is applied on any of the calibrated sensors. If yes, I sum for all of them the values that they return on each round of the loop, until force has stopped being applied. I finally compare the 3 values against each other and I find which received higher pressure in total. This works perfectly fine for the left and right. However, when the board is pressed in the middle, pressure is applied on all 3, since the board is flat. Sorting the values does not help, because very often the left and right sensors have recorded a higher value than the middle.

I noticed that when the board is pressed on the left, the right sensor records very few values, and the same for the other way around. So, I get a high success rate in detecting middle presses like this:

int threshold = 80;
if (left_sum > threshold && middle_sum > 80 && right_sum >80)
    return middle_pressed;

However, when someone presses hard enough on the left or right, the if statement is satisfied.

Is there a more accurate way to detect where force is being applied?

(Following is a quick schematic I made - I am not at all an expert so please excuse me for my mistakes, I just hope it illustrates more or less what it is supposed to)

simulate this circuit – Schematic created using CircuitLab

Please ignore the double arrows right on top of the resistors.


texts: How are libraries added to the Arduino library manager?

texts: Who curates the list of libraries in the Tools / Manage Libraries menu, and what is the procedure for submitting code for consideration?


texts: Arduino UNO - analogRead() returning mixed results

texts:
I have created a small circuit with a 220 Ohm resistor and a LED connected to PIN9 for power.

I want to measure the Voltage of the current flowing through the circuit. In order to do that I connected a bridge from between the resistor and the LED to the A3 PIN and used this code:

int ledPin=9;
int inPin=A3;
long int in=0;
float V_in=0;
int val;

void setup() {
  analogReference(DEFAULT);
  pinMode(ledPin, OUTPUT);
  pinMode(inPin, INPUT);
  Serial.begin(9600);
  }

  void loop() {
    if (Serial.available() > 0) {
      val = Serial.parseInt();

      if (val>=0 && val<=155) {
        analogWrite(ledPin, val);
        //Serial.println(val);

        for (int i=0; i<10; i++) {
          val+=5;
          analogWrite(ledPin, val);
          //Serial.println(val);

          delay(1000);
          in = analogRead(inPin);
          V_in=float(5.0)*(float(in)/float(1023));
          Serial.println(V_in);
          delay(1000);
          }

        }
        else {
          Serial.println("Dio è morto.");
          }
      }
    }

The problem is that when I run it, with an Input of 55, I get what seams to be a random arrangement of 0s and 2.56s. While I expect a increasing sequence of numbers between 0 and 2.5.

What am I doing wrong?

I measured the Voltage on the A3 Pin using a voltimeter, and it increases every step by 0.2, exactly as expected.

This is an output example:


texts:
I'm using a simple microswitch on pin 2, to activate an external interrupt.

void pause()
{
  Serial.print("\n\nPause\n\n");
  delay(1000);
}

void setup()
{
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(0, pause, RISING);
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  Serial.print("\nGoing");
  delay(100);
}

When I tap the micro switch, some reason, my serial monitor output looks like this:

Just to clarify, there is no delay between any of

Is this just some serious debouncing, causing my Arduino to find lots of rising instances? or is there some kind of problem in my code?


texts: I'm looking for a real small but decent Arduino, that can fit in a watch but power a servo and a gyroscope

texts: I've been scouring the internet looking for a small Arduino that can power two sensors and a servo. Is there a way of getting a custom one? Does anyone know if theres software out there for creating custom Arduinos and having them made?


texts:
Consider this scenario, I have a single byte of data; I have to use the 8 bits it is composed of to generate 4 extra bits from it.

Now, my problem is that I have to store this data somewhere while I operate on it and then return the final answer in byte form.

eg. 1 byte of 8 bits becomes 12 bits. Thus 2 bytes results in 24 bits which I want to transfer in packets of 3 bytes.

01001101 becomes this with added bits: _ _ 0 _ 1 0 0 _ 1 1 0 1

What would be the most efficient way to accomplish this?


texts: Cheapest Arduino wireless solution for home automation

texts:
I am from programming background and newbie to this field.

Couple of days ago I brought Arduino Uno (5V). I want to control light bulb and fan from my Android. So I thought, I will buy relays and ESP8266 module and its done.

But now read somewhere that ESP8266 works with 3.3v and my Arduino supplies 5v.

Should I go for different Arduino board (like Arduino pro or Arduino mini) or is there any reliable & cheap solution that will work my Arduino Uno (5V) ?