texts:
How easy is it to create a code using an RTC to rotate the stepper motor one way at a specific time and back the other way at a specific time? and that time being charged different months of the year. how would I go about this?
I want to make an automatic chicken door, to open in the morning and close at night.
Thanks


texts: Burning arduino generate hex file to blank atmel chip

texts:
Is it possible to burn the hex file to a blank chip, generated by Arduino to burn using USBASP to that particular chip without using Arduino board ? Will the program work ?

My main goal is to use Atmega328P for low power. Should I select Arduino pro mini in the arduino IDE ?

Ater successful testing I will just burn the hex file to another 50 chips. thats why I dont want to use arduino board.


texts: Can I send data from one MKR1000 to another MKR1000

texts:
I want to simply send data from one MKR1000 to the other over wifi, both are connected to the same network, but sending the data is where I get stuck, I've looked through tuts everywhere but can't seem to find an answer.. can someone point me to a solution?

I've set up my devices using the tut https://www.arduino.cc/en/Tutorial/Wifi101WiFiChatServer
but the devices don't communicate to each other they only take telnet from the host server(my laptops wifi hotspot)


texts: Synchronization and Implementing hamming code on Software Serial

texts:
I want to learn and use Hamming Code. Would it be wise to
alter the Software serial library to do this or just change the data being
transmitted in the actual Arduino sketch?

Also, for means of better synchronization, what would be the best method with regards to these tx/rx modules working with the Arduino using Software Serial. Am I constrained to using the built in synchronization from the library or may I also implement other forms of synchronization, like manchester and NRZ coding? If so, any guidance here?

EDIT

For implementing Hamming code, what if the interference occurs on the parity bit? Is there a way around this problem?


texts:
I have installed Arduino software into my PC and copied the bin files into the memory card that has to be fixed into Arduino yun.

After switching on the yun board it is not creating any Arduino yun wifi connection.

Can you help me to overcome this problem?
Thanks.


texts: I'd like to buy a standalone capacitive touch sensor to create interactive art.  It says it is powered by 1.8 to 5.5 VDC.  I am new to arduinos - what type of battery can I buy to power this sensor?  I'm hoping it's simple, not complicated. Thanks!


texts:
I am communicating with ESP8266 using SoftwareSerial of Arduino UNO. I can successfully send AT commands and get response when communicating through the terminal. But if i programmatically send particular AT commands there is no response.
For eg:
I type AT in serial monitor I get OK
But if i send the following through SoftwareSerial pins

mySerial.println("AT");

there is no response.

Can anyone tell what will be the solution as to how to send AT commands explicitly.

The sketch is

#include<SoftWareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("AT");
  delay(100);
  while (mySerial.available()>0 ) {
    char ch=mySerial.read();
    data.concat(ch);
    if(ch=='\n')
      Serial.println(data);
    data="";
  }
}//setup

void loop()  {
  while (mySerial.available()>0 ) {
    char ch=mySerial.read();
    data.concat(ch);
    if(ch=='\n')
      Serial.println(data);
    data="";
  }
  while (Serial.available()>0 ) {
    mySerial.write(Serial.read());
    delay(100);
  }
}//loop

I am using Sparkfun Level Shifter to get 3.3V from 5V. The wiring is straightforward. ESP8266 Vcc and CH_PD to 3.3V; GND to GND; Tx to Arduino 2(Rx) directly; Rx to Sparkfun 3.3V RXO LV side and Arduino 3(Tx) to RXI HV side) so that when Arduino transmits it gets stepped down to 3.3V and ESP8266 receives it. The wiring should be correct as it is working perfectly when AT commands are sent manually.

I tried everything of sending mySerial.write("AT/r/n"), mySerial.print("AT") mySerial.print("\r\n"), etc but nothing seems to work.

Is it that there is some problem with SoftwareSerial. But then how is it working if i send AT commands manually through terminal ?


texts:
I need some help because I did not understand the configuration analogReference(INTERNAL).
I would measure the intensity of a Laser beam passing through a filter. This is the circuit I would implement, using the 3.3 V power supply:

In order to rise up the resolution of the system, I would use the 1.1 V power supply (Arduino Uno) to feed the sensor, keeping the Laser power supply at 5 V. In the analogReference(EXTERNAL) configuration shown in the schematic, the sensor is powered by the 3V3 pin, which is connected to the AREF pin. How should I change the circuit in analogReference(INTERNAL) configuration?


texts: What do I do with the potentiometer on Adafruit RGB LCD

texts:
So I just got my Adafruit RGB backlight positive LCD 16x2 + extras - black on RGB In this picture it shows a potentiometer beside the LCD. Anyone know where this is supposed to go?

If it helps, I'm mounting the shields on an Adafruit I2C Controlled + Keypad Shield Kit for 16x2 LCD


texts:
What's the low level difference between if(Serial.available() > 0) and while(Serial.available() > 0)? On what conditions would you choose one over the other?
I was testing my codes on 4 daisy chained 74HC595 shift registers controlling multiple LEDs. The code takes in a number from the serial monitor and displays it out in binary via the LEDs. Here is the code below that worked:
#define latchPin 8  //ST_CP pin of 74HC595
#define clockPin 9  //SH_CP pin of 74HC595
#define dataPin 7   //DS pin of 74HC595

//number of 74HC595 in daisy chain
#define numOfDaisyChainReg 4

byte registerVal[numOfDaisyChainReg];

void setup() {
    Serial.begin(115200);
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
}

void loop() {

  while (Serial.available() > 0) {

    uint32_t num = Serial.parseInt();
    Serial.print(num, DEC);
    Serial.print(" : ");
    Serial.println(num, BIN);

    //breaks the recieved int into 4 unsigned bytes
    //and assigns the byte value into the "registerVal" array
    for (uint8_t a = 0; a < numOfDaisyChainReg; a++) {
      registerVal[a] = (num >> (numOfDaisyChainReg - (a + 1)) * 8) & 0xFF;
      Serial.print("registerVal["); Serial.print(a); Serial.print("] = ");
      Serial.println(registerVal[a], BIN);
    }

    //writes the 4 bytes into the shift register
    digitalWrite(latchPin, LOW);
    for (uint8_t x = 0; x < numOfDaisyChainReg; x++) {
      shiftOut(dataPin, clockPin, MSBFIRST, registerVal[x]);
    }
    digitalWrite(latchPin, HIGH);

  }

}

Originally, I had if(Serial.available() > 0) and that didn't work as no LEDs lit up despite everything else in the code working as it was expected. Switching to while(Serial.available() > 0) solved that problem. Anyone have any idea why that's the case?


texts: I would like to create a program with separated modules, is this this possible using Arduino IDE?


texts:
I've got a cmps10 compass module hooked up to my arduino due through a logic level converter. I am writing code to convert the raw magnetometer readings into a bearing that I can use but have run into a huge problem. My bearings are all funky for some reason. They are totally unrelated to the actual bearing of the robot. I know the sensor is fine because I am able to get the tilt compensated reading from it and it works great. One thing I noticed is that the magnetometer reading on the X-axis is always positive could this be the problem? The X-axis high byte generally between 0x00 and 0x03. My code is below (i2cBus = &Wire)

i2cBus->beginTransmission(I2C_Address);
i2cBus->write(byte(10));
i2cBus->endTransmission();

i2cBus->requestFrom(I2C_Address, 4);
xMagHighByte = i2cBus->read();
xMagLowByte = i2cBus->read();
yMagHighByte = i2cBus->read();
yMagLowByte = i2cBus->read();

xMag = short(xMagHighByte<<8);
xMag |= xMagLowByte;
yMag = short(yMagHighByte<<8);
yMag |= yMagLowByte;

if(yMag!=0){
  magBearing = (atan2(xMag,yMag)*180.0)/3.141592654;
}
else if(xMag>0) magBearing=0.0;
else if(xMag<0) magBearing=180.0;
else magBearing = 1000;
if(magBearing < 0) magBearing+=360;
magBearing=360-magBearing;
return magBearing;


texts:
I am trying to interface 4052 demux with arduino, but my program is not working as high is not displayed on serial monitor corresponding to select lines.

//output coming from demux pins
int sensorValue0=A0;
int sensorValue1=A1;
int sensorValue2=A2;
int sensorValue3=A3;

void setup() {
  Serial.begin(9600);
  Serial.println("start");
  //select pins connected A,B connected to 2 and 3
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
}

void loop() {
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  analogRead(sensorValue0);
  //Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  int voltage0= sensorValue0 * (5.0 / 1023.0);
  Serial.println("volatge0");
  Serial.println(voltage0);
}


texts: If a condition is ever met I want to run a loop permanently

texts:
I am trying to run an LED to do SOS in morse code if a temperature is over 20 C and motion is detected, but I want it to continue doing SOS even after the motion goes away or the temperature comes down.

Right now it simply does SOS 1 time and stops.

(sorry if coding is messy)

   int counter;
   int motion = 0;

   void setup()
  {

    {Serial.begin(9600);
     pinMode(4, INPUT);
     pinMode(0, OUTPUT);
     pinMode(2, OUTPUT);
     pinMode(1, INPUT);
     digitalWrite(0, HIGH);

     }
  }

    void loop()
   {

   int sensorA0Value = analogRead(A0);
   float voltage = sensorA0Value * (5.00 / 1023.00);
   Serial.print("Voltage: ");
   Serial.print(voltage);

   float temp = (voltage -.5)*100;
   Serial.print("| Temp: ");
   Serial.print(temp);
   Serial.println(" Celcius|");

   motion = digitalRead(4);

   if(motion == HIGH)
    {Serial.println("Motion Detected");}
   if(motion == LOW)
     {Serial.println("No Motion");}

   if(motion == HIGH && temp > 30)
     {
     digitalWrite(2, HIGH);
     delay(300);
     digitalWrite(2, LOW);
     delay(300);
     digitalWrite(2,HIGH);
     delay(300);
     digitalWrite(2, LOW);
     delay(300);

     digitalWrite(2, HIGH);
     delay(600);
     digitalWrite(2, LOW);
     delay(600);
     digitalWrite(2, HIGH);
     delay(600);
     digitalWrite(2, LOW);
     delay(600);
     digitalWrite(2, HIGH);
     delay(600);
     digitalWrite(2, LOW);

     delay(600);
     digitalWrite(2, HIGH);
     delay(300);
     digitalWrite(2, LOW);
     delay(300);
     digitalWrite(2,HIGH);
     delay(300);
     digitalWrite(2, LOW);
     delay(300);
     digitalWrite(2,HIGH);
     delay(300);
     digitalWrite(2, LOW);
     delay(1000);

   }
     else {
     digitalWrite(2, LOW);

     }
   delay(1000);
    }


texts: So I have recently been trying to use the Myoware Muscle sensor to control an 3d printed arm, but it is only able to read the muscle of the entire arm. Is there anyway i could make the Myoware sensor read different fingers at the same time?


texts: Why do we use HX711 with load cell (Why do we need A to D conversion)?

texts: We generally amplify the signal from load cell but why there is need for A to D (analog to digital) conversion?


texts:
my serial connection prints rubbish, but it systematic, so it's not just random as you see on image 1, any help would be appreciated

other info:

the first image of the serial monitor of COM6 is my own serial connection, image nr. 2 is the serial monitor of COM4 which already uses the onboard serial to USB
the last image shows how I made my own serial connection

the 2 black cables are providing around 4 volts, I know these are not necessary cause the USB already provides 5 volts and ground

and oh ye, normally the USB on the last image would be connected to my pc ofc


texts:
I am thinking to buy one of "ATTINY85 Development Board"...

Before buying I was checking details/Advantages of it.

First I thought this is just a breakout board & USB for power.

But, then found It can be programmed with "Digispark driver & board manager" directly by the USB.

I checked this Question: EBay “Development Programmer Board for ATtiny”

Someone said there:

  "While limited, this type of board can be useful for "blink an LED on
  USB command" type tasks"

My Main question is:

Is it really programmable withut any TTL/ICSP/FTDI extention?

If so, is it possible to program other AVR chip (Attiny/Atmega) with simple codes directly via USB...?

(with same method)


texts: Can this Motor shield support other arduino functions?

texts:
http://www.flipkart.com/grab-em-l293d-motor-driver-arduino-shield/p/itmehvzzpzj4wyby?pid=ETYEHVZZFFHRFMFG

I want to ask whether this shield will allow me to use the free pins of arduino for other functions?


texts: Allocate object memory statically; intialize it dynamically?

texts:
I have an object whose constructor gets passed a parameter. If I know the parameter value at compile time, I can construct the object statically:

static FOOOBJ foo(3);

(I understand that it isn't really done statically, i.e. by the compiler, but is actually done during setup).

But if I don't know the parameter value at compile time, I'd still like to pre-allocate space for the object but construct the object in that space at run time. Can it be done without a separate .initialize() method?


texts: Hey I'm working on a home automation system where I can replace one of my 2 way switches to an Arduino Or node MCU controlled one but I want to avoid normal relays because as of what I know they can be unreliable and tend to fail. So is there any way I can replace my switch with an Arduino controlled switch and also I cannot use solid state relay as it has only two terminals and it cannot replace my two way switch.


texts: Can I include a header file into a new header file?

texts: Can I include a header file into a new header file that I created? I put #include <MCP23S17.h>. I want to create a another header file.


texts: How to use code for OV7670 on Arduino Uno

texts: I want to interface my OV7670 camera (without FIFO) to my Arduino Uno. I have browsed internet quite a lot about it and found people either saying it's not possible or they just give me the link to this github repository (As this guy has done exactly what I want). As the author of this repository is a man of few words, he did not help me very much. I just want to know how to use this to get image sent to my PC serially. I only know how to use Arduino IDE in windows platform and no other platform.


texts:
Can optiLoader be used to burn custom hex?

For example, there's hex representation stored in optiLoader.ino in image_328, if that value is replaced with content of my pre-compiled hex, should that work right out of the box or some additional tweaking is needed?

EDIT

Discussion about the same topic on arduino forum as well.


texts: Interrupt every second on ATTiny84 (and sleep the rest)

texts:
I'm building a digital watch just like in this post, except I'm using an ATTiny84. However, the ATTiny84 doesn't have an asynchronous Timer2 like the ATMega328 and does not have a power save mode, so it cannot wake up from the Timer2 interrupt as is suggested in that post.

I need to increment my 'seconds' counter every second, and I need to do it precisely so I don't lose/gain time (so I can't use the watchdog timer which, as I understand, does not use the crystal oscillator but rather its own imprecise clock). I was planning on just keeping the CPU on and using an external crystal, but it seems that that takes a lot of power (~3mA). Even with the SLEEP_MODE_IDLE, I could only get the current draw down to around (~1.2mA).

Like Nick Gammon suggested in that post, I feel like the real solution is to sleep when not changing the counter. Is there any way to wake up after a precise amount of time in the POWER_DOWN or STAND_BY modes?


texts: Store 3-dimensional char array in program memory with PROGMEM

texts:
I'm running a sketch whith a quite big, constant three dimensional char array (or simply, a table of strings). As this takes lots of RAM I'd like to store it in programm memory in order to keep the RAM free. This is the Sketch I'd like to run (my first idea):

const char *rules [16][5] PROGMEM ={
 {"1Lorem ipsum dolor sit amet, consetetur sadipscin0g elitr", "sed di7am nonumy 8eirmod tempor invidunt"},
 {"2Lorem ipsum dolor sit amet, consetetur sadipscing2 elitr", "sed diam nonumy 9eirmod tempo5r invidunt"},
 {"3Lorem ipsum dolor sit amet, consetetur sadipscing 4elitr", "sed0 diam nonumy 1eirmod tempor invidunt"},
 {"4Lorem ipsum dolor sit amet, consetetur sadips3cing elitr", "sed diam nonumy 2eirmod tempor in5vidunt"},
 {"5Lorem ipsum dolor sit amet, consetetur 3sadipscing elitr", "sed 7diam nonumy 3eirmod tempor invidunt"},
 {"6Lorem ipsum dolor sit amet, conset9etur sadipscing elitr", "sed diam n8onumy 4eirmod tempor invidunt"},
 {"7Lorem ipsum dolor sit amet, consetetur sadipsc3ing elitr", "sed diam nonumy 5eirmod tempor inv4idunt"},
};

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  for(int i = 0; i < 16; i++){
    for(int j = 0; j < 5; j++){
     Serial.println(rules[i][j]);
    }
  }
}

void loop() {
}

But this fails with the following error:

variable 'rules' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

According to Arduino's FAQ this can be solved by changing the array's declaration to

const char * const rules [16][5] PROGMEM ={

The sketch compiles now without errors, but the global variables (here only the array) still need lots of RAM:

Sketch uses 2484 bytes (7%) of program storage space. Maximum is 32256 bytes.
Global variables use 880 bytes (42%) of dynamic memory, leaving 1168 bytes for local variables. Maximum is 2048 bytes.

I'm not sure what causes this, but is it possible that only the pointers to the strings are stored in program memory, while the strings theirselves are still copied to RAM?

How do I put the whole arary in programm memory?

There has already been a question like this on StackOverflow, but the answer recommends using prog_chars, which are according to the AVR documentation deprecated.


texts:
It's my custom debounce code

It keeps the led on by flipping the required threshold value when triggered after the led has turned on to keep the led in a high state and vice verse triggered again, the comments on the code explain it in more detail.

/*
 * This code is my custom debounce code, I made this but this isn't working as planned,
 * see the thing is that it turns on when I hold the button and if I release it,
 * it starts to flickers and then gradually turn off, what is wrong with my code ?
 * I can't see it.
 */

const int ledPin = 13; // led connected to pin 13
const int PushButton = 2; // a pushbutton connected to pin 2
int switcher = HIGH; // the switcher changes it's value, we require this later
int dilay = 1; // controls the delay
unsigned long lastTrigger = 0; // records the last time the led was turned on

void setup() {
  pinMode(ledPin, OUTPUT); // sets ledpin as output
  pinMode(PushButton, INPUT); // sets pushbutton pin as input
}

void loop() {
  int pushButtonState = digitalRead(PushButton); // stores the value of the pin each time the loop begins agian

  if((millis() - lastTrigger) >= dilay){ // my custom debounce code
    if(pushButtonState == switcher){ //  this is the trick, when the pushbutton pin is high it's equal to the switcher value
      digitalWrite(ledPin, HIGH); // it turns on the led
      int switcher = LOW; // now the switcher value will be low now the pushbutton pin value will also be low keeping the led on
    }else{
      digitalWrite(ledPin, LOW); // now if the led is on and pushbutton is high, then it will not be equal to the switcher because we had changed it in the previous statement
      int switcher = HIGH; // now the switcher is high and the pushbutton value low, switcher isn't equal to pushbutton so there by keeping the ledpin as low

    }

    if(pushButtonState == 1){ // if pushbutton is high
      int lastTrigger = millis(); // then  lastTrigger equals to the current time
    }
  }

}


texts: FlySky TH9X with Arduino: cant get pulseIn() function to return sensible values for any channel

texts:
So I've got a FlySky TH9X and I'm trying to read some pulses using an Arduino Uno.

I'm just starting out so I want to get the hang of using the pulseIn function before moving onto interrupts. My problem is that, when I wire everything up, I don't get sensible values. Furthermore, they don't change even though I move around the sticks on the actual remote.

I tried to start off simple by wiring just the channel 1 of the receiver to pin 3 of the Uno. Then I used this code:

int ch1;

void setup() {
  pinMode(3, INPUT);
  Serial.begin(9600);
}

void loop() {
  ch1 = pulseIn(3, HIGH, 25000);
  Serial.print("Channel 1: ");
  Serial.println(ch1);
  delay(100);
}

The serial monitor then spits out numbers ranging from 0 up to 10000+ in a very erratic and apparently not periodic nature. I'll copy a few lines here:

Channel 1: 9989
Channel 1: 10063
Channel 1: 10068
Channel 1: 274
Channel 1: 0
Channel 1: 10085
Channel 1: 10039
Channel 1: 10336
Channel 1: 9629
Channel 1: 9959
Channel 1: 10064
Channel 1: 10088
Channel 1: 378
Channel 1: 0
Channel 1: 10044
Channel 1: 10059
Channel 1: 10424
Channel 1: 9632
Channel 1: 9867
Channel 1: 10069
Channel 1: 10067
Channel 1: 10473
Channel 1: 10037
Channel 1: 10063
Channel 1: 10063
Channel 1: 10253
Channel 1: 9677
Channel 1: 10013
Channel 1: 10064
Channel 1: 10062
Channel 1: 13

As you can see: not only are the higher-end values a whole order of magnitude too big (i thought pulses are normally between 1000 - 2000us?), but the actual range that these numbers span is far, far too wide for me to do anything with. Also, the sticks on my remote seem to have no influence on the numbers.

Can someone please help me? thank you :)

Hassan


texts: Where does the sound come from this board?

texts:
As the question says, i can't figure out where the sound comes from on this board that i bought, nothing on the manuals and can't see any speaker on the board... It is a "RFID Proximity Entry Door Secure Lock Access Control System"

Thanks.


texts: Will analog servo work with Arduino servo library?

texts:
I ordered some cheap servos from Amazon before I noticed that there seemed to be two different kinds (digital & analog).

Mine are Tower Pro SG90 Analog (http://www.towerpro.com.tw/product/sg90-analog/)

I was trying to get mine to work with an extremely simple sample code (below) using the Arduino Servo library (using digital pin 3) and I was experiencing the jitters.

I read over the solutions at : https://electronics.stackexchange.com/questions/77502/is-there-a-way-to-stop-servos-from-shaking

While reading that I learned that there is also a digital flavor of the servo:
http://www.towerpro.com.tw/product/sg90-7/

I'm wondering if that is part of the problem I'm seeing with the servo jittering.  I haven't seen this addressed elsewhere.

My questions are:

Are those servos even different? Maybe that is just a marketing
thing??
Do I need to switch to using an analog pin for the servo data
    connection?
Is it even possible to use the Arduino Servo library for this
purpose or do I need to use some manual code (like analogWrite()) and move the servo to an analog pin?
Or, should it work completely fine and the jittering is just some
unrelated problem?

Here's the simple code I'm using:

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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

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

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


texts:
I am working on a school project for next week
And I need my Arduino to 'sense' at which direction it is moved is it possible? Are there any direction sensors that 'sense' at which direction the Arduino is moving?


texts: SoftwareSerial + Serial.printlen() not working properly

texts:
I want to read a SMS message , find it's length and do some "substring();" operation on received SMS. My last two(2) statements do not work . How can I get correct answers? What are correct codes ?

#include <SoftwareSerial.h>
#include <string.h>
#include <ctype.h>
SoftwareSerial mySerial(2,3);

String TelephoneNumberText="";

void setup()
{
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);

  mySerial.begin(9600);
  Serial.begin(9600);
  delay(100);

  mySerial.println("AT+CMGF=1\r");    //Sets the GSM Module in Text Mode
  delay(500);
}

void loop()
{

 while(mySerial.available())
  {
   char s;
   s = mySerial.read();
   TelephoneNumberText = TelephoneNumberText + s;
   }

 Serial.println(TelephoneNumberText);           // this statement works

 Serial.println(TelephoneNumberText.length());  // this statement dose not works

 Serial.println(TelephoneNumberText.substring(0,3));// this statement dose not works

} // end loop


texts: Register writing by compound assignment and pointer in Arduino due

texts:
I'm confused with register wrting method by compound assignment and/or pointer because I don't know where are some of the values come from.
Example 1
REG_PMC_PCER1 |= PMC_PCER1_PID36;  // Enable PWM - Peripheral Identifiers 36

This works the same as REG_PMC_PCER1 = (1<<4)
REG_PMC_PCER1 is not readable, so |= operator shouldn't work.
What is PMC_PCER1_PID36 ? Is the some sort of bit mask defined in the IDE ?

Example 2
PMC->PMC_PCER0 |= PMC_PCER0_PID13;   // PWM controller power ON

This works the same as REG_PMC_PCER0 = (1<<13)
This is similar to Example 1 but there is pointer PMC. Why it's needed ? If PMC_PCER0_PID13 is a bit mask then REG_PMC_PCER0 need not indexing.

So my questions are:

Why compound assignment works on write-only registers ?
Where are those constants (PMC_PCER1_PID36,PMC,etc.) defined ?

Thanks in advance !


texts: Minimum current or power for Arduino Mega

texts:
I wanted to use the cigarette lighter receptacle of a car as the power supply for the Arduino Mega. From 12 V, I will convert it to a 7 V supply, but my problem is, what must be the minimum current or electrical power to be fed into the Arduino Mega?

And are there any things I have to do to the Arduino Mega 2560 for it to function well in supplying it a 7 volts supply from a car?


texts: teensy as a keybooard throws error as keyboard input

texts:
I have a program (bash script) I wrote that is for stop motion animation. The script works perfectly, when I use any given keyboard on my laptop, and it works on other computers, as well.  So i wanted to add a controller, using a teensy, and the keyboard library. source here:

The teensy, set up as a keyboard, using one of the example codes, which I modified. The output appears correct: when I press any of the buttons, I get the expected output (asdw). But, the script throws an error, and exits anyhow, which means something else is being sent besides the key presses I desire.

So, WHY?
Here is the keyboard source for the teensy:

 /* Buttons to USB Keyboard Example

   You must select Keyboard from the "Tools > USB Type" menu

   This example code is in the public domain.
*/

#include <Bounce.h>

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);  // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10);  // which is appropriate for
Bounce button3 = Bounce(3, 10);  // most mechanical pushbuttons
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 10);  // to rapid touch, you can
Bounce button7 = Bounce(7, 10);  // increase this time.
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);

void setup() {
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);  // Teensy++ LED, may need 1k resistor pullup
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
}

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button0.update();
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();

  // Check each button for "falling" edge.
  // Type a message on the Keyboard when each button presses
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
  if (button0.fallingEdge()) {
    Keyboard.println("s");
  }
  if (button1.fallingEdge()) {
    Keyboard.println("d");
  }
  if (button2.fallingEdge()) {
    Keyboard.println("w");
  }
  if (button3.fallingEdge()) {
    Keyboard.println("a");
  }
}

What should I do to just get the key presses (asdw) from the teensy as if it were a plain old keyboard.


texts:
i need to read from my ESP32/ESP8266 some SNMP V2 OID values from my home printer: it exists a library/method that can do that?
I've seen some SNMP agents, but they works only with the devie as server and not as SNMP client.
Any thoughts?


texts: ML8511 Sensor, unable to achieve meaningful results. Output voltages are atypical

texts:
Problem: ML8511 Sensor, unable to achieve meaningful results.  A mapping to the voltage output yields values that are unrealistically high. Variance is greater than expected [by me], and sensitivity, if any is questionable. In essence, the sensor reports high levels of UV whether is a dimly lit room, or exposed to daylight.

Background:
The interface is simple enough, and Google Search renders numerous hits, e.g., https://learn.sparkfun.com/tutorials/ml8511-uv-sensor-hookup-guide
All coding examples I have seen are akin to the one shown by Sparkfun.

Prior experience: I have a number of other Arduino devices running my sketches that record, collect, analyse, distribute, transmit and display findings.  All of these work as intended.

Observations:  I have spent a lot of time trying to make sense of the behaviour i observe with the sensor output, but have been unsuccessful. I have used two different sensors [same model], and switched UNO boards.  I've removed all other connections to the board, reverted to using the example code, then to code measuring only pinout values.  I have also measured pin voltage via voltmeter for both the output signal and the 3.3 volt reference pin..  According to specs, the sensor outputs voltage correlate with UV levels, and calibration is achieved via a known voltage reference level.

Based on a 3.3 volt reference, the sensor should output 1 to 3 volts, which can be mapped to a UV Intensity (mW/sq cm) range of 0 to 15.  My output voltages range from 2.8 to 3.2 v, the last of which is seemingly out of specs.
I have also used different sample sizes that comprise a data point, but that has little effect, but since the underlying values are out of range, it really would not matter.
Although cheap sensors such as this are not known for great accuracy. I find that they generally work rather well.

My supposition is that:
a) I am working with defective [abeit new] sensors.
b) This particular model of sensor functions in an atypical manner.
c) Being unexperienced in such, I an overlooking something glaringly obvious to others.
d) Somehow my perception of reality is defective.
e) I have truly entered into the Twilight Zone.

Seeking: Information that supports or refutes my observations.  Ideas that I might use to further isolate/ identify the problem.  A solution to the problem.

Image of item used

ML8511 UV Intensity Graph from specs

[

Typical ML8511 Wiring Diagram, the GYML8511 also has an additional connector for 5V, which I have tried both connected and disconnected, not understanding the board behaviour.


texts: What is using up all the RAM in my program?

texts:
I am running a program on the ATtiny and for some reason I am way over the 512 bytes of RAM that are available to me. This is confusing because when I did the math by hand I should have 432 bytes. Here is my code:

#include <SoftwareSerial.h>

#define FASTADC 1

// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

SoftwareSerial mySerial(0,1);    //This uses 47 bytes of RAM

byte i = 0;      This uses 1 byte of RAM

byte pixelsArray1[128];   //Arrays use 128 bytes of RAM each
byte pixelsArray2[128];
byte pixelsArray3[128];

void setup()
{
#if FASTADC
// set prescale to 16
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
cbi(ADCSRA,ADPS0);
#endif

pinMode(1,OUTPUT);        //Setting the 1 pin to be used for output
pinMode(0,OUTPUT);        //Setting the 0 pin to be used for output
pinMode(A3,INPUT);         //Input for Camera 3
pinMode(A2,INPUT);         //Input for Camera 2
pinMode(A1,INPUT);         //Input for Camera 1

mySerial.begin(9600);     //Setting the data transfer rate
}

It's telling me that I am using 510 Bytes of memory but my math gave me 432 bytes of RAM. Does anyone see what I'm missing?


texts: Connecting a sensor to the 5V pin shorts Arduino Nano

texts:
I bought an ultrasonic distance sensor seen here: http://arduinobasics.blogspot.co.uk/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html?m=1. As per the wiring diagram I connect it to the ground and 5V pins on my Arduino Nano which is powered via USB.

As soon as I connect the 5V to the sensor it shorts and the lights on the Arduino go out and my laptop says 'usb surge too much power being drawn'. Do I need to add a resistor to the circuit? It all works fine and I get a result when the sensor is connected to the 3V3 pin but it does not ping properly.

I have tried using an external power supply via a breakout board as well as usb mains plug but both still short. Any help would be much appreciated!


texts: Arduino randomly does incorrect addition

texts:
I've been trying to make an accelerometer calibration tool for my Arduino Nano and MPU6050, but the arduino seems to randomly do incorrect addition. If you look at the output of the console, it works fine for the first 4 iterations, then on the fifth, decides that -31904+-7964 is equal to 25668. It is supposed to be -39868. It does this every time I run it, usually between the 3rd to 6th iteration, but with different numbers.

bool calix = true; //X calibrated or not
      while(calix)
      {
        accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
        Serial.print("PrevAvgX: "); Serial.println(axo/i);
        Serial.print("Axo: "); Serial.println(axo);
        Serial.print("RawX: "); Serial.println(ax);
        axo = (float)ax + (float)axo;
        i += 1;
        Serial.print("Axo2: "); Serial.println(axo);
        Serial.print("RawX: "); Serial.println(ax);
        float cax = axo/i; //Current Average (x)
        Serial.print("AverageX: "); Serial.println(cax);
        delay(100);
        accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
        Serial.print("NewX: "); Serial.println(ax);
        float offsettocurrent = ax-(axo/i);
        Serial.print("AverageX-RawX: "); Serial.println(offsettocurrent);
        if(offsettocurrent>5 or offsettocurrent<-5)
        {
          Serial.println("Offset not accurate enough. Continuing.");
        }
        else
        {
          Serial.println("Offset accurate enough. Finishing calibration");
          break;
        }
        delay(100);
      }

Serial console output:

Initializing I2C devices...
Testing device connections...
Connected to MPU6050
Attempting full calibration
PrevAvgX: -1
Axo: 0
RawX: -8048
Axo2: -8048
RawX: -8048
AverageX: -8048.00
NewX: -8028
AverageX-RawX: 20.00
Offset not accurate enough. Continuing.
PrevAvgX: -8048
Axo: -8048
RawX: -7940
Axo2: -15988
RawX: -7940
AverageX: -7994.00
NewX: -7964
AverageX-RawX: 30.00
Offset not accurate enough. Continuing.
PrevAvgX: -7994
Axo: -15988
RawX: -7972
Axo2: -23960
RawX: -7972
AverageX: -7986.00
NewX: -8016
AverageX-RawX: -30.00
Offset not accurate enough. Continuing.
PrevAvgX: -7986
Axo: -23960
RawX: -7944
Axo2: -31904
RawX: -7944
AverageX: -7976.00
NewX: -8016
AverageX-RawX: -40.00
Offset not accurate enough. Continuing.
PrevAvgX: -7976
Axo: -31904
RawX: -7964
Axo2: 25668
RawX: -7964
AverageX: 5133.00
NewX: -7944
AverageX-RawX: -13077.00
Offset not accurate enough. Continuing.


texts: can we make Drone with Dc 180 motor and Arduino?

texts:
I want to make a drone as a project for my university, But I am kinda newbie in this, I did many searches about this and I found I should do it with the brushless motors (BLDC) but I can't buy this kind of motors, So I want to do it with DC motors I found in youtube there is motor can be used in the drone it called ( 180 dc motor) but they didn't use them with Arduino.
My question is can I use Dc 180 motor with Arduino and make a drone Or Not?


texts: AVCC and AREF when using a reference voltage lower than 5V?

texts: I'm designing a circuit that will use a 2.5v reference for the AREF. Should AVCC be powered from 5V or 2.5V?


texts: Which Arduino-compatible microcontroller for 2 continuous analog audio recording and 2 digital pin snapshots every second?

texts:
Apologies if the title is not very well worded. I'm new to electronics and trying to learn more about embedded systems too. I have a small project that requires recording an analog audio input at 8-bit at 40kHz and saving it every second in a SD card.

Although I know that I can do that with an ATmega328P chipset, I'm not sure if the processing power of ATmega328P will be good enough for further extension of the project.

Ideally I would like to be able to record two sound sources at the same time at around 40kHz -- 16 or 24-bit would be perfect, and capture two sensory data also every second.

This device should be able to run on a reasonably sized battery for at least two hours, but ideally up to eight hours.

I do like the idea of working on a AT91SAM3X8E chipset, but I'm afraid this might be an overkill for such a small project and the current draw of a Cortext-M3 series might be too much for this project too.

My question therefore is would a ATmega328P or ATmega2560 be suitable for such requirements -- in terms of processing power, or do I have to upgrade to something like the AT91SAM3X8E?


texts: Ignoring the first high output from the sensor

texts:
If the vibration sensor with Arduino detects two high inputs within 1 minute, I want the led to flash in one second.
My ability to write Arduino code is very low; I tried with millis() but I couldn't.
I want it to ignore the first high entrance.
Thank you for all the information you will give.
const byte sensor = 7;
const byte LED = 13;
unsigned long sensorMillis;
unsigned long ledTurnedOnAt;
unsigned long high_1 = 60000UL;
bool ledState = false;

void setup() {
  pinMode(sensor, INPUT);
  pinMode(13, OUTPUT);
}

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

  if (digitalRead(sensor) == HIGH) {
    sensorMillis = currentMillis;
    ledstate = true;
  }

  if (ledstate == HIGH) && ((unsigned long)(currentMillis - ledTurnedOnAt) <= high_1) {
    digitalWrite(8, HIGH);
    delay (1000);
    digitalWrite(8, LOW);
  }

  ledstate = false;
}


texts: Directly read analog voltage using PWM duty cycle timer registers

texts:
I'm outputting an analog voltage by setting an 8-bit duty cycle using analogWrite. Once set, I'd like a way to read back this duty cycle. I've managed to read the duty cycle back from the OCR4D register, which matches the value set, e.g.:

pinMode(6, OUTPUT);
analogWrite(6, 123);
Serial.print(OCR4D);   // 123

However, when setting the duty cycle to 0 or 255, OCR4D is not actually set at all; instead analogWrite calls digitalWrite behind the scenes and the pin is digitally set to LOW or HIGH. This is seen in the source for analogWrite:

if (val == 0)
{
    digitalWrite(pin, LOW);
}
else if (val == 255)
{
    digitalWrite(pin, HIGH);
}
else
{
// set PWM duty cycle as normal...

The problem with this is that OCR4D is simply left at its previous value, so it's not always possible to tell the actual output by reading OCR4D alone. In other words there is no way to tell the difference between:
- PWM is active and OCR4D reflects the duty cycle
- PWM is disabled and OCR4D reflects a previous duty cycle (which is not useful)

Which register(s) can I read to crosscheck the PWM is active?

I'm also aware of the pulseIn function, but would rather read the PWM register directly.


texts:
I'm looking to drive two DC motors (on a toy RC car) using a Seeeduino and Seeed Motor Shield V2, but can't manage to get the power scheme right. Right now, a 9V battery connected to the shield powers everything (i.e. LEDs are illuminated on the shield and seeeduino), but when I try running the motors everything flickers and the motors don't move (I assume this is because there isn't enough current). I've managed to get them working when plugging a USB and 9V battery (at the same time) into the seeeduino, as well as when plugging a 9V into the seeeduino and another into the shield (at the same time). Both of these configurations leave me feeling uneasy, as I'm not sure how the power sources will interact.

Further, there is a jumper (MB_EN) on the shield which, according to my research, should isolate the shield from the seeeduino when removed. The documentation (http://www.seeedstudio.com/wiki/Motor_Shield_V2.0) alludes to the fact that this jumper doesn't work, however. Indeed, when I try removing it, power is lost altogether.

I've found conflicting answers to this problem, none of which seems definitive. I've also found tutorials where people did exactly the same thing (with a proper arduino, mind you...) by plugging a single 9V battery to the shield. This should be possible.

I've exhausted just about every resource I can think of, and have spent innumerable hours searching up a solution -- nothing yet. Any help would be great.


texts: Avrdude can't connect to butterfly programmer

texts:
I'm trying to upload my exported HEX file by avrdude using this command

/Users/user_acc/Downloads/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Users/user_acc/Downloads/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/cu.usbmodem1421 -b57600 -D -Uflash:w:/Users/user_acc/Documents/Arduino/at_command_A6/at_command_A6.ino.with_bootloader.leonardo.hex:i

But instead of loading the file it's stuck on connecting to programmer.

Output: https://scr.hu/rYNzzm
https://paste.ubuntu.com/p/74p37fGYPN/

The output from ArduinoIDE is exactly the same and it finds the programmer without the problem and loads the file.

/private/var/folders/5h/7rxp3rmn5351zh6r8cxhz1sr0000gn/T/AppTranslocation/5C2325EE-CF38-4140-8860-717C9DBAF376/d/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/private/var/folders/5h/7rxp3rmn5351zh6r8cxhz1sr0000gn/T/AppTranslocation/5C2325EE-CF38-4140-8860-717C9DBAF376/d/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/cu.usbmodem124 -b57600 -D -Uflash:w:/var/folders/5h/7rxp3rmn5351zh6r8cxhz1sr0000gn/T/arduino_build_78519/at_command_A6.ino.hex:i

Output: https://scr.hu/M72NaV

Can somebody help me? :)


texts: Difference between PWM and regular output port for servos?

texts:
I have been controlling my servomotors for a while now only using pin 0. After some research, it has became apparent to me that the ports with ~ are the PWM pins.

I thought that all pins sent out PWM signals, therefore the motor was able to move back and forth. Now I'm really confused as to how the motor was able to turn without using a ~ pin like pin 5.

Can someone explain why I should or should not use PWM signal when controlling a motor?


texts:
when I connect VCC pin to the 5V and GND to the GND on the Arduino MEGA, then sometimes the display glows and sometimes it doesn't. It kinda looks like some contacts are bad because it starts to work mostly when I move it somehow, but I'm sure the problem is not in contacts as they defintely touch.
I also measured voltage on the display and it showed correctly ~5V.
Where could be the problem? Thanks
//Edit
I am using those displays to build simple autopilot panel for MSFS20 using MobiFlight. There is not any code, you just have to define what pins you connected and that's it. But even if it turns on, then all the leds stay on.
There might be a problem since I soldered the pins into the display so I could damage the board, it's a cheap one from China. Is there a way how to test if it's a board problem?


texts: Multiple SPI reads slows down read time dramatically

texts:
I have a two channel 24bit ADC(LTC2402- http://cds.linear.com/docs/en/datasheet/24012f.pdf) that I am communicating with via Arduino Leonardo(Leonardo because it was free!). If I attempt to do multiple reads the SPI becomes very slow while if I do a single read the time to send is what is expected. I have have integrated with python and timed the different transactions. A single read takes around 170ms( this is for both channels and the datasheet of the ADC indicates about 65ms per conversion(table 3 arduino as external sck etc.)) BUT if I do 5 reads the time taken is about 1.5s(expected about 0.65s) 10 reads take about 3s and 20 about 6.5s. Doing no ADC conversions and just serial comm to python is less than 2ms.

The relevant python code is as follows:

def getdata(ser,code):#ser is the arduino that has been connected, code is for writting to arduino
    ser.write(code)
    ch0=float(ser.readline().decode()[:-2])
    ch1=float(ser.readline().decode()[:-2])
    return ch0,ch1

code='1'
code=code.encode()

a=datetime.datetime.now()
ch0,ch1=getdata(ser,code)
b=datetime.datetime.now()
print(b-a)

The arduino code is as follows. The code has been simplified to just the necessary byte reads from the ADC, all other code has been removed to ensure the delays are coming from the SPI.transfer(0x00). The full code retrieves 4 bytes per channel and converts this to voltage and returns these values.

#include <SPI.h>

const int ltcs = 3; //active low ADC enable

float ch0=0.0;
float ch1=0.0;
byte b0;

void setup() {
SPI.begin();
SPI.beginTransaction(SPISettings(200000, MSBFIRST, SPI_MODE0));

Serial.begin(9600); // set the baud rate

pinMode(ltcs, OUTPUT);
digitalWrite(ltcs, LOW);
}

void loop() {
if(Serial.available()){

   int data = Serial.read() - '0';
   if(data>0){

   getdata2(ch0,ch1);
    //getdata2(ch0,ch1); //run multiple getdata2 to test multiple conversions
   //getdata2(ch0,ch1);
    //getdata2(ch0,ch1);
   //getdata2(ch0,ch1);

    Serial.println(0.2);
    Serial.println(0.4);

  }
  }
  }

 void getdata2(float &ch0, float &ch1) {
   ch0 = 0.0;
   ch1 = 0.0;

   for (int i = 0; i < 2; i++) { //Do twice to retrieve both Channels
     while (digitalRead(MISO) == HIGH) {
     }

       b0 = SPI.transfer(0x00);
       b0 = SPI.transfer(0x00);
       b0 = SPI.transfer(0x00);
       b0 = SPI.transfer(0x00);
   }
   }

Can anyone help me? I have tried different SPISettings with no change. Interestingly I also find that the Baud rate does not change either.

Thanks for the help if any


texts: I2C communication between Arduino Uno and Nodemcu32-s (ESP32)

texts:
I want to send data between an ESP-32 (NODEMCU-32S) and an Arduino Uno but I haven't found any source on how to do that, so I tried this code:
ESP-32 code:
#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin(21, 22);      /* join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}

void loop() {
  Wire.beginTransmission(8);
  Wire.write(3);  /* sends hello string */
  Wire.endTransmission();  /* stop transmitting */
  Wire.requestFrom(8, 18); /* request & read data of size 13 from slave */
  while (Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
  }
}

And Arduino code:
#include <Wire.h>

void setup() {
  Wire.begin(8);                /* join i2c bus with address 8 */
  Wire.onReceive(receiveEvent); /* register receive event */
  Wire.onRequest(requestEvent); /* register request event */
  Serial.begin(9600);           /* start serial for debug */
}

void loop() {
  delay(100);
}

// function that executes whenever data is received from master
void receiveEvent(int howMany) {
  while (0 < Wire.available()) {
    int c = Wire.read();        /* receive byte as a character */
    Serial.print(c);            /* print the character */
  }
}

// function that executes whenever data is requested from master
void requestEvent() {
  Wire.write("hello esp");
}

But I found that no data was sent.
I connected pin 21 to A4 and 22 to A5 directly.
I cannot find where the problem is. Also, I don't know whether the device address is correct or not, since when I tried an I2C scanner it didn't discover any device.
Also, I hope that there is a similar method to have two-way UART communication between the Arduino and ESP as I found none since I need both chips to send data to each other.


texts: Understanding the contents of a library in C

texts:
So this is a question not just about the #include  but most all includes you find while programming in C.

So I understand a library is prewritten code and when you include that library are you able to used certain function that are included in that library.

What I have always wanted to know is: where can you find the "instruction set", in C, for these libraries?

How can I find out what commands are available for me to use with this library?

hope this makes sense.

thank you everyone.


texts: Transfer analog value via Bluetooth HC-05 (master) to second HC-05 (slave)

texts:
II have setup a UNO and a HC-05 Bluetooth module as a 'Slave', and a NANO and an HC-05 Bluetooth module as 'Master', I believe the comm's work ok as I am receiving values and text, but the analog IN via a pot on the 'Master' (NANO) reads fine on the master Serial Screen, but does not read the same on the Slave (UNO)serial screen,the values received are changing from accurate to inaccurate on during data transfer.
I was hoping for a continuous accurate stream as the pot will be replaced with a 'load cell' and I need to capture weight readings and display them on a time base, I used bluetooth as the load cell and 'Slave' will be approx 5m apart. I would appreciate any help and I can send the sketch if you wish?
Regards, Gordon


texts: what is the right way to parse JSON to Arduino?

texts:
i am trying to Turn an LED from a hosted website, though Arduino using the CC3000 wifi shield. It is working as it should. but i have to questions about optimising my code :

1) the Part where i parse my JSON is kind of sloppy, what is the right way to Parse the code so i can turn the LED on and off when clicking on the website buttons ?

2) i need to keep the arduino connected to the website, so i can always control the LED. Do i need to close the connection at the end ? if so, how can i activate the connection only when clicking the button on the website to active the LED.

#include <ArduinoJson.h>

// Include Libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>

// Define Pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// Define Variables
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER);

#define WLAN_SSID       "MyWeb"
#define WLAN_PASS       ""
#define WLAN_SECURITY   WLAN_SEC_UNSEC // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2

uint8_t dhcpTimeout;

#define host "mygarden.comli.com" // Your domain
uint32_t ip;
String path   = "/light.json";
int port = 80;

int pin = 9;

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

  pinMode(pin, OUTPUT);
  pinMode(pin, HIGH);

  // Connect to Wifi
  cc3000.begin();
  Serial.println(F("Initialising the CC3000"));
  if (!cc3000.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while(1);
  }

  /* Delete any old connection data on the module */
  Serial.println(F("Deleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while(1);
  }

  // Connect to Network
  beginning:
  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected"));

  //Wait for DHCP to complete
  Serial.println(F("Requesting DHCP"));
  while (!cc3000.checkDHCP()) {
    delay(500);
    Serial.print(F("."));
    dhcpTimeout ++;
    if (dhcpTimeout == 60) {
      Serial.println(F(""));
      Serial.println("DHCP Timeout! Attempting to reconnect.");
      dhcpTimeout = 0;
      goto beginning;
    }
  }
  Serial.println(F(""));
  Serial.println(F("DHCP complete"));

  //get website IP
  ip = 0;
  Serial.print(host); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(host, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }
  cc3000.printIPdotsRev(ip);
  Serial.println("");
}

void loop(void) {

  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);

  client.print(String("GET ") + path + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: keep-alive\r\n\r\n");
  delay(500); // wait for server to respond

  Serial.println(F("----------"));
   while (client.connected()) {
    String response = "";
    bool begin = false;
      while (client.available() || !begin) {
      char c = client.read();
      if (c == '{') {
        begin = true;
      }
      if (begin) response += (c);
      if (c == '"}') {
        break;
      }
      delay(1);

      }
      int start = response.indexOf("light\":\"") + 12;
      int end = start + 3;
      String LED_Control = response.substring(start, end);

      if (LED_Control == "onn") {
        digitalWrite(pin, HIGH);
        Serial.println("LED ON");
      }
      else if (LED_Control == "off"){
        digitalWrite(pin, LOW);
        Serial.println("led OFF");
      }

   }

  delay(1000);
  Serial.println(F("\n\nClosing the connection"));
  client.close();
  cc3000.disconnect();

}

And this is my JSON output

{"light": "off"}


texts:
I need to read acceleration data with ADXL335 using ARDUINO MICRO (or NANO) and send this data with RS485 module to another RS485 module connected to an ARDUINO UNO (300m between RS485 modules). Treated to use the codes below but slave does not receives any data.
Data from AXDL335 are in the form "xxx  yyy  zzz"
Do I need to write in a "string format" before send with RS485 (master)??
Many thanks in advance!!

master code

#include <SoftwareSerial.h>
#define SSerialRX   10
#define SSerialTX   11
#define SSerialTxControl  3
#define RS485Transmit  HIGH
#define RS485Receive  LOW
int x;                                                // channel X  ADXL335
int y;                                                // channel Y  ADXL335
int z;                                                // channel Z  ADXL335
SoftwareSerial RS485Serial(SSerialRX, SSerialTX);
void setup() {
  Serial.begin(9600);                                 // configure baud rate monitor

  pinMode(SSerialTxControl, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Receive);
  RS485Serial.begin(4800);                            // starts serial(485) and configure baud rate
}

void loop() {

 x=analogRead(0);                                     //read X in analog(0)
 y=analogRead(1);                                     //read Y in analog(1)
 z=analogRead(2);                                     //read Z in analog(2)
                                                      // print read values in monitor
 Serial.print(x);Serial.print(" ");Serial.print(y);Serial.print(" ");Serial.print(z);Serial.println(" ");
 RS485Serial.print(x);
 delay (250);

 RS485Serial.flush();
 delay (750);
 }

SLAVE CODE

#include <SoftwareSerial.h>
#define SSerialRX   10
#define SSerialTX   11
#define SSerialTxControl  3
#define RS485Transmit  HIGH
#define RS485Receive  LOW
char x;
SoftwareSerial RS485Serial(SSerialRX, SSerialTX);

void setup() {
  Serial.begin(9600);        // configure baud rate monitor
  pinMode(13, OUTPUT);
  pinMode(SSerialTxControl, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Receive);
  RS485Serial.begin(4800);  // start serial(485) and configure baud rate
}

void loop()
{
 if (RS485Serial.available()>0) {
  x = RS485Serial.read();
  if (x!="n")

  Serial.print(x);Serial.println(" ");
  delay(1000);

 }
}


texts:
I have a problem with linefollower which detects line with infrared sensors and follows it, but I would like it to detect obstacles with an ultrasonic sensor. I would like the robot to stop after detecting an obstacle, and when it is removed, it continued along the line. What am I doing wrong in the code that the robot does not stop after detecting an obstacle, but continues on the line?
int mot1=9;
int mot2=6;
int mot3=5;
int mot4=3;
int Trig = 4;
int Echo = 2;
int CM;
long CZAS;
int left=13;
int right=12;
int Left=0;
int Right=0;
void LEFT (void);
void RIGHT (void);
void STOP (void);

void setup()
{
 pinMode(mot1,OUTPUT);
 pinMode(mot2,OUTPUT);
 pinMode(mot3,OUTPUT);
 pinMode(mot4,OUTPUT);

 pinMode(left,INPUT);
 pinMode(right,INPUT);

 digitalWrite(left,HIGH);
 digitalWrite(right,HIGH);

 pinMode(Trig, OUTPUT);
 pinMode(Echo, INPUT);

}

void loop()
{

analogWrite(mot1,255);
analogWrite(mot2,0);
analogWrite(mot3,255);
analogWrite(mot4,0);

while(1)
{
 Left=digitalRead(left);
 Right=digitalRead(right);

 if((Left==0 && Right==1)==1)
 LEFT();
 else if((Right==0 && Left==1)==1)
 RIGHT();
}
}

void pomiar_odleglosci ()
{
 digitalWrite(Trig, LOW);
 delayMicroseconds(2);
 digitalWrite(Trig, HIGH);
 delayMicroseconds(15);
 digitalWrite(Trig, LOW);
 digitalWrite(Echo, HIGH);
 CZAS = pulseIn(Echo, HIGH);
 CM = CZAS / 58;
 if(CM < 25)
 {
 analogWrite(mot1,0);
analogWrite(mot2,0);
analogWrite(mot3,0);
analogWrite(mot4,0);
}

else{
}
}
void LEFT (void)
{
  analogWrite(mot3,0);
  analogWrite(mot4,30);

  while(Left==0)
  {
   Left=digitalRead(left);
   Right=digitalRead(right);
   if(Right==0)
   {
     int lprev=Left;
     int rprev=Right;
     STOP();
     while(((lprev==Left)&&(rprev==Right))==1)
     {
        Left=digitalRead(left);
        Right=digitalRead(right);
     }
   }
   analogWrite(mot1,255);
   analogWrite(mot2,0);
  }
  analogWrite(mot3,255);
  analogWrite(mot4,0);
}

void RIGHT (void)
{
  analogWrite(mot1,0);
  analogWrite(mot2,30);

  while(Right==0)
  {
   Left=digitalRead(left);
   Right=digitalRead(right);
   if(Left==0)
   {
     int lprev=Left;
     int rprev=Right;
    STOP();
     while(((lprev==Left)&&(rprev==Right))==1)
     {
        Left=digitalRead(left);
        Right=digitalRead(right);
     }
   }
   analogWrite(mot3,255);
   analogWrite(mot4,0);
   }
  analogWrite(mot1,255);
  analogWrite(mot2,0);
}

void STOP (void)
{
analogWrite(mot1,0);
analogWrite(mot2,0);
analogWrite(mot3,0);
analogWrite(mot4,0);

}


texts: How to connect MCP4141 digipot and a data logger shield to the same Arduino board

texts:
The main problem here is that they both need to communicate via the Arduino's SPI bus, and I know that each of the two devices will need its own CS pin (The data logger is hard wired to 10, so the digital potentiometer will need a different one)

This would be fine, except that the digital potentiometer has one pin for both SPI and SDO.
I read that to connect this to the Arduino, the shared pin on the digipot needs to be connected to the MISI pin on the Arduino (pin 12) and then to bridge the MISO pin to the MOSI pin with a resistor.

Would anyone be able to tell if this will work. I do not want to try connecting the two devices like this just in case it breaks something in the board.

Thanks


texts:
I am trying to replicate Low power LED firefly project. So what I'm trying to do is to do an analog read from a LED, to detect light. To simplify it a bit, I am using different pins and different leds for IN and OUT. The code:

#define PIN1 don't use this pin! /*this is RESET*/
#define PIN2 3
#define PIN3 4
#define PIN4 don't use this pin! /*this is GND*/
#define PIN5 0
#define PIN6 1
#define PIN7 2
#define PIN8 don't use this pin! /*this is VCC*/
#define ANL1 PIN7
#define ANL2 PIN3
#define ANL3 PIN2

// the setup function runs once when you press reset or power the board
void setup() {
  digitalWrite(PIN3, LOW);
  pinMode(PIN3, INPUT);
}

#define BLINK true
// the loop function runs over and over again forever
void loop() {

  const int value = analogRead(PIN3);
  if(value>=1023) {
    pinMode(PIN2, OUTPUT);
    digitalWrite(PIN2, HIGH);
    delay(500);
    digitalWrite(PIN2, LOW);
    delay(3);
  }
  else {
    delay(1);
  }
}

This is the setup. I am using much smaller resistor, but I'm still getting 1023 on analog read, as indicated by the output led always being on:

simulate this circuit – Schematic created using CircuitLab

What's wrong?


texts:
I have a serial ISP programmer of protocol type "stk500v1" which expects 115200 baud data rate. I have used it successfully with Atmel Studio by calling avrdude manually (custom tool) in the past. This just involves the avrdude option

  -b 115200

But recently I wanted to do use the Arduino software instead of Atmel Studio for a quick mockup. But everytime I try to "Upload with Programmer", the avrdude commandline includes the option

  -b 19200

and so the programming fails.

I can make it work by changing the hard wired serial rate in the programmer from 115200 to 19200, but then of course the programming is dead slow, which I don't want.

I have also looked for a baudrate entry for stk500v1 in "avrdude.conf", but didn't find any. How can I change the baud rate for "Upload with programmer" in the Arduino software?


texts: Control two stepper motors simulatenously?

texts:
I'm using Arduino Mega 2560, A4988 motor driver for 5 stepper motors. There are X1, X2, Y, Z, A axis, and if I control Y and Z at once, it works. But when I just change axis from Y&Z to X1&X2, only X1 stepper motor spins. X1&X2 need to move at once(simultaneously) due to they are connected in single bar.

My Arduino IDE code is,

==============================

const int X2step = 5;

const int X2dir = 4;

const int X1step = 3;

const int X1dir = 2;

void setup() {

    pinMode(X1step,OUTPUT);

    pinMode(X1dir,OUTPUT);

    pinMode(X2step,OUTPUT);

    pinMode(X2dir,OUTPUT);

}

void loop() {

    digitalWrite(X1dir,HIGH);

    digitalWrite(X2dir,HIGH);

    for(int x = 0; x < 4000; x++) {

        digitalWrite(X1step,HIGH);

        delayMicroseconds(2000);

        digitalWrite(X1step,LOW);

        delayMicroseconds(2000);

        digitalWrite(X2step,HIGH);

        delayMicroseconds(2000);

        digitalWrite(X2step,LOW);

        delayMicroseconds(2000);
    }

    delay(1000);

    digitalWrite(X1dir,LOW);

    digitalWrite(X2dir,LOW);

    for(int x = 0; x < 4000; x++) {

        digitalWrite(X1step,HIGH);

        delayMicroseconds(2000);

        digitalWrite(X1step,LOW);

        delayMicroseconds(2000);

        digitalWrite(X2step,HIGH);

        delayMicroseconds(2000);

        digitalWrite(X2step,LOW);

        delayMicroseconds(2000);
    }

    exit(0);

=================================================

Any suggestion would be helpful for me. Thanks.


texts: Leading Zeroes on Arduino Ethernet MAC Address

texts:
How can I pass the MAC address to Ethernet shield with leading zeroes?
I change the default MAC address from DEADBEEFFEED to something like DEADBEEFFE01. So I only change the last number from 0xED to 0x01. My board is communicating to a separate server and when I look at the MAC in that server, my board is listed as DEADBEEFFE1.
It's not as simple as printing the MAC address with padded zeroes as the board is actually removing it.
I've looked at the Ethernet library and I saw that the mac is passed as an array of uint8_t. I think that's why, the last number is read as 1 (which is correct) but passed as just that.
Is there a way for the MAC to pass leading zeroes?


texts:
I am having a problem with my Arduino freezing after a small amount of time. I'm using an RTC DS1307 breakout to keep track of the time and display the time on an LCD. It displays hours, minutes and seconds (updated every second).

Then I have 25V which is supplied by a transformer and connected to a set of LEDs through a CAT4101 constant-current sink LED driver. The Arduino board is powered by a 2amp USB transformer.

At a set time, the timer should set off the process to dim the lights.

Everything is working well if I set the lights to dim within a few minutes. However, if I leave the board on for more than 10-15 minutes then everything seems to freeze (i.e. the time on the LCD stops being updated and stays stuck at the moment it froze).

I originally thought it could have been something to do with my code. But I then skimmed everything down to the bare essential and just uploaded the code necessary to update the time on the LCD. And even in this case it freezes.

The only way I managed to avoid things freezing was to disconnect the CAT4101 pin 1 from Arduino's PWM and disconnect pin 2 from Arduino's 5V.

What could be causing this issue?

CAT4101

pin 1 = connected to Arduino PWM
pin 2 = connected to +5v
pin 3 = connected to ground
pin 4 = connected to ground with 2kOhm resistor
pin 5 = connected to LED cathode

UPDATE

Code below (I have stripped down the code by removing any additional functions and leaving only the bare code which is leading the application to crash).

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

RTC_DS1307 rtc;
DateTime now;
LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);

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

 if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__)); // time = hh:mm:ss format, e.g. 06:01:01
  }

  lcd.clear();
}

void loop() {
  now = rtc.now();
  updateDisplay();
}

void updateDisplay(){
 int h = now.hour(); // Get the hours right now and store them in an integer called h
 int m = now.minute(); // Get the minutes right now and store them in an integer called m
 int s = now.second(); // Get the seconds right now and store them in an integer called s

 lcd.setCursor(0, 0); // Set the cursor at the column zero, upper row...
 lcd.print(" The time is: "); // ...with spaces to clear characters from setting alarm.
 lcd.setCursor(4, 1); // Move the cursor to column four, lower row
 if (h<10){   // Add a zero, if necessary, as above
  lcd.print(0);
 }
 lcd.print(h);   // Display the current hour
 lcd.setCursor(6, 1); // Move to the next column
 lcd.print(":");  // And print the colon
 lcd.setCursor(7, 1); // Move to the next column
 if (m<10){   // Add a zero, if necessary, as above
  lcd.print(0);
 }
 lcd.print(m);   // Display the current minute
 lcd.setCursor(9, 1); // Move to the next column
 lcd.print(":");  // And print the colon
 lcd.setCursor(10, 1); // Move to the next column
 if (s<10){   // Add a zero, if necessary, as above
  lcd.print(0);
 }
 lcd.print(s);   // Display the current second
}


texts:
The problem
Hey. I'm trying to use the sensor Mq131 to measure some ozone data in a closed environment, but I'm having some bad time to adjust the trim in the sensor and get results in ppb. By searching on the internet I could not find any elucidative manual/instruction.

My Hardware set
As my first attempt, I've made the following wiring with the Arduino UNO and the sensor module.

Notice that my potentiometer does not have any indication of the resistance reached when spinning the potentiometer screw.

My software script
To get the value of tension in the output from the sensor I'm using the following approach.
int sensor_AOUT = A1; //connected from AOUT to the sensor to A1 on the Arduino
int sensor_DOUT = 2; //connect DOUT from sensor to Arduino pin 2
int wartosc_AOUT; //variable for the value of AOUT
int wartosc_DOUT; //variable for the value of DOUT

void setup() {
 Serial.begin(9600); //start the monitor serial port
 pinMode(2, INPUT); //set pin 2 as input

}

void loop() {

 wartosc_AOUT = analogRead(sensor_AOUT); //load values from AOUT
 wartosc_DOUT = digitalRead(sensor_DOUT); //load values DOUT

 Serial.print("D0: "); //display on serial monitor
 Serial.print(wartosc_DOUT);
 Serial.print(" -- A0: ");
 Serial.println(wartosc_AOUT);
 delay(200); //delay between consecutive readings
 }

which gives me values 30 < A0 <50. How can I get a value in ppb (parts per billion) and how can I calibrate the potentiometer screw?

Sensor Datasheet
The datasheet of this sensor can be found in this link.


texts: How to handle multiple input pins at once?

texts:
I am relatively new to Arduino platform and not know much. I am working on a Bicycle speedometer with turn and stop indicators.

I am planning on connecting an inductor magnet to calculate the rotation of my front wheel while providing the following services from the same arduino board:

Input horn and turn indicator switches.
Output to turn indicators.
Stop light when one of the brakes is
applied.

While I am sure of how to connect all the sensors, except the magnet, I am not sure how to handle the various inputs and the outputs at once.

I must be able to horn and stuff while the indicator blinks at a regular interval all the while the monitor keeps displaying my speed and distance covered.

Any reference or help would be greatly appreciated.
Thanks in advance.

Bharath. S.


texts: connecting a MPU6050 and sabertooth 2x12 to a single Arduino Uno

texts: so im using the sabertooth speed controller to control the two motors on my lawn mower and im trying to use the MPU6050 to keep the lawn mower straight. The problem im facing is that im trying to use the sabertooth and the MPU6050 on a single Arduino and the sabertooth uses the baud rate of 9600 but the MPU6050 uses 115200 and im trying to use a single .ino file to control everything. I want to receive the data from the MPU6050 and based of that make a program to move the motor so that the mower will go in a straight line and such.


texts:
I'm building a portal gun from the game Portal and I'm struggling with the wiring for the lights and sound. I've the lights working using the first image from Instructables and adding more LEDs shouldn't be a problem. I'm trying to add the SD card and speaker so when you flick the switch, as well as the lights changing, the firing sound is played. Image 2. everything is wired quite nicely the only change is I'm using pin 10 not 4 on the memory card.

This is my code and it all compiles fine and seems to make sense to me but I'm new to programming.

The lights work but none of the sounds play. I've formatted the SD card and also made sure the .wav files are the right format: mono 8 bit 16000 Hz. I can't work out what's wrong and why I can't get it to play the sounds.

I also have an Adafruit amp just in case it isn't loud enough but not a clue how to wire it in.

#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>                       // need to include the SD library
#define SD_ChipSelectPin 10            // using digital pin 10 on arduino uno 328, can use other pins
#include <SPI.h>

void setup()
{
  // put your setup code here, to run once:
  TMRpcm tmrpcm;
  tmrpcm.speakerPin = 9;          //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc

  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin))
  {
    Serial.println("SD fail");
    return;
  }
  tmrpcm.setVolume(6);
  tmrpcm.play("1.wav");
  tmrpcm.play("2.wav");

  //set the switch input, pin 8, as an
  pinMode(8, INPUT);

  //set both the LED pins, pin 5 and 6 as OUTPUTs
  pinMode (5, OUTPUT);
  pinMode (6, OUTPUT);
}

void loop()
{
  TMRpcm tmrpcm;
  int switchValue = digitalRead(8);
  if (switchValue == 1)
  {
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    tmrpcm.setVolume(6);
    tmrpcm.play("4.wav");
  }
  else
  {
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
    tmrpcm.setVolume(6);
    tmrpcm.play("5.wav");
  }
}


texts: What data type are the analog pin labels (A0, A1, etc)?

texts:
Arduino Mega

I would like to have an array containing analog pin labels something like...

int analog_pins[] = {A0, A1, A2, A3};
int num_analog_pins = sizeof(analog_pins) / sizeof(analog_pins[0]);

Is this possible? It has compiled without any warnings or errors but I'm dont have my board with me (yes beginners mistake) so cant really check if it works.


texts: Nano onboard "test" LED blinks when powered via 5V pin

texts:
I have a Nano (clone) that I am powering from a regulated supply via the 5V pin; I have checked this at the board and my multimeter reads 4.92V, which seems close enough (?). The main reason I don't use the microUSB jack is a space constraint. In any case, thus far it does work fine.

Except the leftmost (considered with the microUSB jack as "top") of the four onboard LEDs, on the opposite side from the rx/tx lights, blinks at a steady one second interval.  Searching around, the only association I've found for that LED is that it is connected to D13, which I'm not using for anything.

What does this indicate?  I have not tried disabling it (by setting 13 low) but I am hoping to do so if it is a benign issue.


texts: Receiving serial data in acsii, how to split it.

texts:
Hello I want to know how to split an incoming serial message that comes in this format CxxxLxxx, x=number, so i can take the 3 numbers after the C and save them and then take the 3 numbers after the L and also save it, i have a code for this but it doesn't always work, can anyone tell me where I´m wrong or is the approach I´m taking is not the right one. Thanks.

int value = 0;
int channel;
int x;
String str;
int y;
String str1;
int le;

void loop()
{
if (Serial.read() == le)
{ }
  else
       {
        str = Serial.readStringUntil('C');
        str1 = Serial.readStringUntil('L');
        channel = Serial.parseInt();
        value = Serial.parseInt();
      DmxSimple.write(channel, value);
      le = Serial.read();
      Serial.println();

       }
}


texts: Regenerative motor drive for arduino with torque control

texts:
I'm looking for a motor drive for use with an Arduino that fits the following requirements:

Drive brushed or brushless DC motors (I don't mind which)
Regenerative - can feed power back to the supply when slowing the motor
Serial control interface - I don't much care about the details of voltage levels, baud rate etc but I want a serial control interface, not analog/PWM
Torque control mode - most drives have speed control modes where the input specifies a fraction of the maximum speed, but I'm looking for one with a mode where the input specifies a fraction of the maximum torque to be applied
12V, 5A rated supply - there is some flexibility here, but I'm not looking for a 400V, 50A machine.  It needs to be small.  Ideally the motor would be rated about 50VA and we'd be able to work over most of the control input range
Arduino shield footprint would be ideal, but some other fairly standard connector to interface to the arduino would be okay
Ideally would be able to report motor speed over the serial interface, but not essential

Any recommendations for drives that fit these?


texts: How to connect Arduino with ESP8266-11 WiFi module to 000webhost (free webhosting)

texts:
I want to know how to connect my Arduino to my website on 000webhost.com (free webhosting account). I'm using ESP-11 WiFi module and it is connected to the internet.

This is my Arduino code:

#include <SoftwareSerial.h>
SoftwareSerial ESP11 = SoftwareSerial(10,11); // RX, TX
#define DEBUG true

// WIFI SHIELD DECLARATION
String ssid = "\"SampleSSID\"";
String pass = "\"SamplePass\"";
String tcp = "\"TCP\"";
String remoteip = "\"jvystocksystem.000webhostapp.com\"";
String portnum = "80";

void setup(){
  ESP11.begin(9600);
  Serial.begin(9600);
  sendData("AT+CWMODE=1\r\n",2000,DEBUG); // configure as access point and Client
  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  sendData("AT+GMR\r\n",2000,DEBUG); // View version Info
  sendData("AT+CWLAP\r\n",5000,DEBUG); // List all available AP's*/
  sendData("AT+CWJAP=" + ssid + "," + pass + "\r\n",10000,DEBUG); // Connect to AP
  sendData("AT+CIFSR\r\n",2000,DEBUG); // get ip address
  sendData("AT+CIPMUX=0\r\n",2000,DEBUG); //Single TCP Connections
  sendData("AT+CIPSTART="+ tcp +"," + remoteip + "," + portnum + "\r\n",3000,DEBUG); // Start connecting to localhost <link id>,<type>,<remote IP>,<Port Number>

  String getStr = "GET /getCpno.php?user_type=admin HTTP/1.0"; // Getting info from my online database through my online website
  getStr += "\r\n\r\n";
  String cmd;
  // send data length
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  sendData(cmd + "\r\n",1000,DEBUG);
  sendData(getStr,3000,DEBUG);
}

void loop() {
  // put your main code here, to run repeatedly:
// For ESP8266
  if(ESP11.available()) // check if the esp is sending a message
  {

    if(ESP11.find("+IPD,"))
    {
     delay(1000); // wait for the serial buffer to fill up (read all the serial data)
     // get the connection id so that we can then disconnect
     int connectionId = ESP11.read()-48; // subtract 48 because the read() function returns
                                           // the ASCII decimal value and 0 (the first decimal number) starts at 48

     ESP11.find("pin="); // advance cursor to "pin="

     int pinNumber = (ESP11.read()-48)*10; // get first number i.e. if the pin 13 then the 1st number is 1, then multiply to get 10
     pinNumber += (ESP11.read()-48); // get second number, i.e. if the pin number is 13 then the 2nd number is 3, then add to the first number

     digitalWrite(pinNumber, !digitalRead(pinNumber)); // toggle pin

     // make close command
     String closeCommand = "AT+CIPCLOSE=";
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";

     sendData(closeCommand,1000,DEBUG); // close connection
    }
  }
}

/*
* Name: sendData
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/

String sendData(String command, const int timeout, boolean debug)
{

    String response = ""; // ESP8266 sendData String
    ESP11.print(command); // send the read character to the esp8266

    long int time = millis();

    while( (time+timeout) > millis())
    {
      while(ESP11.available())
      {

        // The esp has data so display its output to the serial window
        char c = ESP11.read(); // read the next character.
        response+=c;
      }
    }

    if(debug)
    {
      Serial.print(response);

    }
    return response;
}

But my code is not returning the value I want from the database, instead I'm getting this in my serial monitor:

I hope you guys can help me with my code.


texts: What sensor would work for soccer ball detection efficiently using Arduino?

texts: I want to make a soccer goal counter using Arduino and some sensors. I built using an ultrasonic sensor, but it does not detect if the ball is moving too fast. Are there any other sensors I can use to detect soccer ball?


texts:
I am currently working on a little code which needs to react fast. Here is what I am trying to accomplish:

Using a sine wave phase detector I am detecting every zero crossing and feeding that pulse into the Arduino.

Using an ISR the Arduino detects this zero crossing pulse using RISING. Once one pulse has been detected AND I have pressed a button, I need there to be a delay of 0 - 10ms before switching on an output.

If I don't use an ISR and set a delay of up to 10ms inside the loop, it won't really be 10ms and it will be some other delay, nothing consistent. (I checked with an oscilloscope).

Only when using an ISR and using delayMicrosenconds() inside the ISR I can delay the output consistently for up to 10 ms everytime.

Now I have read that doing this is wrong...Even though it works perfectly. Which better way could I use?

Thanks!

EDIT: While 100% accuracy may not be possible, it needs to be as precise as possible. More important is the repeatability. Using my method I could reproduce the outcome everytime with an accuracy in the nano seconds range.


texts: Arduino Uno's RX and TX lights not blinking. Unable to upload sketches!

texts:
When arduino starts up, RX TX lights doesn't blink. Only the PIN 13 and Green light turns on. Pin 13 light blinks thrice before getting stable. RX TX lights are not blinking at all. I am not able to upload any sketches. The error I get is "Not in sync resp=0x00" or "Programmer not responding" or "Not in sync resp=0x95" or "Not in sync resp=0x69" and so on. A new error everytime. Most probably the error is with serial communication.

A brief history of what I have done

I have a Relay which is operated at 12V. But Arduino works at 5V logic. So I used a comparator (IC741) to improve the logic (By setting Vcc and -Vcc at 12 and 0 and the input pins connected to arduino). I also connected HC-05 bluetooth module to use the relay using my cellphone. You know what I was trying was home automation. Also Arduino was connected to 12V DC supply (I think this was my mistake). Everything was going right.

Suddenly IC741 started burning,maybe I shorted some pins when I was trying to measure the voltages using multimeter. I quickly removed it. Suddenly HC 05 started burning. I immediately removed all the connections. After some time I turned on Arduino again (This time using USB connected to laptop). I connected HC05. The bluetooth module heats up again. I thought the module is now gone. I turned to check Arduino and as I stated I am unable to upload any more sketches. Most probably the bluetooth module cause an error in serial communication. May be not.

So my question is
1. What's the real problem. Is my bluetooth module gone? Or is Arduino gone? If arduino is still fine, how can I get the serial to work back and enable me to upload sketches?
2. If Arduino is gone, most probably the microcontroller Atmega328 is still fine. How can I use it now without Arduino (I don't have any extra Arduino)?

Things I have already tried :

Loopback test : No echo back. Serial data can neither be sent nor received.
When I open the Serial window, Arduino doesn't resets as it it earlier.
RX TX Vin and 5V pin reads 4.99V. I hope they are fine.


texts: 100 hz Square Wave of 50% duty cycle in digital pin 3 and verifying with pin 4

texts:
I am stuck on this for a while, I am trying to generate a 100 hz square wave with 50% duty cycle in pin 3 and trying to verify it with wire at pin 4; I am getting 64000 but not 100 in serial monitor.

#define LEDPIN 3

uint16_t val2= pulseIn(4, HIGH);

ISR(TIMER1_COMPA_vect) { digitalWrite(LEDPIN, !digitalRead(LEDPIN)); }
void setup() {
Serial.begin(9600);
pinMode(LEDPIN, OUTPUT);
// initialize Timer1 (the 16-bit timer) using channel A output compare
noInterrupts(); // disable global interrupts
// TIMER 1 for interrupt frequency 100 Hz:
cli(); // stop interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
// set compare match register for 100 Hz increments
OCR1A = 19999; // = 16000000 / (8 * 100) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12, CS11 and CS10 bits for 8 prescaler
TCCR1B |= (0 << CS12) | (1 << CS11) | (0 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); // allow interrupts
//TCCR1A = 0; // Timer/Counter Control Register 1A
//TCCR1B = 0; // (both control registers need to be configured)
//// set compare match register to desired timer count:
//OCR1A = 15624; // Output Compare Register 1A (i.e., for channel A)
//TCCR1B |= (1 << WGM12); // CTC (Clear Timer on Compare Match) mode
//TCCR1B |= (1 << CS10); // for 1,024 prescaler; UNO has a 16 MHz clock
//TCCR1B |= (1 << CS12);
//TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable global interrupts:
}
void loop() {
uint16_t val = OCR1A/8;

ICR1 = val -1;
OCR1A = val/2 - 1 ; // 50% duty cycle for pin 3
//OCR1B = val/2 - 1 ; // 50% duty cycle for pin 4
//uint16_t val2= pulseIn(4, HIGH);
Serial.print(val2);
delay(1000);
Serial.print("\n");

}


texts: Problem interfacing CR95HF with Arduino Uno

texts: I am interfacing a CR95HF with an Arduino to detect NFC tags. I have taken the code from this link as reference. I am able to get the response to the IDN command, and also set the protocol (ISO/IEC 14443-A). But the tag is not detected. What should I do to detect the tag?


texts:
Looking for some help on this please. It is a little long winded, but the point of it is I cannot retrieve a string response via my ESP8266 ESP-01S.

I connect my ESP to my Ardiuno using SoftwareSerial esp8266(2,3).

I can quite happily send POST and GET commands to my server and process the request server side. This is done through the AT sequence below. My server uses a REST API to receive the request and responds with a simple string (for example 'HELLO'). If I attempt the same client side functionality through C# code or Python on my Pi I receive the response from the server no problem. But on my Arduino the response is always 32 when reading via ESP.read() (which I believe is in bytes and signals end of data). I have also tried esp.readString() and esp.readStringUntil('\n') all with no luck.

Is it not possible to access the response sent back to the ESP using my approach?

I see many examples go down the route of programming the ESP directly. I'm not really looking to do that on this attempt as I am creating some basic Arduino tutorials for family and friends and would prefer to not add that complexity.

Result server response

esp8266.println(postRequest);
while (esp8266.available() > 0) {
  Serial.println("." + esp8266.readString() + ".");
}

So I guess in short, am I wrong in expecting the

//* AT SEQUENCE*
AT
AT+RST
AT+CWMODE
AT+CWJAP
AT+CIPMUX
AT+CIPSTART
AT+CIPSEND

// CREATE DATA

String data = "=DATA1";

// POST

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

// GET

String postRequest =
  "GET " + URI + "?data=" + data + " HTTP/1.1\r\n" +
  "Host: " + HOST + ":" + PORT + "\r\n" +
  "Accept: *" + "/" + "*\r\n" +
  "Connection: keep-alive\r\n" +
  "Content-Length: " + String(0) + "\r\n" +
  "Content-Type: text/plain\r\n" +
  "\r\n";


texts: Are all Arduino shields compatible with all Arduino boards? Like is the Wi-Fi one compatible with the Arduino Nano & Micro as well as the Uno, etc., or do I need to be careful when buying shields that they'll be compatible with my board? Also, the shields just plug into the boards, don't they?


texts: How to restart a counter in a program using a push button in a LDR Tripwire setup

texts:
So, trying to configure this code so that when I push the button, the person counter will go to zero and just as it goes, the counter will increase when the LDR will get tripped and again when the button is pressed, the counter will go to 0.

#include <LiquidCrystal.h>

int laser=8;
int pushbutton=12;
int flag=0;
int myCounter = 0;
LiquidCrystal lcd(7,6,5,4,3);

void setup()
{
    pinMode(laser,OUTPUT); pinMode(pushbutton,INPUT);
    lcd.begin(16, 2);
    lcd.print("Person Counter:"); lcd.setCursor(0,1);
    lcd.print(0);
}

void loop()
{
    lcd.setCursor(0, 1);
    digitalWrite(laser,HIGH);

    if(analogRead(A0) < 600) //A0= LDR
    {
        flag = 1;
    }

    if(analogRead(A0) > 600 && flag == 1)
    {
        myCounter++;
        delay(200);
        lcd.print(myCounter);
        delay(20);
        flag=0;
    }
}


texts: Arduino IDE on Attiny45: What kind of power does a chip need?

texts:
I have this little AtTiny45 which I'm loading a program with Arduino as ISP.
My goal to use this chip along with a op amp, a piezo buzzer and a press button, and have it automatically sleep between uses.
I intend to use 2 3V pill batteries in parallel (specifically CR2032 if this makes a difference) as the power source, so here are my two questions:

Can 2 3V pill batteries in parallel power a small application that will produce audible sound?
How long could these batteries last --based on constant use-- if someone used this item for an hour per day?


texts: How to properly use volatile variables in Arduino?

texts:
I was doing a small project with an Arduino Uno. It involved interrupts as I am using encoders to measure how much the differential wheel system moves forward. My robot moves only forward. So I use only a single channel from each encoder. Here are my two interrupt routines:

ISR (INT0_vect){

      encoderRPos = encoderRPos + 1;

}

ISR (INT1_vect){

  encoderLPos = encoderLPos + 1;

}

The variables encoderRPos and encoderLPos are of type volatile int. I understand that the variables which undergoes change in any interrupt routine need to be of type volatile. This is to warn other parts of the code that use these variables that it may change anytime.

But what happened in my code was a bit strange and I could not explain it. Here is how I compute the distance moved by the left wheel:

  #define distancePerCount 0.056196868
  float SR = distancePerCount * (encoderRPos - encoderRPosPrev);
  float SL = distancePerCount * (encoderLPos - encoderLPosPrev);

  encoderRPosPrev = encoderRPos;
  encoderLPosPrev = encoderLPos;

But when I print the following on my serial monitor, I notice an anomaly:

If you look at the third column, (SL) it's value is too high just for some time. This is upsetting all my calculations.

The only clue I can get it, if I take the value of SL that I got (3682), which is always a constant, and calculate back (encodeLPos - encoderLPosPrev), I will get 65519.66, which is close to the max value of unsigned int. Which means (encoderLPos - encoderLPosPrev) is causing an overflow while both the values whose difference is taken is somewhere around 5000 only!

And I managed to solve it. It was by luck. This is how I modified the code:

  static int encoderRPosPrev = 0;
  static int encoderLPosPrev = 0;

  int diffL = (encoderLPos - encoderLPosPrev);
  int diffR = (encoderRPos - encoderRPosPrev);

  float SR = distancePerCount * diffR;
  float SL = distancePerCount * diffL;

  encoderRPosPrev = encoderRPos;
  encoderLPosPrev = encoderLPos;

I can't comprehend what has happened. Is there something about volatile variables that I should have known about?

Update: Here is the entire code if you ever want to take a look. And it's working very well after changing it to what was suggested in the accepted answer.


texts: Combining code for multiple sensors (Current and Voltage Sensors) in one program

texts:
I need to operate 2 different sensors (Current and Voltage) simultaneously. I have managed to run each one of them separately and I don't know how to manipulate the code so they could work together. My background in coding is basic and I'm not the one who wrote these codes.

Here are the sketches:

1. Current Sensor Code

void setup() {

  Serial.begin(9600);
}

void loop() {

  float average = 0;
  for(int i = 0; i < 1000; i++) {
    average = average + (.0264 * analogRead(A0) -13.385) / 1000;//this is
    //for the 5A mode, if 20A or 30A mode, need to modify this formula to
    //(.19 * analogRead(A0) -25) for 20A mode and
    //(.044 * analogRead(A0) -3.78) for 30A mode
    delay(3);
  }
  Serial.println(average);
}

2. Voltage Sensor Code

/*
DC Voltmeter Using a Voltage Divider
Based on Code Created By
T.K.Hareendran
*/

int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; //
float R2 = 7500.0; //
int value = 0;
void setup(){
   pinMode(analogInput, INPUT);
   Serial.begin(9600);
   Serial.print("DC VOLTMETER");
}
void loop(){
   // read the value at analog input
   value = analogRead(analogInput);
   vout = (value * 5.0) / 1024.0; // see text
   vin = vout / (R2/(R1+R2));

Serial.print("INPUT V= ");
Serial.println(vin,2);
delay(500);
}


texts: RS232 server client connection over nodeMCU

texts:
I have two devices that communicate between them over UHF radio, the radio is hocked up to the serial port, the device use RS232 protocol. I would like to use a couple of NodeMCU to connect the two machines in order to gain extra range (I can't go further than a 2 km over the two). The communication of the two devices is only one-way Master to slave.
My idea is to connect the master device to the server NodeMCU, the server node will be connected to internet over a hot spot. This device will be sending data
The client node will be connected to the slave device which must receive data over it.
Any help idea will be much appreciated. I have no clue from where to start. I can’t connect the two devices over a serial cable so they communicate over RS232. but how can I make it wireless?


texts:
Today I started messing with the idea of getting an arduino uno to autoconnect with another arduino uno using the nrf24l01 breakouts.

I dont have a particular goal in mind per se but was just wanting to get the logistics down so I started simple as pie.  One arduino at address 0x0000000B LL sends a one element array over and over.  Easy.

The second arduino goes through a for loop in the void loop().

The for loop is set to loop 16 times.  It starts with the address 0x00000000 LL and checks to see if radio.available is true.  if it is, the program simply states it has found an address over serial.  If not it states the address is invalid.  afterwards it increments the address by one and repeats until the address gets to 0x0000000F LL (or the for loop repeats 16 times.)

once the address gets to 0x0000000B (or the transmitter address) it states that it has found an address over serial.  So far so good!

Now the problem arises when the address increments to the next address.  No matter what I seem to do or change, once radio.available() becomes true once....it seems to stay true until the function is called again from the main loop in which case it repeats the same scenario.  I have worked hours on such a small program to no avail.  Can someone help please???  I must be overlooking the most simple of things but for the life of me I have no idea what.

Super Simple TX Code.

#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(8,9);
uint64_t myAddress = 0x0000000BLL;
byte txData[] = {1};

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

  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(myAddress);
}

void loop()
{
  if( Serial.available() )
    {;}

  radio.write(txData,sizeof(txData) );
  Serial.println("Sent a packet");
}

RX CODE

#include <nRF24L01.h>
#include <RF24.h>

RF24 myRadio(8, 9);

byte rxData[] = {0};

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

  myRadio.begin();
  myRadio.setRetries(15, 15);
}

void loop()
{
  if( Serial.available() )
    {;}
    //function that searches through a set of 16 addresses
    searchAddresses();
}

void searchAddresses()
{
  //declare a temp address variable
  //and initialize it to first possible address
  uint64_t tempAddress = 0x00000000LL;

  myRadio.openReadingPipe(1, tempAddress);
  myRadio.startListening();

  for (int x =0; x < 16; x++)
  {
      if ( myRadio.available() )
      {
        myRadio.read(rxData, sizeof(rxData) );
        Serial.println("Found an address");
      }
      else
      {
        Serial.println("Address Invalid");
      }
      //increment temporary address to next address
      tempAddress++;

      myRadio.openReadingPipe(1, tempAddress);
      myRadio.startListening();
  }
}


texts: Best way to obtain angular velocity from a 9 DoF sensor

texts:
I have been using a BNO055 sensor (9° dof IMU) for a project which will use angular velocity to the mouse cursor on screen.
So far, I have gotten quaternion output from the sensor and been able to convert it to angular velocity in a couple of ways. The first, multiplying 1 quaternion sample by its conjugate in the next sample, and then converting the quaternion Delta in Euler angles. The second, converting from quaternions to Euler angles and then finding the change in those between samples.
Both methods result in angular velocity measurement, but each with their advantages and disadvantages. E.g. Quaternion Delta between samples does not suffer from gimbal lock, but it's difficult to isolate y-axis from z-axis movement.
I know that you can ask the sensor for angular velocity data directly, but apparently that's less precise due to the Gyro drift and it's relative orientation only, which is why I opted to work with quaternions.
Is there a better way to go about this?
My code included below for reference with the 2 approaches in case it's helpful/interesting. It uses the Adafruit repository, doing the standard stuff in setup function and then calling the function below in loop.
void quaternion_Delta () {
  // Quaternion data 1
  imu::Quaternion quat = bno.getQuat();
  // Euler 1
  imu::Vector<3> euler_one = quat.toEuler();
  //delay between samples
  delay(BNO055_SAMPLERATE_DELAY_MS);
  // Quaternion data 2
  imu::Quaternion quat_two = bno.getQuat();
  // Euler 2
  imu::Vector<3> euler_two = quat_two.toEuler();
  // quaternion comparison
  imu::Quaternion quatDelta = quat_two * quat.conjugate ();
  imu::Vector<3> euler = quatDelta.toEuler();
  Serial.print(" X: ");
  Serial.print(euler.x()*radius_to_degrees, 2);
  Serial.print(" Y: ");
  Serial.print(euler.y()*radius_to_degrees, 2);
  Serial.print(" Z: ");
  Serial.print(euler.z()*radius_to_degrees, 2);
  Serial.print("\t\t");
  // Euler comparison
  imu::Vector<3> euler_comparison = euler_two - euler_one;
  Serial.print(" x: ");
  Serial.print(euler_comparison.x()*radius_to_degrees, 2);
  Serial.print(" y: ");
  Serial.print(euler_comparison.y()*radius_to_degrees, 2);
  Serial.print(" z: ");
  Serial.print(euler_comparison.z()*radius_to_degrees, 2);
  Serial.print("\n");
  }