texts:
Objective: To get my USB keyboard to interface with an Arduino Uno board.

Constraints: I can't afford a USB host shield for now for Arduino. Currently available is a keyboard with PS/2 connector. That example is available here. However, it is silly going for such a keyboard, or, buy a USB to PS/2 converter at the moment.

Challenge: USB has VCC, GND, RX/TX. (Rx/Tx also labelled D+/D- respectively). The parallel port connector has the following:

Where will the D- pin go?


texts: Sending GPS data to computer via USB and then to iPhone app through Wi-Fi on LAN

texts:
I was wondering how I would parse data from a GPS module from the Arduino to my laptop and from there send it to an iPhone app I'm building.

One idea I had was to have it print the incoming serial data to a terminal and save that to a text file, then send that file to the phone, although I'm not sure how to do that continuously and automatically or details such as overwriting each time or overwriting after the file reaches a certain size, etc.

Also I'm not sure on how to start sending that data over Wi-Fi to an iPhone on a local network using the laptop's Wi-Fi either.

Any suggestions or pointers in the right direction would be greatly appreciated. Thanks!


texts:
I used this simple code to understand the basics of serial communication. This achieves simple communication between the computer and arduino:
String receive_buffer;
void setup() {
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()>0)  //check for any data received
  {
      receive_buffer = Serial.readString();  //read received data
      Serial.print("received data is: ");
      Serial.println(receive_buffer);        //display received data
  }

}

This works. Now, my next idea was to try communicating between two arduinos. I used this code for the reciever arduino.
The sender arduino contains a motor fitted with an encoder, and using the ppr value I  calculate the rpm of the motor. The code for rpm works perfectly. I now want to communicate this data to the receiver.
Wiring: (RX,TX) of sender connected to (TX,RX) of receiver, and GND is made common.
Now, on arduino.cc, it says that Serial.write() can have String as an input. So, I tried typecasting the rpm value (which was int), into a String, and then send that string to the receiver through Serial.write().
float ppr=512.0;
int encpin=3;
volatile long pulsecount=0;
float revs;
float rps;
int rpm;

extern volatile unsigned long timer0_millis;

void setup()
{
  pinMode(encpin,INPUT_PULLUP);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(encpin),function,RISING);
                                        //when pulse is detected
                                           //interrupt triggered,
                                           //function callled
}
//increments pulse by one
void function(){
  pulsecount+=1;
}

void loop()
{
 revs= pulsecount/ppr ;
 if(millis()>=1000)
  {
    rps= revs;
    rpm=rps*60;
    pulsecount=0; //resets pulsecount

    String strrpm= (String)rpm;

    //Serial.println(rpm);
    Serial.write(strrpm);

   // Serial.println("string rpm");
    //Serial.println(strrpm);

    noInterrupts ();  //resests millis() to 0
    timer0_millis = 0;
    interrupts ();
  }
}

However, I get an error:
43:24: error: no matching function for call to 'HardwareSerial::write(String&)'

The issue is not with typecasting. I tried to simply print strrpm and it worked fine. When tried Serial.write() with a different and simple string, i.e Serial.write("abcdef"); , it still gave the same error.
How then should I should I send my strrpm (string rpm) value to the receiver?


texts: Measuring power consumption on Arduino off of DC supply

texts:
I am working on a project involving the Uno, and I would like to benchmark the power requirements of Arduino. I am using the external 9V supply option.

Specifically, the Uno will be in to states,power-intensive and power-save. In the first mode, I am doing some heavy processing tasks (RF and some sensors are the only external loads), and the Arduino typically runs loop() without any delays. In the second mode, loop() is execued about every 10-40 seconds.

I am interested in benchmarking how much power is consumed in both states (I need this to estimate the size of the battery required for the 9V supply).

Obviously, googling yielded me solutions that involved measuring current using chips in series with the supply (I probably can pull this off with a multimeter). What I am wondering is whether there exists an elegant solution for this, with (highly) accurate results (I would most likely quote the power values, so accuracy is a must for me)? Something I can dynamically measure on the Uno itself?


texts: How to encode resistance change (reed) for Arduino?

texts:
I have a water counter which switches reed on each 10 liters of water. I would like to count these values with Arduino.

I wrote a program which counts changes from analog input and connected counter between +5V and analog input. It counts well but I am doubt I connected correctly. Because when reed is opened, then analog input is connected to nothing, while it should be connected to GND.

How to implement correct conversion from reed to analog or digital input?


texts:
So I'm working on my car and now I've got my sights on the electrical system. I've installed a keyless entry system and a pulse timer for the dome light. Now, I'd like to give the dome light the fade effect all the modern cars have. After looking around, it seems an Arduino would be the most reliable.

I currently own an board similar to the Arduino Nano, specifically the SainSmart Nano. So I've determined that I'd power the board with a constant 12V, use pin 7 as input, and use pin 9 as output.

My code:

int domeLightIn = 7;
int domeLightOut = 9;
int brightness = 0;
int fadeAmount = 5;

void setup() {
  pinMode(domeLightOut, OUTPUT);
  pinMode(domeLightIn, INPUT);
  digitalRead(domeLightIn);

}

void loop() {
  // Case 1: State of Door: Open/Closed
  // Case 2: State of Switch: On/Off
  // Case 3: State of KES: Active/Inactive

  //Case 1: If door is closed and led is off, brightness remains 0;
  //Case 2: If switch is off and led is off, brightness remains 0;
  //Case 3: If KES is inactive and led is off, brightness remains 0;
  if (digitalRead(domeLightIn) == LOW && brightness != 255){
    brightness = 0;
  }

  //Case 1: If door is open and led is off, brightness will fade in;
  //Case 2: If switch is on and led is off, brightness will fade in;
  //Case 3: If KES is active and led is off, brightness will fade in;
  if (digitalRead(domeLightIn) == HIGH && brightness != 255) {
    for (brightness = 0; brightness < 255; brightness = brightness + fadeAmount) {
      analogWrite(domeLightOut, brightness);
      delay(35);
    }
  }

  //Case 1: If door is closed and led is on, brightness will fade out;
  //Case 2: If switch is off and led is on, brightness will fade out;
  //Case 3: If KES is inactive and led is on, brightness will fade out;
  if (digitalRead(domeLightIn) == LOW && brightness == 255) {
    for (brightness = 255; brightness > 0; brightness = brightness - fadeAmount) {
      analogWrite(domeLightOut, brightness);
      delay (35);
    }
  }
}

I am unsure whether I am using digitalRead() correctly along with wiring the input. So, am I doing this right? or perhaps there is a better way?


texts: How to extract the last byte out of an IP adress

texts:
Newbie question:

I need to pass the last byte of a local IP as a parameter.
Eg.: when Ethernet.localIP() returns 192.168.0.100,
I need to extract the 100 and put it in a char array or string.

Anyone any ideas? Thx!


texts: How to input keyboard commands using Arduino Mega 2560?

texts:
I have an Arduino Mega 2560 connected to a Windows 8 laptop. I want to program it to send keystrokes to the attached computer (when a pin's digital read goes from HIGH to LOW.)

The trouble is, I cannot find any way to program my Arduino Mega to send keystrokes.

The supposedly "core" Keyboard and Mouse libraries only support 32u4 boards, and other libraries that give the Arduino keystroke functionality are out of sight. When I googled the issue, I found no question or explanation of how to send keystrokes on the Arduino Mega. When I searched further, I thought the V-USB library would be a potential workaround, but the library throws numerous errors when imported into an Arduino sketch (even on the 1.0.0 IDE it was designed for.)

After hours of searching, two final workarounds seem to have popped up:

Some method to run a Python code to send keystrokes to the PC, and then connect the Arduino code to Python. (I don't know Python...)
Use some program called Gobetwino, which runs between the Arduino and PC, to   convert Serial commands into keystrokes somehow. (Pressing and releasing a key can't be simulated very well by repeatedly sending Serial commands, I think.)

Both are very unideal, very tedious, and are equally likely to just not work. I have spent hours on this.

Does anyone have any suggestions to get me out of this hell? Libraries, workarounds, anything?

(Feel free to PM me questions for clarification.)


texts: SIM900 AT command HTTP GET request not show the web page

texts:
I build a simple HTTP GET request by SIM900. Here is it:

-----1-----
AT+CSQ

+CSQ: 25,0

OK

-----2-----
AT+CGATT?

+CGATT: 1

OK

-----3-----
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK

-----4-----
AT+SAPBR=3,1,"APN","indosatgprs"

OK

-----5-----
AT+SAPBR=1,1

OK

-----6-----
AT+HTTPINIT

ERROR

-----6.1-----
AT+HTTPPARA="CID",1

OK

-----7-----
AT+HTTPPARA="URL","http://www.minimalsites.com"

OK

-----8-----
AT+HTTPACTION=0

OK

-----9-----
AT+HTTPREAD

OK

-----10-----
AT+HTTPTERM

ERROR

+HTTPACTION:0,200,1240

-----10.0-----
AT+SAPBR=0,1

OK

The step 9 AT+HTTPREAD I supposed to see some html from http://www.minimalsites.com. But i dont see anything, What wrong with me?


texts: How can I program a ATmega328 au tqfp32 ( SMD ) chip?

texts:
I have some experience with the Arduino UNO , Nano , mega etc .. But today I want to upgrade my skills and knowledge to next level . So I am about to design my own PCB for ATmega328 au ( SMD ) but this time I want to use a tqfp32 programmer to get the job done .. I have searched the internet and I have found that people use Universal programmers ( ISP ) such as Top2013 universal programmer or TL86ii but I have no idea how to use them and I don't even know what  software that the youtubers are using ... They are actually uploading some *.hex files it seems I am not sure but they aren't using Arduino IDE . According to my knowledge they are using a tqfp32 to dip28 programming module ( I have attached a pic ) . And then the Module is mounted on top of the ISP . Then they have uploaded code using some unknown software. And few people are using USBasp , can any explain me the scenario and what they have done ..  https://youtu.be/GFyr9tVEHzQ
The link is a reference video .


texts: What are the different types of high-speed serial data transfer protocols, and how do they work (ex: baudrate, synchronous vs asynchronous, etc)?

texts:
Otherwise worded: How do I resolve my understanding about baud rates and high speed serial data transfer?

From what I understand, serial communication is relatively slow.  By slow, I mean that the fastest common rate of transmission of data is 115.2 kBaud.

However, also from what I understand there are fast ways of transferring data serially.  I know that some serial configurations through Firewire or Ethernet can transfer data at speeds that are orders of magnitude higher than 115.2 kBaud.  These data streams are able to be read on simple computers that you can buy from Staples.  I don't know how these systems receive data at such a high speed if common baud rates are so low.

I know something is wrong with my understanding of it all.  I am new to electrical engineering and I am trying to teach myself some basic ideas for my research project - with much frustration.  I know that I need to have a system that can receive a pulse train at a minimum speed of 10MHz (hopefully up to 500MHz).  I will then program it to process this data.  The system that I currently have to receive the data is an Arduino certified product:

http://store.arduino.cc/product/E000052

Programming in the Arduino language is not a problem, I already know how to do this.  I just want to understand what I can do to receive this data stream.  Do I need something faster than this?  Or will this suffice?  I'm more interested in the theory than the device; it is more valuable for me to bolster my education than for me to solve my problem (though it needs to be solved).


texts:
I'm new in Arduino stuck in String to a dynamic byte array.

My String:

String Finalval="6D616320747820636E662031352033300D0A";

Dynamic Byte array:

byte ft[]={0x6D,0x61,0x63,0x20,0x74,0x78,0x20,0x63,0x6E,0x66,0x20,0x31,0x35,0x20,0x33,0x30,0x0D,0x0A};


texts:
I have the following code working correctly except for the Index portion.
I am not sure if I have the syntax correct for the hardware.  The end result I am looking for is to have the encoder reset to 0 degrees every time the index comes around (360 degrees).
I am also looking for any comments on the code as I would like the encoder output to be as accurate and efficient as possible.

Here is the code:

// Wiring connections for my encoder:
// Brown : VCC = 5V
// Blue + Shield : 0V = GND
// Black : ENCODER0PINA, Pin 20
// White : ENCODER0PINB, Pin 17
// Orange : ENCODER0PINI, Pin 19

#define ENCODER0PINA         20      // this pin needs to support interrupts
#define ENCODER0PINB         17      // no interrupt required
#define ENCODER0PINI         19      // this pin needs to support interrupts
#define CLOCKWISE            1       // direction constant
#define COUNTER_CLOCKWISE    2       // direction constant

// variables modified by interrupt handler must be declared as volatile
volatile long encoder0Position = 0;
volatile long interruptsReceived = 0;
volatile byte INTFLAG1 = 0;

// track last position so we know whether it's worth printing new output
long previousPosition = 0;

void setup()
{

  // inputs
  pinMode(ENCODER0PINA, INPUT_PULLUP);
  pinMode(ENCODER0PINB, INPUT_PULLUP);
  pinMode(ENCODER0PINI, INPUT_PULLUP);

  // interrupts
  attachInterrupt(3, onInterrupt, RISING);
  attachInterrupt(4, onReset, CHANGE);

  // enable diagnostic output
  Serial.begin (9600);
  Serial.println("Ready.");
}

void loop()
{
  // only display position info if has changed
  if (encoder0Position != previousPosition )
  {
    Serial.println(encoder0Position, DEC);

    previousPosition = encoder0Position;
  }
}

// interrupt function needs to do as little as possible
void onInterrupt()
{
  // read both directional inputs
  int a = digitalRead(ENCODER0PINA);
  int b = digitalRead(ENCODER0PINB);

  if (a == b )
  {
    // b is leading a (counter-clockwise)
    encoder0Position--;
    if (encoder0Position < 0)
    {
      encoder0Position = (encoder0Position + 360);
    }
  }
  else
  {
    // a is leading b (clockwise)
    encoder0Position++;
    if (encoder0Position >= 360)
    {
      encoder0Position = (encoder0Position - 360);
    }
  }

void onReset()
{
  // read Index input
  int i = digitalRead(ENCODER0PINI);

  if (i = 1)
  {
  encoder0Position = 0;
  }
}


texts:
So, my plan is to be able to turn a motor, with a gear on the end, for a certain amount of gear teeth then stop it. I can’t find a data sheet for the motor but it is very fast, brushed and DC. I was thinking putting something like this below the gear so when a tooth goes past, it turns on and off. Like I said before the motor is very fast (faster then being able to see the teeth as it spins)  and I don’t think the arduino will be able to read that kind of speed with digital read, I may be wrong. Any suggestions would be appreciated. Thanks.

EDIT:
The motor runs off 2 cell or three cell lipo which is 7.4-11.1v, it’s maximum current is 20 amps.

Edit: For anyone wondering how to use the sensor, the datasheet is here and it shows the positions of the collector, emitter, anode and cathode.


texts: What happends if I turn on all LEDs at the same time in an 4 digit 7 segment display? that would be 32 LEDs turned on at once, wouldn't that exceed the 200ma MAX for the arduino output?


texts:
i'm study the Low-Power library to better undertand how it works.
In this part of code i have some question.

Sometime he uses commands like:

power_timer1_disable();
power_timer0_disable();

but in other part of code, example "TIMER2_OFF":

if (TCCR2B & CS22) clockSource |= (1 << CS22);
if (TCCR2B & CS21) clockSource |= (1 << CS21);
if (TCCR2B & CS20) clockSource |= (1 << CS20);

// Remove the clock source to shutdown Timer2
TCCR2B &= ~(1 << CS22);
TCCR2B &= ~(1 << CS21);
TCCR2B &= ~(1 << CS20);

power_timer2_disable();

he uses the register code and, in the end, the function.

Someone can explain to me why?


texts:
I recently got an Arduino starter kit from a friend that he wasn't using and this came with it but, i can't find anything about it, cause i don't know how to search for it.
Anyone can enlighten me what it is?


texts: Could a bluetooth, speaker and microphone equiped arduino be used to form a range sensing swarm?

texts:
I am trying to figure out how to build a system of devices that could, on command, notify similar devices that are within a configurable distance. Maximum ranges would need to be around 20' though up to 40' would be preferable. Accuracy +- 20% is acceptable as is degradation due to things such as large intervening objects, walls, buildings etc. Only one notification is expected in any given 10 second block.

I was thinking the sending device could send a ultrasonic ping, and then send a data packet with the ping time stamp and range notification to all devices in range. And then each receiver could compare the ping receive time and range notification and calculate if it is within the range given in the data packet.

Would this work? Is there a better way to do this?


texts: how to compile arduino sketch from termnial without using arduino ide

texts: I want to know how can I compile and upload the arduino sketch from my terminal instead of using Arduino IDE. I want to use a different IDE for writing code.


texts: How to I press a button once to display text and again to remove it?

texts:
My code is displaying voltage and I want to have a button that when pressed it displays a text and when I pressed it again it would turn off the text. I put the word "YES" just for a test

float vPow = 4.7;
float r1 = 1000000;
float r2 = 100000;
const int buttonPin = 8;
int buttonState = 0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  pinMode(buttonPin, INPUT);
  Serial.begin(100);
}

void loop() {
  float v = (analogRead(0) * vPow) / 1024.0;
  float v2 = (v / (r2 / (r1 + r2)))/.48;
  lcd.setCursor(0,0);
  lcd.print("V:");Serial.println(v2); lcd.print(v2); lcd.print("%");delay(100);
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    lcd.setCursor(0,1); lcd.print("YES");
  } else {
    lcd.setCursor(0,1); lcd.print("");
  }
}


texts:
When I tried to verify a simple “Hello world” program I get the following message:

class hardwareSerial has no member named printin.

What does it mean?


texts: Reasons why it is not OK to connect a relay directly from an Arduino digital pin

texts:
After looking into various schematics on controlling a relay via an Arduino, I have noticed that, most of the time, transistors are used to switch the separate supply into the relay coil rather than directly supplying the relay with the 5-Volt output from the I/O pin of the Arduino. For example, I have a 5-volt DPDT relay and also a small dc motor. I want to drive both directly from my Arduino UNO (SMD clone) with an Atmel328 processor? Would it be advisable to proceed?

If not (most likely):

Can someone give a detailed explanation and might as well important cautions on current limits and stuff?
How can one control such components without risking the Arduino? What are some common means to accomplish this?
What other devices can generally harm an Arduino board (or any microcontroller unit) in a similar manner?

I'm just a beginner who wants to be extremely cautious. Thanks.


texts: Serial.read(): Value changes to ASCII when I input from Serial Monitor

texts:
I was having some problems on a project, so to test my Arduino, I wrote the following program to check things. When I start the serial monitor, the value of i is 1, but after I start sending numbers, they change into ASCII. Why?

int i = 1;
void setup(){
  Serial.begin(9600);
}
void loop(){
  Serial.println(i);
  if(Serial.available()){
    i = Serial.read();
  }
}


texts: Help choosing an ESC for a 500W/60V motor

texts:
I have a 3 phase (3 wires) unicycle motor - 500W, 60V and a battery 50 - 60V (if I understand correctly - 16 cells x 3.7 V), 2.9 Ah.

I want to control this motor with Arduino PWM pin.

I understand, that I need an ESC to do that, but with what kind of specs? How can I know what voltage and amps should I look for? Maybe someone could explain this to me and also give some URL's to real ESC's.

Thanks.


texts:
Hey guys i have made an automatic plant watering system. Its really basic. the code is:-

char yo = 0;
void setup() {
  pinMode(2, INPUT);//moisture sensor
  pinMode(3, OUTPUT);// pump
  Serial.begin(9600);
}

void loop() {
  yo = digitalRead(2);
  if(yo == 1){
      digitalWrite(3,HIGH);
      Serial.println("Plant is Being Watered as the soil is dry");
      delay(5000);
    }
  else{
      digitalWrite(3,LOW);
      delay(5000);
      Serial.println("the plant has sufficient water");
    }
}

The thing that i want to add is.. i want to add a feature which can manually control it with bluetooth but the normal program should also be running. for eg. soil is wet but i want to add more water so i write 9 on the blueterm app which starts the pump for 2 seconds. I am using an HC-05 bluetooth module. can someone tell me how this can work on an arduino?

EDIT!

Sketch 2:

char ha;
void setup() {
  pinMode(3, OUTPUT); //pump
  Serial.begin(9600);
}

void loop() {
 ha = Serial.read();
 if(ha == 5){
    digitalWrite(3, HIGH);
    delay(2000);
  }
 else{
    digitalWrite(3,LOW);
  }
}


texts: Cannot communicate with Serial Monitor - Arduino Yun

texts:
I connect Arduino Yun to my Computer with WiFi. I was able to get the IP address of my Arduino Yun. However, when I try to print something. It seems to not work at all. The following code is the one that I try:

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

void loop() {
 // print labels
 Serial.print("NO FORMAT");
 delay(100);
}

I did not get any kind of error. However, when I open the Serial Monitor, it shows nothing at all. I try to use the same code with Arduino Uno. It works fine.


texts: Arduino LED lighting up when signal is reading low on multimeter

texts:
My code is designed to play a tone when ever pin 3 is high on my Arduino. When I am examine the pins voltage with a multimeter it is always reading below 1 volt. When I examined the voltage off of a osiliscope it is reading the voltage pretty steady at 0.2 to 0.3.

My multimeter reads at 0.26

:

My code is:

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
int input = digitalRead(3);
Serial.println(input);
if(input == 1){
  tone(A5,4000);
  }
}

My board looks like:

The bottom of the board looks like:


texts:
I am trying to turn on LEDs one after the other so that I can start at one end and slowly turn the LEDs until it reaches the middle of the strip. The code works coming from the end of the LED strip, but not when coming from the start of the strip. From the start of the strip, it just turns on all the LEDs up until the midpoint.

int midpoint = 30;
int R = 255;
int G = 0;
int B = 0;
for(int j = 0; j<midpoint; j++){
     //starting from the end, filling towards the middle
        for(int k = NUM_LEDS-j; k < NUM_LEDS; k++){
           leds[k] = CRGB (R, G, B);
        }
//there's some other code here in the interim
FastLED.show();
delay(20);
     //starting from the beginning, filling towards the middle
     //this is the section of code that doesn't work correctly
        for(int l = j - 1; l < midpoint; l++){
           leds[l] = CRGB (R, G, B);
           }
//more interim code
FastLED.show();
delay(20);
}


texts: Are (how much are) interupts interfering I2C or SPI communication?

texts:
I am thinking over an autonomous rover.

One of the features/components of the rover will be ability to know how fast is the rover moving and what distance did it travel. I would like to use dedicated attiny85 chip for that. The chip will use rotary encoder and interrupts to detect motion. It will be connected throught I2C/SPI (do not know yet) with the main controller. Main controller will ask the attiny85 on speed and distance if needed.

The problem is, I guess, that rotary encoder will use interrupts and so the I2C or SPI may not work properly. I could disable interrupts while communicating but:

Motion sensing won't be precise, as I will loose some motion data.
When attiny85 will be on receiving side, it wont know soon enough that it should disable the interrupts.
There is a chance that SPI/I2C uses the interrupts as well, not sure, have to check.

Am I right? What would you advise?


texts: AVR USB based device detection problem after switching from RPI3 raspbian stretch to buster

texts:
I have a device constructed from a Raspberry Pi 3 B and an AVR based USB device. The interconnection of these components is depicted in this picture.

When RPI is on, data lines of keyboard will be connected to the USB port of RPI. When RPI is off and a USB cable from PC is connected to the device, then data lines of the USB keyboard will be connected to that USB port.
The problem is that when using Raspbian Buster, the OS doesn't detect the USB keyboard at all. It isn't listed in dmesg logs nor in lsusb output. I know that maybe this is not the standard interconnection, but I can not change the hardware. And more importantly, this setup works great with Raspbian Stretch.
So, although this detection problem may be caused by the connection architecture, but there must be a software solution because as I mentioned, the USB keyboard is detected and working when the OS of RPI is Raspbian Stretch.
I think the problem lies in the RPI firmware changes that happened from Stretch to Buster, but downgrading firmware using rpi-update didn't help.
What can I do to make the Buster firmware detect this USB keyboard as Stretch does? As I mentioned, downgrading the Buster firmware/kernel from 4.19.57-v7+ to 4.9.35-v7+ (the firmware/kernel version of the working stretch release that I have) didn't help.
If it matters, the USB keyboard is an AVR based CDC device.


texts:
I’ve bought a RF transmitter and receiver on eBay and I’m trying to get my garage door codes with my Wemos D1 Mini.

I’ve downloaded the RCSwitch library, hooked up the receiver to ground, 5v and data to pin D4.  Also flashed the sample receiver sketch.

The problem is that I don’t get anything on serial monitor... the Wemos board has an inbuilt led that flashes when I press my garage remote buttons, which means that pin DATA is sending a signal to the board, but I can’t see anything on serial monitor (Baud rates and serial connectivity is all good).

Tried other pins and didn’t get anything different.

Does anyone know how can I specify the pins with RCSwitch or have and idea of what is going on?

UPDATE 1
I’ve certified that transmitter is working and hooked properly using the Radiohead library.

UPDATE 2
The remote I have is so cheap that it is barely impossible to determine which chip it uses:


texts: Blueduino Rev2 service UUID for web bluetooth

texts:
I have a Blueduino Rev2 board that I would like to have communicating with a web app (running the chrome bluetooth software) but I'm having trouble sorting out the service UUIDs that the web bluetooth library requires.

According to the wiki, it uses the service UUID 0xFFF0, write characteristic UUID 0xFFF1 and read characteristic UUID 0xFFF2 (source) but when I scan for the device through the web app filtering for that service UUID it doesn't appear, but does when I remove the service UUID filter.

Code used to scan for the blueduino:

navigator.bluetooth.requestDevice({
    filters: [{
        name: 'ZeroBeacon',
        services: [0xFFF0]
    }]
})

Does anyone know what the UUIDs are that I should be using? The documentation is quite unclear and lacking.


texts: Water pressure an salinity sensor connected to arduino

texts:
I am trying to design a project that Arduino would have connected water and salinity sensor, would be packed in a special box be droped into ocean up to 500 meters. What sensors should I use and how should they be conencted. I assume that I would need professional equipment, not chineese stuff from ebay.
Hardware needs to be able to work under 50*C and up to 50bar

Update:

Budget is about up to 400 pounds for sensors.
Resolution of pressure 0 to 100 bar
Resolution of salinity doesnt matter so much. Few percents of mistake, just to measure it somehow


texts: Arduino - Raspberry Pi serial communication

texts:
I need to connect a Raspberry Pi and an Arduino Uno through serial communication and decided to follow this guide, which mentions the use of a voltage divider.

I understand the connection to the Raspberry Pi GPIO requires 3.3V but I also plan to power the Raspberry Pi from the Ardunio's 5v output pin.

What's the safest approach to achieve this and the recommended current? Thanks.


texts: Run motor for a set amount of depending of Pressure Sensor

texts:
I'm a noob when it comes to time-based coding.

I have a pressure sensor which shows me readings for when someone is sitting on a chair.

I want to turn a motor for 2 seconds when the pressure sensor says occupied
I want to turn the motor the other way for 2 seconds when the pressure sensor says empty.

Also after the motor has turned for 2 seconds, I don't want it to turn the motor at all until the reading of the pressure has changed to the other reading.

Here is my code.

#include <AFMotor.h>
AF_DCMotor motor(1,MOTOR12_64KHZ);
AF_DCMotor motor2(2,MOTOR12_64KHZ);
int fsrPin = 0;     //FSR and 10K resistor are connected to pin 0
int fsrReading;     //the analog reading from the resistor divider

bool WheelLock = true;  //controls whether the wheelchair is locked or not
long startTime = millis();
long stopTime = startTime;

void setup(void){
  Serial.begin(9600);
  motor.setSpeed(255);
  startTime = 0;
  stopTime = 5000;
}

void loop(){
  while(startTime < stopTime){
    if(onChair() == false){
      motor.run(BACKWARD);
      startTime = millis();
    }
    else{
      motor.run(FORWARD);
      startTime = millis();
    }
  }
  motor.run(RELEASE);
  Serial.println("RELEASED");
  startTime = 0;
  Serial.println(startTime);
}

bool onChair(){
  fsrReading = analogRead(fsrPin);

  if(fsrReading > 800){
    Serial.println("Wheelchair is occupied");
    WheelLock = false;
  }

  else{
    Serial.println("Wheelchair is empty");
    WheelLock = true;
  }
  delay(200);
  return WheelLock;
}


texts: What I should be aware before I touch my Arduino?

texts:
Before you start to mess with a computer there are basic guidelines to be aware of, such as turn the power off and watch out for static electricity. What guidelines should I be aware of when I work with an Arduino board if I don't want to harm neither myself nor the board. The three kind of activity that requires touching the Arduino and what I'm asking about:

Setting up wire, component layout or breadboard.
Debugging a running setup.
Moving, mounting up the board somewhere.


texts: How to implement a tilt compensated compass?

texts:
So i was trying to implement a tilt compensated compass, using HMC5883L and MPU6050. The problem i am facing is, there are 2 equations for tilt compensation
Tilt Compensated X:   X,Y,Z are compass output (raw output)
new_X =  X*cos(pitch) + Y*sin(roll)*sin(pitch) – Z*cos(roll)*sin(pitch)
Tilt Compensated Y:
new Y =  Y*cos(roll) + Z*sin(roll)
Final Heading :
Azimuth =  atan2(Y, X) * RAD_TO_DEG
The angles which i am getting from the mpu are gyro-drift corrected angles which are coming through a kalman filter. Those angles are fed to these above equations and after atan2 i get the tilt compensated heading. But the issue/observation here is, when i rotate the body(on which the compass and mpu are) along the Z axis (YAW axis) the heading doesn't change(sort of locked on), but changes when i tilt the body in X/Y.
I searched for thorough references, but wasn't able to find any!
Here is my code snippet (uses compass part form adafruit library):
double HEADING(double r, double p){
  sensors_event_t event;
  mag.getEvent(&event);
  r = r * (PI/180);
  p = p * (PI/180);
  double x = (event.magnetic.x)*cos(p) + (event.magnetic.y)*sin(r)*sin(p) - (event.magnetic.z)*cos(r)*sin(p);
  double y = (event.magnetic.y)*cos(r) + (event.magnetic.z)*sin(r);

  float heading = atan2(y,x);

  float declinationAngle = 0.366667 * (PI/180);// (0°22')positve declination
  heading += declinationAngle;

  if(heading < 0)
    heading += 2*PI;

  if(heading > 2*PI)
    heading -= 2*PI;

  heading = heading * 180/PI;

  return heading;
}

The HMC5883L data acquisition I wrote :
// i just need a direction reference not actual heading, just to keep my drone
// steady on yaw axis with reference to that direction reference but it shall be Tilt compensated
#include<Wire.h>

#define MAG 0x1E

#define R 0
#define P 1
#define Y 2

float mag_raw[3],h;
float CMP_DEC = 0.36667 * (PI/180);

void setup(){
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(400000);

  Wire.beginTransmission(MAG);
  Wire.write(0x02);
  Wire.write(0x00);
  Wire.endTransmission(true);

}

void loop(){
  Wire.beginTransmission(MAG);
  Wire.write(0x03);
  Wire.endTransmission(false);
  Wire.requestFrom(MAG,6,true);

  mag_raw[R] = Wire.read() << 8 | Wire.read();
  mag_raw[P] = Wire.read() << 8 | Wire.read();
  mag_raw[Y] = Wire.read() << 8 | Wire.read();

  h = atan2(mag_raw[P],mag_raw[R]);

//  h += CMP_DEC;

  if(h < 0) h+= (2*PI);
  if(h > (2*PI)) h -= (2*PI);
  h *= (180/PI);

//  Serial.print("X : ");
//  Serial.print(mag_raw[R]);
//  Serial.print(" Y : ");
//  Serial.print(mag_raw[P]);
//  Serial.print(" Z : ");
//  Serial.print(mag_raw[Y]);

  Serial.print(" H : ");
  Serial.println(h);

}

Some guidance will be very helpful!


texts:
I want to create a 30 minutes delay in my program (Arduino).

which is better millis() or timer for this purpose?

please give me an example to clarify my doubt ...

Thanks.


texts: How to program Arduino LCD shield with Python?

texts:
so I want to run a Arduino LCD shield with Python code..But after having some research on the Internet, I can not found any tutorial, some just give some basic code with LED.

And one things that how can I add a LCD library (LyquidCrystal.h in Arduino code) if i program in Python.

Thank you guys very much.


texts:
I would like to write a class which utilises another class and it´s member functions. I found out that this is object composition and read some examples of how to do it but it ither doesn´t work for me or I just don´t understand it completely. Here are parts of my code.
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>     // Touch library
#include <TriangleButton.h>        // TriangleButton library

I want to use an Adafruit_TFTLCD object and its member functions inside my own class TriangleButton. The object tft is initialised before setup.
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Class is part of SPFD5408_Adafruit_TFTLCD.h

I built the TriangleButton.h similar to this thread (Use object of other class within class) and used a reference to the tft object.
/*
  TriangleButton.h - Library for for constructing and reading triangle Buttons.
*/
#ifndef TriangleButton_h
#define TriangleButton_h

#include "Arduino.h"
#include <SPFD5408_Adafruit_TFTLCD.h>

class TriangleButton
{
  public:

    TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color) : _tft(tft){}
    boolean IsTriggered();
    void dash();
  private:

    Adafruit_TFTLCD &_tft;
    int16_t _coordX;
    int16_t _coordY;
    int16_t _orientation;
    int16_t _size;
    int16_t _color;
    int16_t _ru;
    int16_t _hc;
};

#endif

In the ccp. i put a coresponding constructor.
TriangleButton::TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color)
:
_tft(tft)

Now i get the following error message:
C:\Users\Erik\Documents\Arduino\libraries\AquariumController_Library\TriangleButton.cpp:19:1: error: redefinition of 'TriangleButton::TriangleButton(Adafruit_TFTLCD&, int16_t, int16_t, int16_t, uint16_t, uint16_t)'
TriangleButton::TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color)
^~~~~~~~~~~~~~
In file included from C:\Users\Erik\Documents\Arduino\libraries\AquariumController_Library\TriangleButton.cpp:7:0:
C:\Users\Erik\Documents\Arduino\libraries\AquariumController_Library\TriangleButton.h:14:5: note: 'TriangleButton::TriangleButton(Adafruit_TFTLCD&, int16_t, int16_t, int16_t, uint16_t, uint16_t)' previously defined here
TriangleButton(Adafruit_TFTLCD &tft, int16_t coordX, int16_t coordY, int16_t orientation, uint16_t size, uint16_t color) : _tft(tft){}
^~~~~~~~~~~~~~
exit status 1
I don`t understand why ther is a redefinition. Can somebody explain it to me?


texts:
First excuse me if tags are not reflecting the content,

While watching a video about single board computer (SBC) I got confused that it doesn't mention arduino as SBC. I always considered it as SBC.

After digging around a bit I got more confused. It seems single board computer is where processor, memory, I/O this things are built on single circuit board rather than using expansion card attached on to a circuit board (motherboard).
According to that is not arduino a SBC? It's processor, memory,storage are on single ATMega32A (for uno) attached on a single board which provides some I/O port (I/O pin, USB, UART, I2C etc.).

From some digging I learned that arduino code runs on bare metal unlike SBC like Rpi and that's the reason for it not being SBC. This seems weird reason.

(1) Is Arduino a SBC?
If (1) is no then next questions are,

(2) Is Being less powerful is the cause? If yes where do you draw the line?

(3) Not having an OS hosted environment for execution is the cause?

If (3) is Yes then,

(4) Arduino has some bootloader code to load the program through USB. Isn't it  kinda like OS, I admit it's not giving some nice api for h/w usage but is it all?

This link comment section kind of started a debate but ended without giving clear answer about my question.


texts: how do you capture the top value in a fallen edge in analogs data (flex sensor)

texts:
Guys i'm working with a flex sensor and I'm trying to capture a specific value which is the moment before the user lets go of a flexed flex sensor and its represented as the top point of a falling edge as sub picture A in the picture I included. using an array I tried two methods, which can produce a close value at times but at other it will give me wrong values
first I tried the following logic, whenever I detect a value below a certain threshold it indicates that a fallen edge has occurred so get me the value that came right before it as shown in sub picture C but depending on the delay this can be quite unpredictable.

the second method is to store the maximum value of but this returns the peak and it's not always the top of the fallen edge as shown in subpicture B

what do you guys suggest to capture those values?
this is my code so far

bool loaded = false;
int threshold = 760;
int index = 0 ;
int _max=0;
int values[4];
int values_size = 4;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int data = analogRead(A0);

  if (loaded) {
    values[index] = data;
    if(data>_max){
      _max=data;
      }

    if (data < threshold) {
      loaded = false;
      Serial.flush();
      Serial.print('a');
      Serial.print(',');
      Serial.print(_max);
      Serial.println();
      _max=0;
      delay(300);
    }
    index++;
    index %= values_size;
  }
  else if ( data > threshold && !loaded) {

    loaded = true;
  }

  delay(20);

}


texts: Help with app controlled Arduino sensors

texts:
(I'm a beginner in using Arduino and MIT App Inventor)
We have this project (an app-controlled aquaponics system) where our group decided to use an app to control the arduino sensors and then show the results in the app. The problem is most tutorials focus only on Bluetooth, how can I do this using WiFi and Temboo? And where can I get the .aix files for pH sensor, water level sensor, and soil moisture sensor?
Below are pictures of the progress I made:


texts: Is there an Arduino library that uses ARP to get list of connected devices on network?

texts:
I have been looking for a library that can execute an ARP (Address Resolution Protocol) command to return a list of connected devices on the network. The idea is that it would send the request to the gateway and get a list of MAC addresses of currently connected devices as a sort of "who's home" request.

I have searched around Arduino's libraries and have not found any that specifically perform this type of functionality so I was hoping that maybe it was available in a function within a broader networking library.

The particular networking interface (wifi via ESP8266/ESP32 or Ethernet) does not matter as I have not chosen a specific board for the job yet. I'm interested in any library solution that would allow me to poll the gateway to see which devices are currently online without having to buy a special device like FingBox.

Any recommendations for a library that includes this functionality or an approach that would allow me to send ARP commands over the network?


texts: Stopping Serial on RX/TX pins while running Serial on USB

texts:
The Arduino/Genuino Micro has RX/TX pins and can do serial via USB.

But, Arduinos Serial ties them both together, so when using Serial.begin(9600) to send messages between my PC and the Arduino, I cannot use the RX/TX pins as GPIOs.

From what I can tell reading the Atmega32u4s Datasheet, the USART module on the chip is completely separate from the USB controller, so it should be possible to somehow disable the USART Transceiver and Receiver after executing Serial.begin(9600).

Is there something fundamental preventing me from doing this or can it be done? If it can, how would I do it?


texts: Connecting a switch and a MOSFET to an Arduino?

texts:
I have an LED strip that I am trying to turn on with a magnetic switch when a door opens. I want the LEDs to fade on when I open the door and fade off when I close it, which is where the Arduino comes in. I am using PWM for the fading. I can get each component to work separately. The fading LEDs work with the MOSFET without the switch. I tested the switch with serial output on the Arduino and it works fading a single LED without the MOSFET.

I am using:

Arduino Uno R3
Magnetic Switch
N-Channel MOSFET IRLB3034
5 Meter White LED Strip
12VDC 30W Power Supply
10k Ohm Resistors

My setup looks like this:

Schematic:

Code (if it helps):

const int buttonPin = 2;     // the number of the switch pin
const int ledPin =  9;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the switch status
int brightness = 0;
int fadeAmount = 5;

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop(){
  // read the state of the switch value:
  buttonState = digitalRead(buttonPin);

  // check if the switch is ON.
  // if it is, the buttonState is LOW:
  if (buttonState == LOW) {
    // fade LED on:
    analogWrite(ledPin, brightness);
    if (brightness < 255) {
      brightness = brightness + fadeAmount;
    }
  }
  else {
    // fade LED off:
    analogWrite(ledPin, brightness);
    if (brightness > 0) {
      brightness = brightness - fadeAmount;
    }
  }
  delay(30);
}

I have a feeling the problem is with the common ground on the MOSFET and the switch. Any solutions/suggestions are appreciated.


texts: Detecting a finger snap(basically trying to replicate infinity gauntlet)

texts:
I am trying to make an infinity gauntlet. So it's obvious it should have a snap feature(which will switch of a light,motor or whatever). But I don't know how to go about sense this snap. I thought of two ideas: one detecting the snap sound but since I will be wearing a glove it can't be heard loudly, second is, trying to detect the pressure between thumb and middle finger and calculating velocity of middle finger during the snap. And I even found EMG sensor can be used but it's too costly so suggest me best way possible with proper explanation

P.S: This is my first ever Arduino project


texts: Arduino ATmega 2560 frequency measurement

texts:
I would like to measure frequency with an Arduino 2560 board. The approach is to use a timer interrupt set to one second and pin interrupt to count interrupts in one second.

The problem I have is that I get the wrong frequency. On my frequency generator I set up a frequency of 1000 Hz in my program I get 1006 Hz instead of 1000 Hz.

What am I doing wrong?

Here is my program. In the stup method I have declared a timer. When the signal comes on pin 2, the counter is increased by 1. After one second passed the flag bData is raised. If the flag is true then I print out a frequency on serial port.

#include <SPI.h>
#include <Ethernet.h>
#include <Math.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177);
EthernetServer server(80);
const byte interruptPinTemp = 2;
const byte interruptPinSlanost = 3;
//konstante za SBE-3
const double g = 4.85442486e-003;
const double h = 6.77300393e-004;
const double i = 2.65502731e-005;
const double j = 2.06782794e-006;
const double f = 1000.0;
volatile int cnt = 0;
volatile int cnt1 = 0;
volatile double slanost = 0;
volatile double slanost1 = 0;
int timer1_counter;
boolean bData = false;
volatile int dvesek = 1;

void beriTemperatura() {
  cnt++;
}

void beriSlanost() {
  slanost++;
}

double calcTemp(double frekvenca) {
  double logRes = log(f / frekvenca);
  return 1.0 / (g + (h * logRes) + (i * pow(logRes, 2.0)) + (j * pow(logRes, 3.0))) - 273.15;
}

void setup() {
  Serial.begin(9600);       // inicializacija serijskega porta
  noInterrupts();           // disable all interrupts
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  pinMode(interruptPinTemp, INPUT_PULLUP);
  pinMode(interruptPinSlanost, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPinTemp), beriTemperatura, CHANGE);
  attachInterrupt(digitalPinToInterrupt(interruptPinSlanost), beriSlanost, CHANGE);
  TCCR1A = 0;
  TCCR1B = 0;
  timer1_counter = 34286;   // preload timer 65536-16MHz/256/2Hz
  TCNT1 = timer1_counter;   // preload timer
  TCCR1B |= (1 << CS12);    // 256 prescaler
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();
}

//Timer interrupt na 1 sekundo
ISR(TIMER1_OVF_vect) {
  // interrupt service routine
  TCNT1 = timer1_counter;   // preload timer
  cnt1 = cnt ;               // prepisemo vrednost v cnt1
  bData = true;             // postavimo flag
  cnt = 0;  // resetiramo counter
}

void loop() {
  // če je postavljen flag, da so podatki jih izpišemo ali naredimo karkoli drugega
  if (bData == true) {
    bData = false;
    Serial.println(calcTemp(cnt1), 3);
    Serial.println(cnt1);
  }
}

Here is the frequency from my generator:

And here is a frequency measured with my board:

What is wrong that I get 1006 Hz instead of 1000 Hz?

If I raise the frequency for example to 5 kHz then I get 5032 Hz in my program (32 Hz to0 much).

Thank you for any advice.


texts:
I have faced an issue where the shock sensor is not running in the file. My idea is that when the ultrasonic sensor sense that when it is 4cm, the garage door will open. When the car reverses, the obstacle avoidance sensor will check if there is obstacle behind. These two sensors are working fine.

After that, shock sensor will be activated to see if the car has hit the wall.
But from shock sensor part onwards, the shock sensor does not run. I troubleshoot by putting the shock sensor code into another sketch and it works.

I have no idea where I have done wrong. I appreciate any help

Update
I have modified the code to accommadate interrupts which is advised by CodeGorilla. I need help with how can I let the interrupt know that they can execute when it reaches the if (distance == 4).

 #include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

const int trigPin = 9;
const int echoPin = 10;

long duration;
int distance;

const int shockPin = 3; // Use Pin 3 as Input

void setup() {

  Serial.begin(9600);

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Distance left:");

  // Ultrasonic Sensor
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // Obstacle Avoidance Sensor
  pinMode(8, INPUT);// set pin as input

  // Shock Sensor
  pinMode (shockPin, INPUT) ; // input from the KY-002

  attachInterrupt(digitalPinToInterrupt(3), detectShock, CHANGE);
  attachInterrupt(digitalPinToInterrupt(8), senseObstacle, CHANGE);
}

void detectShock ()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Detection: ");
  if (digitalRead(shockPin) == LOW) // If we're in an alarm state
  {
    lcd.setCursor(0, 1);
    lcd.print("Shock exists");
  }
  else
  {
    lcd.setCursor(0, 1);
    lcd.print("Shock is absent");
  }
}

void senseObstacle() {
  lcd.clear();
  lcd.setCursor(0, 0);
  //delay(300);
  lcd.print("Detection:");
  if (digitalRead(8) == LOW) {
    lcd.setCursor(0, 1);
    lcd.print("Obstacle Present");
  } else {
    lcd.setCursor(0, 1);
    lcd.print("No Obstacle");
  }

void loop() {

  // Clears the trigPin
  digitalWrite(trigPin , LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin , LOW);

  // Reads the echoPin, returns the sound wave
  // travel time in microseconds
  duration = pulseIn( echoPin , HIGH);

  distance = duration * 0.034 / 2;

  lcd.setCursor(0, 0);
  lcd.print("Distance left: ");

  lcd.setCursor(0, 1);
  lcd.print(distance);
  lcd.print(" CM");

  if (distance == 4) {
    // I am lost at here.
    lcd.setCursor(0, 1);
    lcd.print("Door Opens");
    delay(500);
    // Once the car enters, the obstacle avoidance sensor checks if there are obstacles in the way..
    delay(5000);
    lcd.clear();
  }

}

}


texts: Keep 5V on while sleep with LowPower library

texts:
Is it possible to keep the 5V on, while putting the Arduino (ATMEGA328P) in sleep more, using LowPower library?

I'm trying to use this HAT:

https://spellfoundry.com/product/sleepy-pi-2-usb-c/

to control the power of my Raspberry Pi. But on top of it, I want to have a second HAT that I want to feed 5V input, event after I shut down Raspberry Pi and put the Arduino to sleep.


texts: Arduino and RF24 library: communication stops after short amount of time

texts:
I am using two Arduino Unos, NRF24L01+ transceivers, and a few components as per this site on which I am following the second tutorial on this page: Arduino Wireless Communication – NRF24L01 Tutorial.

I am using the exact code from the page as well - and have set everything up as per the diagrams, however everything stops working after a short amount of time. Usually between 15 and 30 seconds, everything stays powered but it seems like the transceivers stop communicating. A reset of the Transmitting board (the one with the potentiometer) will fix the problem until it again stops 15 or 30 seconds later.

Any idea what might be going on?


texts:
I'm currently learning Arduino. So right now I'm trying to create an Arduino app that will use buttons, LEDs and RGB.

So I have 2 buttons, 8 LEDs and an RGB. The first button is the function switcher: when you press it the LED will light according to their function. The second button is the function activator so right now here's I want to do:

Function 1: Turn on/off RED light
Function 2: Increase RED light brightness by 5; if already at 255, reset at 0
Function 3: Turn on/off GREEN light
Function 4: Increase GREEN light brightness by 5; if already at 255, reset at 0
Function 5: Turn on/off BLUE light
Function 6: Increase BLUE light brightness by 5; if already at 255, reset at 0
Function 7: Turn on ALL lights, all brightness to 255
Function 8: Turn off ALL lights, all brightness to 0

I already started coding and I'm stuck at turning on and off the red light. Here's my code:

const int red = 5;

int b1, b2; //Buttons
int dir = 0;
int light = 11;
int func = 0;
boolean buttonValue = true;
boolean buttonState = true;

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(red, OUTPUT);
  for (int i = 11; i <= 18; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  b1 = digitalRead(2);
  if (b1 == HIGH) {
    dir = 2;
    func++;
    if (func >= 8)
      func = 0;
    } else {
      dir = 0;
    }
    digitalWrite(light, LOW);
    if (dir == 2 && light < 18) {
      light++;
    }
    digitalWrite(light, HIGH);
    delay(200);
  }

void function(int pin) {
  b2 = digitalRead(3);
  switch (func) {
    case 1:
      if (b2 = true) {
        digitalWrite(5, HIGH);
      } else {
        digitalWrite(5, LOW);
      }
  }
}


texts: What is the name of a peripheral which reads servo output data physically?

texts:
I know the title is phrased terribly, but I'm not sure how to phrase it since I'm not sure of the name.

I have a servo, that I cannot connect to, except for the output spine/shaft (physically).  I need to get the output of that servo into an arduino, or raspberry pi.  So I need some kind of peripheral that can attach to the shaft of the servo, and tell me what position it's in.  I can't figure out how to find what part I need, because I can't google for the name of it correctly.  I've tried servo input shaft, and many other things that don't make sense.

More Info.

I have a servo on a machine, and I can not interface with this servo in any way but physically.  I can't read the output from it electronically, and the signals are proprietary.  I can't take anything apart, all I can do is put something physically on it.

So, the issue is, I need to (based on nothing but the position of the servo shaft) figure out what position that 3rd party servo is at.

With that information, I'm then going to man in the middle, and attach another servo to my device, and change the value to what I want.

So if the factory servo is at 50%, and I know that by using something like a rotary encoder, if that ends up being the answer, I then could add x% to my actual servo.


texts: Power small hobby motor using Vin pin on Arduino and 9V battery, safe?

texts:
I want to power a small motor with a 9V battery and control it with PWM using an Arduino Leonardo. I know I can power the motor separately, but this introduces the problem of needing a battery to power the motor (9V battery) and another power source to power the Arduino (another 9V battery?)

Would it be safe to simply power the Arduino with a 9V battery and use the Vin pin on the board (which is unregulated and outputs directly the power source powering the Arduino) to drive the motor? That way, I power everything from the 9V battery, and use a transistor to drive the motor.

Thanks a lot!

Steve.


texts: I recently bought an ESP-WROOM-32 module and I want it to talk to my Pro Mini via I2C. Do I have to pull-up the lines to the 3.3v side (ESP32)? Since the Pro Mini runs at 5v, I think it's a bad idea to pull-up the lines from that side.


texts:
I'm trying to read in and parse a message in the form of X123987 continuously streaming into a serial port. There are no new lines or control characters other than the X which marks the beginning/end of the message. The message contains two, three-character components, ex: 123, and 987. I'm trying to copy bytes as their read into a char array, and then on the control character, return the result, but while this compiles, I don't get any output, and it crashes constantly.

#include <SoftwareSerial.h>

SoftwareSerial RS485Serial(10, 11);

char _byte_received;
char _buffer[10];
char _value[10];

bool OnReceive()
{
  if (RS485Serial.available())
   {
    digitalWrite(13, HIGH);
      _byte_received = RS485Serial.read();
      if (_byte_received == 'X') {
        strcpy(_value, _buffer);
        memset(_buffer, 0, 10);
        return true;
      } else {
        strcat(_buffer, _byte_received);
        return false;
      }
    digitalWrite(13, LOW);
   } else {
    return false;
   }
}
void setup() {
  Serial.begin(9600);
  Serial.println("Restarting...");
  pinMode(13, OUTPUT);
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  RS485Serial.begin(9600);
}

void loop()
{
  if (OnReceive())
  {
    Serial.print("value: ");
    Serial.write(_value);
    Serial.println("");
  }
}

Output:

Restarting...
value:
Restarting...
value:
Restarting...
value:
Restarting...
value:
Restarting...
value:

I expect to see value: 123987


texts: Arduino-compatible micro-controller with both I2C and CAN

texts:
I am looking for a controller that works with Arduino (i.e. there is official or third-party support for the controller in the Arduino IDE and core libs) and has both built-in CAN and I2C buses. I was looking at the ATMega automotive series (16M1, 32M1, 64M1, 32C1, 64C1) but it does not mention I2C/TWI in the datasheet at all.

(I know I can bitbang I2C, I know there is MCP2515 for CAN over SPI.)

Thanks!

EDIT: The application in mind is a bridge between a few I2C sensors and CAN, no complex logic. High performance is not necessary, plus it will drive costs upwards.


texts:
I have 2 Arduino Nano, they are connected via ports 2 and A2

While I use only one port to receive, it works properly. But if I activate the second port, system crash (and even first port don't work properly)

Code of first Arduino:

#include <SoftwareSerial.h>
SoftwareSerial SerialPort2(2,A2);
SoftwareSerial SerialPort3(3,A3);

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

void loop() {
  delay(500);
  SerialPort2.listen();
  if(SerialPort2.available()){
    char value = SerialPort2.read();
    Serial.print(value);
    Serial.print(" First port\n");
  }
  // IF YOU REMOVE PART BELLOW, THE 'SerialPort2' WILL WORK PROPERLY
  SerialPort3.listen();
  if(SerialPort3.available()){
    char value = SerialPort3.read();
    Serial.print(value);
    Serial.print(" Second port\n");
  }
  // END OF THIS PART
}

Code of second Arduino:

#include <SoftwareSerial.h>
SoftwareSerial SerialPort2(2,A2);

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

void loop() {
  SerialPort2.write('a');
  delay(1000);
}

PS in real system I need to listen 6 ports


texts: What happens if there is a runtime error?

texts: What happens if there is a runtime error in a program? Will execution of the program just stop? Is there some way I can get the Arduino to tell me what the error is?


texts:
I am a research scholar working on exploring the diffusion kinetics of metallic ions into substrate materials. To do so, I have to process 486 specimen combinations and it has been very difficult and practically impossible manually. Therefore I am attempting to automate my PG research using Arduino UNO.
To automate my reactor I estimate there would be 7 limit switches of lever type, 1 temperature sensor (K Type thermocouple), and 1 push button switch for start and stop. For the output, there would be 2 solenoids and 2 relays for stepper motors, and one relay for the alarm speaker. I would also like to log the temperature against time. Kindly suggest the feasibility of the automation using Arduino UNO. Kindly suggest other means for doing the same.
Thanks.


texts: No sketches will upload to Arduino Uno board; says "access denied"

texts:
I'm using an Arduino Uno board with an HP computer running Windows 10 and IDE version 1.6.8. Arduino was working fine for me until a few days ago, when (and I suspect this is the root of the problem) I accidentally tried to upload software with something connected to the RX and TX pins on the board. Now I continually get the error message below:

  avrdude: ser_open(): can't open device "\.\COM2": Access is denied.

The only other thing that changed is I disconnected a bluetooth dongle (Kinivo BTD-400 Bluetooth 4.0 USB Adapter for Windows) without uninstalling any software, so I suspect that software may be searching for open COM ports and disrupting the Arduino upload.

I've tried everything I could find about troubleshooting online, including that "did I brick my arduino" post elsewhere on this forum, and nothing has worked or even changed the problem - please help! I believe I've narrowed down the problem to my computer scanning open COM ports, but I can't find any reliable way to make sure that doesn't happen.

Thanks


texts:
I am playing with stepper motors and I need a precise square wave generator for f=29.710617283951Hz. I've done this on Raspberry Pi without any problems, but I need something smaller and with less power consumption.

Is it even possible to get that frequency?


texts: Can I use an AC signal to make an LED light up with arduino?

texts:
I want to use a 220VAC load as a signal and act as a switch to my arduino so Labview could interpret it as an LED ON state. I used a 4n33 octocoupler but it seems that the LED Simulation on labview keeps fluctuating. I think it's because of the negative half of the signal being blocked. Is there a way to fix this?

Here is my schematic


texts: Can't upload code to an Arduino LilyPad using FTDI

texts:
I've tried to upload my code to an Arduino LilyPad (328) using an FTDI basic breakout, but i get this:

avrdude: stk500_recv(): programmer is not responding

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

I tried to install the latest FTDI drivers from the FTDI website, tried another PC, tried to install the CDM-2.08.28 driver (latest I think) and nothing.

If I change the PC port the USB Serial Port doesn't change (is always COM3).


texts: Arduino program does not start when plugged in

texts:
I am having trouble with my Arduino Mega with getting the program to start when the Arduino is plugged into a computer via USB.  All that happens is the LED turns on and stays on.  The device does not initialize, and only when I press the reset button does it begin the setup.  How can I make the Arduino start the program when it is first plugged into the computer?

EDIT: my code

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

void loop() {
  Serial.println("test");
}

very simple, which is why i don't understand why this is happening


texts: Serial Write fails to send when Motors moving

texts:
I have an unusual bug with the code I have written for my rover V2 robot.

I have a raspberry pi running some computer vision code written in opencv tracking an object doing the heavy processing.

Once the object is detected, a command is sent via serial (USB) to make the robot move left, right, forwards etc.. The pi sends: w, a or d for the direction it wants the rover to move, it then turns off it's ability to send any further commands via a flag and will turn this back on when the rover sends a response confirming it has completed the command.

The idea is, eventually the rover v2 will be able to do some audio processing itself so it can turn and face the direction of a sound impulse but always prioritize any incoming serial data, sending the more accurate movement commands.

So my idea has been to implement an interrupt routine that is called upon receiving a command using the less than perfect approach suggested here.

So now for the weird part.. the code works entirely... until the motors have power!

If the Rover V2 motor power is entirely disabled the interrupt routine will work flawlessly. The Raspberry Pi will send a command and receive every reply from the Rover.

However, if the Rover V2 Motors are powered on, the Rover will receive all commands and send replies accordingly. The issue is for some reason, the Raspberry Pi will occasionally not receive a reply rendering the robot stationary as no more commands can be sent, this happens after varying periods of time all the way from 2 successful command interrupts to 100.

The fact that this occurs only when power is applied to the motors on the Arduino, is leading me to believe it is not a fault in the Pi code.

Why is it, that as soon as the power is applied to the motors there is inconsistency in the transmission of serial replies?

Does anybody have any suggestions on how I could further diagnose the cause of this fault?

Or is there any obvious issues in this code I have not seen?

Thanks in advance!

ohkneel

Code can be  viewed HERE


texts:
I am trying to get RSSI of a network without connecting to it directly but I get an error " error: cast from 'const char*' to 'uint8_t {aka unsigned char}' loses precision [-fpermissive]"

   char ssid[]="GreenNET";
    long rssi = 0;

    void updateRSSI(){
      rssi = WiFi.RSSI(ssid);
    }

I am following this: https://www.arduino.cc/en/Reference/WiFiRSSI except I am not passing password since it is not required WiFi.RSSI(wifiAccessPoint);


texts: Switch Control Between Two Different Techniques

texts:
I have implemented PID control of a generator governor to maintain a constant RPM using an Arduino Uno. It works pretty well, but there is a tradeoff between stabilty and response time. Using PID values that allow it to respond without oscillation is also about half as fast as the old mechanical governor.

I came up with a plan to use a CT to sense the AC amps and have the Uno rapid the throttle servo to a known value determined manually. Either using a lookup table or an interpolation algorithm, I haven't yet checked the linearity of the amps vs. throttle angle. The idea is to use a table (or interpolation) to get the governor close, and then let the PID fine tune it.

My hangup is that I'm not sure how to switch between lookup control and PID control as needed.

Pseudo-code:

analogRead(AMPS);
myservo.write(table_Val);
somehow_switch_to_PID;
myservo.write(PID_value);


texts:
I'm trying to have a user enter a series of strings. This is my code.

this is my error message - cannot convert 'String' to 'char*' in assignment

char* titles[] = {"entry one", "entry two", "entry three", "entry four", "entry five"};

void setup() {
 Serial.begin(9600);
 Serial.println("Storing numbers in an array");
}

void loop()

{

for (int x =0; x < 5; x++)
{
  if (Serial.available() > 0)

  {
   Serial.println("Enter a word... ");
   titles[x] = Serial.readString();

    Serial.println(" ");
    Serial.println(chartitles[x]);

   }
  }
 }


texts: The Time are functions do not work correctly when the processor clock speed is set at 128K

texts:
How can I change The timers to work correctly when The processor clock is set to 128K instead of 16 M?
At present, using the delay function does not work correctly, The delay is far too long.


texts: Stream video from camera to mobile and send control signal back from mobile to Arduino via WiFi

texts: I want to make an Ardunio based project in which I want to stream live video from camera (which is connected to Arduino borad ) to my Android app via WiFi and send back actions/control signals from my android app to Arduino to controller servo motor which are connected to Arduino board. Right now I only have Arduino mega with me. What else components are going to be required?


texts: Problem with simple coding for PLDuino: trying to turn relay on and off

texts:
I am writing the following, simple code to try to turn a relay in the PLDuino on and off, and it is giving me warnings and not compiling/uploading. Any help would be greatly appreciated. Here is my code:

#include <PLDuino.h>
using namespace PLDuino;

void setup()
{
  // A necessary call.
  // It sets pin modes according to their function.
  PLDuino::init();
}

void loop()
{
  // Simple switch RELAY3 on and off with 2 second timeout.
  digitalWrite(PLDuino::RELAY3, HIGH);
  delay(2000);
  digitalWrite(PLDuino::RELAY3, LOW);
  delay(2000);
}

I have installed the proper libraries. Here are the warnings I am getting:

WARNING: Category 'Graphics' in library PLDTouch is not valid. Setting to 'Uncategorized'
WARNING: Category 'General' in library PLDuino-Library is not valid. Setting to 'Uncategorized'
WARNING: Category 'Graphics' in library PLDuinoGUI is not valid. Setting to 'Uncategorized'
Sketch uses 1702 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.
avrdude: ser_open(): can't open device "\\.\COM4": The system cannot find the file specified.

avrdude: ser_drain(): read error: The handle is invalid.

avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.

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


texts:
I am trying to interface a Arduino Uno with an ASM330LHH using SPI. Whenever I try to read any register, I either get 0xff or 0x00 on the serial monitor
The code I am using:
#include <SPI.h>

#define LOOP_DELAY 1000 //ms
uint8_t data;

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

  /* Refer datasheet for ASM330LHH
   * SPI freq max 10MHz
   * MSB first
   * SPI mode 3
   */
  SPI.begin();
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));

  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  Serial.println("Setup complete!");

}

void loop() {
  digitalWrite(10, LOW);
  byte masked_addr = 0x0F | 0x80;
  Serial.println(masked_addr, BIN);

  SPI.transfer(masked_addr);
  data = SPI.transfer(0x00);
  Serial.println(data, BIN);
  digitalWrite(10, HIGH);
  delay(LOOP_DELAY);
}

The output I get:
10001111
11111111
10001111
11111111
10001111
0
10001111
0

The expected output for the above code is 0x6B. What might have gone wrong?
Thanks in advance


texts:
Arduino: 1.8.9 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Serial, 115200, 4M (3M SPIFFS)"

In file included from C:\Users\Priyaranjan Tiwari\Documents\Arduino\007mcu_php\007mcu_php.ino:3:0:

C:\Users\Priyaranjan Tiwari\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:84:9: error: 'WiFiClient' does not name a type

         WiFiClient & getStream(void)  __attribute__ ((deprecated)) ;

         ^

C:\Users\Priyaranjan Tiwari\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:85:9: error: 'WiFiClient' does not name a type

         WiFiClient * getStreamPtr(void);

         ^

C:\Users\Priyaranjan Tiwari\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:97:9: error: 'WiFiClient' does not name a type

         WiFiClient * _tcp;

         ^

C:\Users\Priyaranjan Tiwari\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:98:9: error: 'WiFiClientSecure' does not name a type

         WiFiClientSecure * _tcps;

         ^

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

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


texts: Reading file from SPIFFS in nodemcu using ArduinoJson

texts:
#include <ArduinoJson.h>
#include <FS.h>

/* Set these to desired credentials in runtime */
struct Config {
  String ssid = "";
  String pass = "";
  bool hFlag = false;
};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("");
  delay(1000);

  //allows serving of files from SPIFFS
  Serial.println("Mounting FS...");
  if (!SPIFFS.begin()) {
    Serial.println("Failed to mount file system");
    return;
  }

  if (readConfigFile("/LaSt.json", false)) {
    Serial.println("Config read");
  } else {
    Serial.println("Failed to read config");
  }
}

bool readConfigFile(char* fileName, bool whichFile)
{
  File configFile = SPIFFS.open(fileName, "r");
  if (!configFile) {
    Serial.println("Failed to open config file");
    return false;
  }

  size_t size = configFile.size();
  if (size > 1024) {
    Serial.println("Config file size is too large");
    return false;
  }

  // Allocate the memory pool on the stack.
  // Use arduinojson.org/assistant to compute the capacity.
  StaticJsonBuffer<256> jsonBuffer;

  // Parse the root object
  JsonObject &root = jsonBuffer.parseObject(configFile);

  if (!root.success())
    Serial.println(F("Failed to read file, using default configuration"));

  // Copy values from the JsonObject to the Config
  Config.ssid = root["ssid"];
  Config.pass = root["pass"];
  if (whichFile)
  {
    Config.hFlag = root["hFlag"];
  }

  // We don't need the file anymore
  configFile.close();

  return true;
}

Compile gives error in Copy values from the JsonObject to the Config section. Error: expected unqualified-id before '.' token.

Want to read file from SPIFFS, and store in variable to use.


texts: Can I switch a pulse solenoid from the onboard 5V/3.3V power source?

texts:
I have two pulse solenoids.  One is 6V...

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

and the other is 3.6V...

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

I have a Wemos R2 Mini with an ESP8266 chip on it, and I'm running the switching operation through a H Bridge motor shield (which handily switches the polarity of the electricity for a short time, which opens/shuts the solenoid).

I want to run this thing off a smallish battery pack that will supply 5V to the WeMos. I have three questions:

1) Can I send a 3.6V solenoid a 60ms pulse to open/shut it from a 5V power source without burning out the coil or causing any other damage?

2) Is 3.3V too low to power a 3.6V solenoid?

3) Do pulse solenoids still generate back EMF?

I don't know a lot about solenoids or electromagnetic fields so, sorry if my questions are noobish.


texts:
Hello in a previous question i was able to set variables through if statements

    const uint16_t inputLength = 512;
int ss = 0;
int bHold = 0;

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

 void loop() {
  if ( Serial.available() > 0 )
  {
    static char input[inputLength];
    static uint16_t i;
    char c = Serial.read();

    if ( c != '\r' && c != '\n' && i < inputLength - 1)
      input[i++] = c;

    else
    {
      input[i] = '\0';
      i = 0;

      uint16_t array[80];
      uint16_t j = 0;

      if ( !strncmp(input, "ss", 2) )
      {
        char* p = input + 2;
        while ( (p = strchr(p, ' ')) != NULL )
          array[j++] = strtol(p, &p, 10); //

        for ( uint8_t i = 0; i < j; i++ )
        {
          ss = array[i];
          Serial.println(ss);
        }
      }

      if ( !strncmp(input, "bHold", 5) )
      {
        char* p = input + 5;
        while ( (p = strchr(p, ' ')) != NULL )
          array[j++] = strtol(p, &p, 10);

        for ( uint8_t i = 0; i < j; i++ )
        {
         bHold = array[i];
         Serial.println(bHold);
        }
      }

      if ( !strncmp(input, "Whos There", 10) )
      {
        Serial.print("me");
      }
      if ( !strncmp(input, "hello", 5) )
      {
        Serial.print("hi");
      }
      if ( !strncmp(input, "sa", 2) )
      {
        Serial.print("  ss= ");
        Serial.print(ss);

        Serial.print("  bHold= ");
        Serial.print(bHold);

        Serial.println(" ");
        Serial.println("==============================");
      }
    }
  }
}

if works! but if i keep adding variables i have to keep adding if statements and this will get longer. so then i went with code like this that allows me to set all variables at once

  #define INPUT_SIZE 30

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

}
void loop()
{

  while (Serial.available() > 0) {

    int _mode = Serial.parseInt();
    int _ss = Serial.parseInt();
    int _bHold = Serial.parseInt();

    if (Serial.read() == '\n') {
      ss = _ss;
      bHold = _bHold;
      mode = _mode;

    }
  }

}

this works awesome! but i have to set all variables at once. my question is is there a way i can simply input a command like ss = 10 press enter then bHold = 30 and not have to input any other variable?
thanks i advance. please point me in right direction  Maybe make a function?


texts: Press the Windows key using "keyboard.press();"

texts:
Is it possible to allow an Arduino Leonardo to simulate pressing the Windows key using the keyboard.press(......); command?

If so, what is the required value?


texts: I am making a game system, and I would like to run code for a sd card over spi. the sd card is set up already. I want to know if there is a way i can put a string of code onto the arduino and run it.


texts:
I tried to edit the Fade sketch such that the max intensity the PWM reaches is controlled by a potentiometer. I used analogRead() on the potentiometer and converted the 10bit value to 8bit equivalent(by dividing by 4 and rounding) to feed into analogWrite. I am new to arduino and I dont know a more elegant way to do this, sorry!

It worked generally but sometimes while turning the potentiometer, the LED would be stuck at a fixed level of brightness. I have to reset the Arduino or turn the pot to the extremes to remove this "loop". I set up serial monitor to look at the values of brightness. It does not always happen at the same position of the potentiometer.

I deduce that it is a mathematical error causing this loop, likely due to my poor use of the if() function. Can anyone offer me a reason for this?

*I tested with both the Uno and Nano, as well as TinkerCad simulator with similar results.

-----------------------------Fade sketch edited by me----------------------

/*
 Fade, edited with maximum intensity controlled by potentiometer reading
 */

int led = 11;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int potPin = A0;    // set the pin that reads the potentiometer voltage
int potValue = 0;   // declare and initialize potValue
int potValueConverted = 0; // 10bit potValue converted to 8bit equivalent

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  //read the voltage at the pot
  potValue = analogRead(potPin);

  //convert 10bit input into 8bit output by dividing by 4, rounding to avoid need for float variable
  potValueConverted = round(potValue/4);

  // set the brightness of pin 11:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

Serial.println(brightness);

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= potValueConverted) {
    fadeAmount = -fadeAmount;
  }

  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}


texts: ESP8266 returns whatever is sent through Arduino serial

texts:
I am a newbie and working on a kind of WiFi-controlled vehicle (car or maybe hovercraft later). My ESP8266 repeats the commands I send. For example, AT gives AT, AT+GWR gives AT+GWR, dabdabik gives dabdabik, etc.

I am using an Arduino Uno to send commands, as I don't have FTDI related stuff (USB to Serial Converter). I use AA cells for power supply (1.5v*2=3v). I don't even have 3.3 volt direct supply. I am using the Arduino IDE Serial Monitor. I connected the Arduino's TX to the ESP8266's RX via a voltage divider (1.66K Ohm(TX) and 1.66K Ohm (GND)->3.29 Ohm(RX)).

My connections are:

ESP8266----------------Arduino Uno
TX---Voltage divider---RX(d0)
RX---------------------TX(d1)
GND--------------------GND
VCC-------**3V**
CH_PD-----**3V**

Sometimes it gives garbage otherwise it just repeats (weird). Garbage ONLY changes if baud rate is changed.

I flashed it (it seems) with the AT 9.5.2 firmware. Flashing works rarely ONLY with TX to TX connected directly without a voltage divider.

I tried as much as I could after searching the web and ESP8266 forum but still couldn't solve problem.

Please help. I am a student in a small town (Manipal) in Southern India so no good stores nearby and I don't want to buy FTDI or anything online. I am a bit new to electronics, but I am a C++ programmer and student.

UPDATE: I noticed after some resets that it gives full garbage to longer commands most of the time, whereas two-letter commands give partial garbage. For example AT gives IT,TT,OT,etc.

There is no coding.
I am sending the commands directly via Arduino hardware serial pins (rx,tx) and a bare minimum program.


texts: HC-SR04 quits pinging when distance < 0 || distance < MAXDISTANCE

texts:
so here is the issue. I have a mega 1280, a handful of neopixels and a HC-SR04. I am using the New Ping library (tried both 1.5 and 1.6). I am trying to make a device that will tell my mom when she has pulled into the garage enough so she don't get hit by the garage door AND doesn't run into the wall. I wrote a bunch of code to handle the lights and what colors to do when and this part works perfectly. My issue is with the sensor. It works great except for 2 specific conditions.

if you are too close. I normally either cover one of the 2 sonic sensor part or just barley touch then with a piece of cardboard (or anything for that matter
If you go outside the scope of the max distance

when either of this are met, the ping sensor stops clicking and it just returns all 0's for the output. I am including the code less the part for the lights because even if i remove that part of the code, it still fails on those 2 conditions.

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include <NewPing.h>
#define TRIGGER_PIN  52
#define ECHO_PIN     53
#define MAX_DISTANCE 120
#define PIN 6
#define LEDNUM 8

int codeFact = (MAX_DISTANCE / (LEDNUM * 3));
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDNUM, PIN, NEO_RGB +     NEO_KHZ800);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  strip.begin();
    strip.show();
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(0, 255, 0));
      strip.show();
      delay(50);
    }
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(255, 255, 0));
      strip.show();
      delay(50);
    }
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(255, 0, 0));
      strip.show();
      delay(50);
    }
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(0, 0, 0));
      strip.show();
      delay(50);
    }

Serial.begin(115200);
}

void loop()
{
 delay(2000);
  int uS = sonar.ping();
  int dis = uS / US_ROUNDTRIP_CM;
  Serial.println(dis);
  /*
  Light code normally goes here
  */
}


texts: Send Bluetooth Data to Android App (HC 05)

texts:
I'm struggling to send data strictly from my arduino UNO to an android app using bluetooth module HC 05. I am able to send/receive using 1) the serial monitor in arduino IDE and 2) Bluetooth Chat android app (a sample project in Android Studio). But when I use software serial using pins 3,2 instead of TX/RX on my UNO, the Bluetooth Chat app cannot connect to my HC 05. I think I'm missing something important.

My end goal is not to send messages like a chat. It will be a very simple flag-based system where, for example, an event occurs on my arduino which causes it to transmit character 'h' through bluetooth, which is then received by my android app. In android receive: if 'h' is read by bluetooth, doSomething(). I don't need to send anything from my android app to the arduino right now, but that would be nice to know.

I just thought I could test my bluetooth functionality with this Bluetooth Chat sample app. Now, that seems like a poor place to start.

Any suggestions are appreciated.


texts: Connecting Arduino and Processing, how do I know what COM to read?

texts:
I'm using Processing to read data from the serial port that the Arduino sends. When I go to device manager it shows that the Arduino is in COM 4, but in order for Processing to read from the Arduino the COM I need to type in is 2:

String portName = Serial.list()[2]

Why do the numbers not match?

Thanks!


texts: Arduino Uno keeps looping on setup() everytime I press a specific button on the remote

texts:
I'm trying to decode my Panasonic television remote using the IR_RECEIVE sketch below.

When I press the remote's buttons it works fine and Iget the values, except from when I press the power button - the setup() function executes.

This is the code:

/* Raw IR decoder sketch!

This sketch/program uses the Arduno and a PNA4602 to
decode IR received. This can be used to make a IR receiver
(by looking for a particular code)
or transmitter (by pulsing an IR LED at ~38KHz for the
durations detected

Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
*/

#define IRpin_PIN      PIND
#define IRpin          2
#define MAXPULSE 65000
#define RESOLUTION 20

uint16_t pulses[100][2];  // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {
    Serial.begin(9600);
    Serial.println("Ready to decode IR!");
}

void loop(void) {
    uint16_t highpulse, lowpulse;  // temporary storage timing
    highpulse = lowpulse = 0; // start out with no pulse length

    while (IRpin_PIN & (1 << IRpin)) {
        highpulse++;
        delayMicroseconds(RESOLUTION);

        if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
            printpulses();
            currentpulse = 0;
            return;
        }
    }
    pulses[currentpulse][0] = highpulse;

    while (!(IRpin_PIN & _BV(IRpin))) {
        lowpulse++;
        delayMicroseconds(RESOLUTION);
        if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
            printpulses();
            currentpulse = 0;
            return;
        }
    }
    pulses[currentpulse][1] = lowpulse;

    currentpulse++;
}

void printpulses(void) {
    Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
    for (uint8_t i = 0; i < currentpulse; i++) {
        Serial.print("delayMicroseconds(");
        Serial.print(pulses[i][0] * RESOLUTION, DEC);
        Serial.println(");");

        Serial.print("pulseIR(");
        Serial.print(pulses[i][1] * RESOLUTION, DEC);
        Serial.println(");");
    }
}

This is the output:

  Ready to decode IR!

  Received:

  OFF   ON
  delayMicroseconds(34724);
  pulseIR(3600);
  delayMicroseconds(1800);
  ......
  delayMicroseconds(1340);
  pulseIR(460);
  delayMicroseconds(1360);
  pulseIR(460);
  Ready to decode IR!
  Ready to decode IR!

The last 2 rows appeared when I pressed the power button (twice).
The rows above appears when I press any other button.

I played around with the Arduino and the remote, I might have done something to cause this. The first time I tried it - it worked fine.

I tried resetting and re-uploading.

Sorry if the post is too long or not informative enough - I'm new to this and not really sure what kind of information to provide.


texts: Value of joystick reduces when I send it over serial

texts:
I've got two arduino cards and two bluetooth bluesmirfs. I am currently trying to read value from a joystick and send it over to the other arduino card and use that value to control my servo motor.

Here's my code.

       //Master Code
void loop()
{
    yVal = analogRead(yAxis);   (value between 0 and 1023)
  if(bluetooth.available())
  {

    bluetooth.print(yVal);
  }
  else if(Serial.available())
  {

    Serial.print(yVal);
  }
  delay(100);
}

//Slave code
void loop(){
  while(Serial.available())
  {

    int c = Serial.read();
    Serial.print("Joystick value: ");
    Serial.println(c);
    int val = map(c, 0, 1023, 0, 255);
    Serial.print("Map value: ");
    Serial.println(val);

      myServo.write(val);
    }
  }

Am I doing something wrong? Instead of getting something between 0 and 1023 I get something below 50.


texts: How can I exactly put my sensor at 4 Hz readings?

texts:
I'm using the grove GSR sensor: http://www.seeedstudio.com/wiki/Grove_-_GSR_Sensor with this code:

const int GSR=A0;
int threshold=0;
int sensorValue;
const long interval = 1000;
void setup(){
  long sum=0;
  Serial.begin(9600);
  delay(1000);

  for(int i=0;i<500;i++)
  {
  sensorValue=analogRead(GSR);
  sum += sensorValue;
  delay(5);
  }
  threshold = sum/500;
   Serial.print("threshold =");
   Serial.println(threshold);
  }

void loop(){
  int temp;
  sensorValue=analogRead(GSR);
  Serial.println(sensorValue);
  temp = threshold - sensorValue;
  delay(250);
  }

There is the delay way to skip milliseconds or the millis() function. Do you have ideas on how can I implement it? The delay has the problem that doesn't consider the time the sensor uses to read the data.

Here's what I am trying

const int GSR=A0;
int threshold=0;
int sensorValue;
const long interval = 1000;
unsigned long startTime=millis();

void setup(){
  long sum=0;
  Serial.begin(9600);
  delay(1000);

  for(int i=0;i<500;i++)
  {
  sensorValue=analogRead(GSR);
  sum += sensorValue;
  delay(5);
  }
  threshold = sum/500;
   Serial.print("threshold =");
   Serial.println(threshold);
  }

void loop(){

  if((millis() - startTime) % 250 == 0) {
   int temp;
  sensorValue=analogRead(GSR);
  Serial.println(sensorValue);
  temp = threshold - sensorValue;

  }
  }


texts: How can I read the serial output of STM32F103C8T6 from USB to Serial TTL?

texts:
I recently bought a STM32F103C8T6 board (blue pill)
I programming to it using the USB to Serial TTL I bought (CP2102).

I'm still taking very first steps and trying to figure out how to operate the component.
I was able to burn a basic script to STM32F103C8T6 that causes the P13(LED) to blink.

Now I'm trying to add basic printing that I can see over the serial interface
Which I am already connected to (CP2102).

Here's what my code looks like:

void setup() {
// initialize digital pin PC13 as an output.
pinMode(PC13, OUTPUT);
Serial.print("finish setup function \r\n"); // try to print something using serial
}

void loop() {
digitalWrite(PC13, HIGH);
delay(500);

digitalWrite(PC13, LOW);
delay(500);

Serial.print("loop throgh loop function \r\n"); // try to print something using serial
}

Everything is compiled and loaded fine (I work through ARDUINO IDE), but it is not clear to me where I can see these prints.

I tried to see them in Tools-> serial monitor (in the arduino ide tool)
But I didn't see any printing ...

(I know that my code got loaded successfully because I play with the speed of the LED blinks and I see that it is responding to the change at the speed of the flicker).

It feels like it's a really stupid question but where can I see my prints?


texts:
I am trying to choose a wire encoder for my project. So far, I found this wire encoder (see link). Assuming the measurement range of my cylinder is 1 m. Then, with a 10 bit ADC converter of my Arduino Mega2560, I would have a resolution of 0.09cm (= 100cm/1024). But, lets say some cylinder only have a measurement range of 0.5m. Then the resolution would be 0.048 (=50cm/1024).
I can see that I am missing something here, because the resolution of the later case should be worse than the case with the full measurement range 1m. I would be appreciate for any tipps.

Edit:

Cylinder's movement range 0~1m

Wire encoder's measurement range 0~1.25m

Wire encoder's analog output 0~10v
ADC resolution 10 bit


texts: I am thinking about buying an ATtiny84A, which fits perfectly into my project. I want to embed it into a watch that I am designing right now. But I want to buy an SMT version so I have less space to consume. What do I need for programming it through USB? Special Atmel chip? Or just 2 digital pins from USB directly into it? Thank you very much. :)


texts:
In short, I have programmed and wired a speed/odometer and all is working well. However, I need to save data from the components/sensors once a power button is pressed, which has led me down the road of capacitors which seem to be the solution to my problem. Reading online about capacitors has dropped me in the deep end where I would like some help to see if I am thinking right.

I have attached a clearly very crude circuit which I need someone to confirm if I have it correct. If it's important, the whole system ran on 5v, powered by a 9v battery. Is a 5v Capacitor even the right one to use, considering that most components will not be active at the point of powering down?

OLD IMAGE: https://imgur.com/a/TTZGS1n
NEW IMAGE: https://imgur.com/a/aHRpzE4

Just tried to download the app and it's not happening for some reason, so the link(edited) will have to do, I'm sorry.


texts: my LM35 temperature sensor gives weird measurements,

texts:
Board: esp32

I know my wiring is correct because I get data from the sensor, but the data is a bit weird.

At 22 celcius I get 140, even though if I do the voltage calculation (* 0.473372) it still doesn't work.

the number 0.473372... comes from taking the voltage 4.7v / 1024 * 1000 / 10

My code:

 Serial.print("temp: ");
 float temp = (analogRead(A13) * 0.473372781065088);
 Serial.println(temp);
 delay(2000);

Any answers?


texts: No Matching Function for call to Ultrasonic:Ultrasonic(int,int)

texts:
Good Day! I am trying to code the distance of Ultrasonic Sensor but the problem is it gives me this error. Any idea? Please help.

#include <Ultrasonic.h>

// HR-SC04 SENSOR
#define TRIGGER_PIN   5
#define ECHO_PIN      6

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);

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

// Global variables
int lastDistance = 0;
int thisDistance = 0;

void loop()
{
  // Copy over last distance
  lastDistance = thisDistance;

  // Get new this distance
  thisDistance = ultrasonic.Ranging(CM);

  if (outlierCheck(lastDistance, thisDistance)) {
    Serial.println("Outlier found: " + String(thisDistance));
  } else {
    Serial.println(String(thisDistance) + " cm");
  }

  delay(10);
}

// Check for significant jumps and outliers in sensor reading
bool outlierCheck(int lastDistance, int thisDistance) {

  // if the difference between measures is greater then 20cm, outlier found
  if ((lastDistance - thisDistance) > 20) {
    return true;
  } else {
    return false;
  }
}


texts: Good book/reference for AVR coding in pure C/C++?

texts: Can someone recommend a good book/reference for going vanilla (i.e. not using arduino simplified language) on e.g. ATtiny85? I will need to use the equivalents of analogRead() and digitalRead() quite a bit. And is softwareserial the best method for debug output? I have less than 8KB of flash, so any advice on that (and reduction of binary for upload) would also be greatly appreciated.


texts: I want to initialize the value of byte to -1. When I just use byte num = -1 the value ends up being a decimal 255. I've also tried int8_t number = -1 and then byte num = number but this didn't work either.