texts: MPU6050 Accelerometer freezes/glitches after acceleration

texts:
I am trying to do rotational vector calculation using a MPU6050 chip which actually work really well with not too much drift when I rotate the MPU slowly. However, when I accelerate too much, e.g. change direction in my slow rotations or just slightly tap the breadboard with my finger, the values completely go nuts.

I am using an ESP8266 chip to control the chip and I have tried multiple libraries for reading the Gyro/Accelerometer values which all have more or less the same behaviour.

My accelerometer readings from the Serial plotter, before and after the light tap to the breadboard:

Gyroscope does the same thing. The MPU is new (just arrived in the mail few hours ago), I power it using 3.3V and use 3.3V GPIO logic from the ESP chip.

Does anyone know what could be causing this?


texts: Using Serial Plotter with Visual Studio Code

texts:
I'm using the Visual Studio Code extension to develop for Arduino which works great.

It doesn't have a Serial Plotter like the regular Arduino IDE, which I need to debug this project. I can run the Arduino IDE's Serial Plotter alongside Visual Studio Code without too much of a problem.

However, if I try to compile and upload from Visual Studio Code while the Arduino IDE is running, the port is busy (not a surprise):

avrdude: ser_open(): can't open device "/dev/cu.usbmodem14201": Resource busy
An error occurred while uploading the sketch

So I have to keep exiting and relaunching the Arduino IDE every time I build.

Anyone have a suggestion for how to work around this? Using an iMac as development environment.


texts: AVR-GCC can't call function located on fixed address

texts:
I wrote the following code:

#include <avr/io.h>

__attribute__((noinline, section(".app_start"))) void app_start() //app_start section starts at 0xFA0
{
    //register_packet_dispatch(packet_received);
    PORTB = 0xFF;
}

__attribute__ ((noinline)) void call_app()
{
    asm ("call 0xFA0\nret");
    //app_start();
}

int main()
{
    DDRB = 0xFF;
    //call_app();
    app_start();
    while(1){}
}

What I compiled with:

avr-gcc -Wl,--section-start=.reg_dispatch=0xdac -Wl,--section-start=.app_start=0xFA0 -mmcu=atmega328p -Os -o ubb.o ub_bootloader.cpp -DF_CPU=16000000

Which tries to simulate a host application that tries to call a relocated client application, begins from the 4000 address (0xFA0). If it would work, it's light up the LED wired to the arduino's 13. pin. But why app_start won't be called?

I've also inspected the output assemlby:

avr-objcopy -j .text -j .data -O ihex ubb.o ubb.hex

00000fa0 <_Z9app_startv>:
 fa0:   8f ef           ldi r24, 0xFF   ; 255
 fa2:   85 b9           out 0x05, r24   ; 5
 fa4:   08 95           ret

00000080 <main>:
  80:   8f ef           ldi r24, 0xFF   ; 255
  82:   84 b9           out 0x04, r24   ; 4
  84:   0e 94 d0 07     call    0xfa0   ; 0xfa0 <_Z9app_startv>
  88:   ff cf           rjmp    .-2         ; 0x88 <main+0x8>

Everything seems correct, why it isn't working at all?
Of course, if i remove the "noinline" attribute, it works. But that's a mirage, the compiler inlines the content of the function, but when I build this into an application, the code after the 0xFA0 address will be rewritten by the host application.


texts:
First we set fuse bits:

avrdude -c usbasp -p atmega328p -U lfuse:w:0xFF:m -U hfuse:w:0xDF:m -U efuse:w:0x07:m # same for atmega168

In the following examples we use the following commands to compile and burn all the programs:

avr-gcc -Os -mmcu=atmega328p -c -o serial.o serial.c
avr-ld -o serial.elf serial.o
avr-objcopy -O ihex serial.elf serial.hex
avrdude -c usbasp -p atmega328p -U flash:w:serial.hex

Let us burn the following program:

#define F_CPU 16000000UL
#include <avr/io.h>
void main (void) {
  DDRB |= (1<<PB5);
  PORTB |= (1<<PB5);
  while (1);
}

It makes the led to be on constantly. And it stays so for infinite period of time.

Then we burn the following program:

#define F_CPU 16000000UL
#define BAUD 9600
#include <avr/io.h>
char data = 0;
void main(void) {
  // Initialize USART:
  #include <util/setbaud.h>
  UBRR0H = UBRRH_VALUE; // set the speed (Higher bit)
  UBRR0L = UBRRL_VALUE; // set the speed (Lower bit)
  UCSR0B |= (1<<RXEN0); // enable receiver
  UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00); // set mode (8N1)
  DDRB |= (1<<PB5); // enable output on pin PB5 (default led on arduino)
  while(1) {
    while(!(UCSR0A&(1<<RXC0))); // wait until a byte is received
    data = UDR0; // read it
    if (data) PORTB |= (1<<PB5); // set the led on
  }
}

Then we open a terminal (9600,8N1) and press several keys, until the led turns off.
Now we burn the first program again and the led is constantly blinking. The reason for this is that watchdog times gets started when we press the keys in terminal. But why and when WDT gets started? How to make so that it will not start?

It should be noted also that we can disable the blinking only with complete poweroff/poweron - only after that the led lights constantly without blinking, as necessary.

This happens on atmega168 and atmega328p, 100% reproducible.

avr-gcc version 4.8.1 avrdude version 6.1

NOTE: bootloader is not used at all.


texts: Sending data from Arduino to the server where arduino (sketch) acts as a client

texts: I want to make simple client-server program where arduino behave as a client. For example I have a LED connected in arduino board that is controlled by a switch. With the switch I can turn off and on the LED. Now I want to send the status of that LED to another computer wirelessly (let's say within the Local network). That computer will act as a server and update the change as soon as the LED changes its status. I am not expecting any complete code, I just want to know how could it be done in general? May be some links can help me? Because this is my first time working with client-server in arduino sketch, I need some kind of guidelines. Thank you.


texts:
I'm working on a project in which I use a lot of the pins on the Arduino;  I have run out of most of the pins and and I need to read the value of a push button.

Is it possible to read the value of the switch in the analog in pins on the board??

If so how can I implement this?


texts: Need help with uploading to arduino ng or older with atmega8

texts:
I am a newbie in arduino. I successfully installed driver for arduino atmega 8l, which were provided by the company i bought arduino from. The driver is PL2303 by prolific. The reason i m mentioning this is because at first i had some problems in installing them.
Now after i have made a blink program. I thought of uploading it. Whenever I try to upload i get this error:
avrdude: arduino_read_sig_bytes(): (a) protocol error, expect=0x14, resp=0x75
avrdude: error reading signature data for part "ATMEGA8", rc=-2
avrdude: error reading signature data, rc=-1

My computer: Windows 7 32-bit
I tried pressing the reset button before uploading, i get the same message.
I tried it in another computer of mine. There the driver is showing a code 37 error so basically my other computer is not reading the arduino.(also my board comes with bootloader already innstalled). Thank You


texts: If the USB gives 5v, how can the Arduino supply 5v to the 5v pin? (And another question)

texts:
I must not of understood something. Online, I've heard that the Arduino uses 9v typically (average), and that USB's in general supply 5v@500mA. If this is true:

How can the Arduino even POWER ITSELF with the 5v USB? I've heard the minimum is 7v.
How can there be a 5v pin if the USB supplies 5v... that leaves no room for the Arduino!

My understanding is very bad currently, any explanation would be great. Thanks!


texts:
We have an arduino pro mini, we are trying to trying to upload sketch the controller but we are prohibited, as the arduino attempt to upload the sketch, it display an error of: not in sync.

We are pretty new in this are, so any help would be much appreciated.

Our setup is: -Breadboard -Connection to adapter: USB Serial. -Arduino Pro Mini as a controller

Through the Arduino Programming Client.

The processor and the port are setup op properly.

The strange thing is, it has worked sometimes these past days..

Much Thanks.

Mieer


texts: portd not writing on digital ports 5 and 7

texts:
I try to build a function generator (preferably a sine) with an R-2R ladder and a Arduino Leonardo by Borderless Electronics.

For performance reasons one should use portd instead of digitalWrite.
However the signal is not at all what I want (just noise). So upon further investigation I found that the digital pins were never on HIGH. Pin 6 worked flawlessly. Furthermore I have tested the two failing pins with simple test programms and they behaved exactly as I would have expected.

Here is the code I use

 int sine[255];

 void setup()
 {
     pinMode(0, OUTPUT);
     pinMode(1, OUTPUT);
     pinMode(2, OUTPUT);
     pinMode(3, OUTPUT);
     pinMode(4, OUTPUT);
     pinMode(5, OUTPUT);
     pinMode(6, OUTPUT);
     pinMode(7, OUTPUT);

     float x;
     float y;
     for(int i=0;i<255;i++)
     {
          x=(float)i;
          y=sin((x/255)*2*PI);
          sine[i]=int(y*128)+128;
     }
}

void loop()
{
     for (int i=0;i<255;i++)
     {
          PORTD=sine[i];
          delayMicroseconds(10);
     }
}

I tested this with two Arduinos of the exactly same type.

Question: Why are pins 5 and 7 never on HIGH?

Edit: I have simplified everything down to one statement in the loop: portd = x;

I vary x manually

expected findings:

x  ->  #pin that is on high

0  -> None

1  -> 0

2  -> 1

4  -> 2

8  -> 3

...

128 -> 7

actual findings

x  ->  #pin that is on high

0  ->  None

1  ->  3

2  ->  2

4  ->  0

8  ->  1

16 ->  4

32 ->  None

64 ->  None

128->  6

I test this by simply connecting an oscilloscope to the output pins. The behaviour is extremely strange since the pins seem to be in random order, some even missing to portd. Furthermore portd = B11111111, according to the manual, is equivalent to portd = 255; and should set all pins on HIGH. But in my case it sets every pin to HIGH, except pins 5 and 7 are on LOW.


texts: I am trying to build a set of four stars using an Arduino, potentiometer and a four channel relay to control how fast it speeds across the stars. My question is how can I delay the process, say for 20 or 30 seconds before it starts again?


texts: ATMega328 not able to fully switch coreless motor on

texts:
I'm having trouble regarding motor control in a project I'm working on.

It uses an ATMega328 DIP package on a PCB. The motors I'm using are small coreless motors and I'm trying to control them using Si2302ds N-MOS FETs. For the power supply I'm using a 3.7V(4.2V on full charge) Lipo. I've tested this setup with a promini before and the motors turned on and off just fine.

This time I'm having problems with controlling 1 motor out of the 4. I've attached 0.1uF caps across each motor terminal (see schematic). Them control pins used for the motors are pins 3,5,6,9. The problem occurs at pin 3. I tried running the blink program on pin 3 to pulse the motor on and off through the FET but all I get is a bit of clicking from the motor.

Things I've already checked relating to the circuit :

FETs are soldered on correctly and made sure they aren't defective.
Motor works fine prior to connecting it to the circuit.
Disconnected the FET and motor from pin 3 and checked the output.
It works fine on its own.

The puzzling thing is that only 1 motor (at pin 3) seems to struggle to come on. The rest work just fine. Also if I try and turn all 4 motors ON, it doesn't work. But if I turn only the 3 working ones on and keep the non-working one off they turn on perfectly.

Is the problem occuring due to noise generated by the motor? What could be the problem? I've attached the schematic to this post below.


texts: How to read Serial data when multiple functions are Running?

texts:
I want to halt the execution of that code, when arduino is receiving serial data for the execution. Right now the Serial data runs when the other code has completed its execution. How can I do it ?

void loop() {
    dmd.setBrightness(brighVal); // set the brightness to led matrix
    scroll();  //function to scroll message

}
void serialEvent() {
  while (Serial.available()) {
    Jsondata = Serial.readString(); //reading json data from APP
    DynamicJsonBuffer jsonBuffer;
    Serial.println(Jsondata);
    JsonObject& root = jsonBuffer.parseObject(Jsondata);
    if (root.containsKey("BiM")) {
      brighVal = root["BiM"];
      switch (brighVal) {   // set's the value of brightness according to brighVal
        case 0:
          brighVal = 2;
          break;
        case 1:
          brighVal = 10;
          break;
        case 2 :
          brighVal = 25;
          break;
        case 3 :
          brighVal = 200;
          break;
      }
    }
  }
}
void scroll() {
  dmd.clearScreen( true );
  dmd.selectFont(Arial_Black_16);
  dmd.drawMarquee("Scrolling Text", 17, (32 * DISPLAYS_ACROSS) - 1, 0);
  long start = millis();
  long timer = start;
  boolean ret = false;
  while (!ret) {
    if ((timer + 30) < millis()) {
      ret = dmd.stepMarquee(-1, 0);
      timer = millis();
    }
  }
}


texts:
I have been using a HC-SR501 PIR module with my Arduino Mega and it was tracking presence pretty well.

Because of cost constraints, I decided to go with HC-SR505 sensor - bought a bunch of them. The performance is very bad. It almost seems like it is giving random HIGH and LOW values. Out of the 20 odd sensors I bought, may be one or two are fairly ok - others are all behaving weird. Have someone experienced this kind of behavior with HC-SR505?

Are they highly sensitive to noise in the power supply - is there any workaround to mitigate the effect? Help?

Code:

const int buttonPin = 4;

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

   pinMode(buttonPin, INPUT);
 }
 void loop()
 {
    if (digitalRead(buttonPin) == HIGH)
    {

      Serial.println("Presence Detected");
    }
    else {

      Serial.println("No Presence Detected");
    }

 delay(2000);

 }


texts:
After execute the program of below, the 13 pin output is 4.8v. Why it's not 3.3v?

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13, HIGH);
}


texts: Standalone ATmega328P stops responding when RX is connected

texts:
I have followed this demo and have set up a standalone ATmega328P being programmed from a Raspberry Pi via the SPI lines. I have also added a 16 MHz crystal with 22 pF capacitors, as well as I have enabled and set up I²C between the ATmega and Raspberry Pi.
I have compiled and uploaded a bunch of programs and I can confirm everything works as expected.
As you can imagine, it is quite hard debugging things without a serial connection, so I connected pin 2 of the ATmega to GPIO14 of the Raspberry Pi and pin 3 to GPIO15. At this point, when I try uploading a program, I get this:
$ avrdude -P /dev/spidev0.0 -c linuxspi -p m328p -U flash:w:build-uno/program.hex

avrdude: error: AVR device not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

If I break the pin2 to GPIO14 connection, then my program gets uploaded. And if I restore the connection between the pins and open Minicom on the Raspberry Pi I see the output of my simple program:
void setup() {
  Serial.begin(9600);
}

void loop() {
  delay(1000);

  Serial.println("Echo Test");
}

$ minicom -b 9600 -o -D /dev/ttyS0

Welcome to minicom 2.7.1

OPTIONS: I18n
Compiled on Aug 13 2017, 15:25:34.
Port /dev/ttyS0, 16:50:17

Press CTRL-A Z for help on special keys

Echo Test
Echo Test
Echo Test
Echo Test

But whenever I press a button on the keyboard (inside Minicom), I notice that the ATmega gets reset. If I hold the button down the transmission of "Echo Test" seizes as it is getting reset rapidly.
How can I get serial to function properly?
Addendum:
I'm using a Raspberry Pi 4, and in raspi-config I have disabled serial login and left the serial hardware enabled.


texts:
I'd like to flash the eeprom sector with content so that the eeprom already holds data when it boots the first time.
How do I upload such an eeprom file like I would do with avrdude on an atmega? Is there a tool that can be installed in the arduino IDE like the data uploader?


texts: Help Led matix isn't lighting up correctly Is it a Hardware or software issue?

texts:
I am trying to reverse engineer the project from this video: https://youtu.be/zc1zbwheyE0?t=50s.

From the video a visible 10 wires are going from the LEDs to the Arduino mega, i am assuming that they are wired in a 5x5 matrix (5 rows, 5 columns) given that there are 25 keys on the Midi controller so there most be 25 LEDs.
I reconstructed the project the best a could from observing the video, but my issue is when i press 3 keys 5 LEDs light up unlike in the original video where 3 keys are pressed and 3 LEDs light up(as seen @ 0:50 of the video).
This is the issue i am having : http://imgur.com/a/9SOEJ.
I am thinking the issue is related to how i have my LEDs wired, but my LEDs are wired exactly the same as in the video. isn't it ? is there something i might have missed? How is the project in the video able to light up 3 LEDs without having an issue with extra LEDs lighting up in their matrix? how can i fix my circuit to replicate the video?

Here is some of my coed for turning on an LED when a key is pressed:

<include MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

byte anodes[5] = {30, 32, 34, 36,38};

byte cathodes[5] = {31, 33, 35, 37,39};

byte data1 = 0;

void setPinTo5V(byte pin) //set a pin given to this function to a 5V voltage source

{
    pinMode(pin, OUTPUT);
    digitalWrite(pin, HIGH);
}

void setPinToGND(byte pin) //set a pin given to this function to a GROUND (GND pin)
{
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
}

void loop() {
    MIDI.read();
}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity)
{
    data1 = MIDI.getData1();

    if (data1==48){//C3
        setPinTo5V(anodes[0]);//set pin 30 to 5V
        setPinToGND(cathodes[0]);//set pin 31 to GND

        delay(1); //do nothing for 1 ms
    } //this is done for all 25 keys

}

any help would be appreciated Thanks.


texts:
I try to detect commands given by user in Serial Monitor, but strcmp fails to flag as identical.

What do I do wrong ?

Is there a better way not reading as String and convert to char for comparison ?

Guy

char* additional_callbacks [] = {"command_1", "command_2", "command_3"};

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

void loop() {
  if (Serial.available() > 0) {
    char tmpchar[50];

    Serial.print("entered_text:");
    String str = Serial.readString();
    str.toCharArray(tmpchar, 50);
    Serial.println(tmpchar);

    for (int i = 0; i < sizeof(additional_callbacks) / sizeof(char*); i++) {
      if (strcmp(tmpchar, additional_callbacks[i]) == 0) {
        Serial.println("match");
      }
    }
    Serial.flush();
  }
  delay(50);
}


texts: How to connect two Arduino without shields?

texts: I'm planning an Arduino system that consists of several Arduino boards. The maximum distance between the boards is about 50 meters. I want to send basic data between these, like short strings or integers. I know I could send data through ethernet cables but that requires an ethernet shield or the Arduino Ethernet board that doubles the costs. Is there a low budget way I could connect the boards using only the most basic boards (like Uno) and some other components but not a full shield?


texts:
I meet a terrible problem. I can't compare two string!

My job is simple, every 1ms use SoftwareSerial read_card(2, 3);to check if i read a id card.And don't read a card twice.Here are my code:

bool CardReader::check()
{
    String str= read_card.readString();
    if (str.length() == 0 ) return false;
    //Log("card:%s", str);
    Serial.println("card_id");
    Serial.println(str);
    Serial.println(card);
    Serial.print("cmp:"); Serial.println(str == card);
    if (str.length() == card.length())
    {
        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)str.c_str();
        for (int i = 0; i < card.length(); i++)
            if (p1[i] != p2[i])
                break;
        return false;
    }
    card = str;
    return true;
}

Let's see output:

card_id
 Rq
 僐R
cmp:1

The hex are:

00 01 52 71 02
00 83 52 52 00

Why the two string is equal?

Bugs are fixed.If string begin with '\0',== can't work and = can't work either.

bool CardReader::check()
{
    String str = read_card.readString();
    if (str.length() == 0) return false;
    if (str.length() == card.length())
    {
        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)card.c_str();
        for (int i=0; i < card.length(); i++)
        {
            Log("%d:%d", p1[i],p2[i]);
            if (p1[i] != p2[i])
                goto find_card;
        }
        return false;
    }
find_card:
    for(int i=0;i<5;i++)
        card[i]=str[i];
    return true;
}


texts:
I am using an LDR (Iduino SE012) to measure light. It returns a 10-bit value of the incoming voltage and I don't know how to convert this into lux, lumen candela or any other light-intensity unit. I was googling for datasheets but nothing useful came up. So is there any way how I can extrapolate a light intensity from the voltage?

I mean one idea that I would have is to measure some things where I know the lux output, but since I don't have such things or a luxmeter I'm pretty stuck. It also returns 1024 pretty quick if you hold it into the sun (Altough the sun is very strong today and it has 36°C). Is there maybe a "minimal value" at wich it returns the full voltage? From that point I could calculate it for all the other values.

Here are some datasheets I found:

https://www.manualshelf.com/manual/iduino/se012/datasheet-english.html
https://wakamatsu.co.jp/waka/SE012.pdf


texts:
I am trying to do a HTTPS post on ESP8266 as shown in Postman below

But I keep getting: 'HTTP/1.1 401 Unauthorized'.

Can someone please help me with how to build up the headers correctly in the HTTPS POST? And maybe also give a link to some documentation? I cant seem to find any...

My code is:

const char* host = "api.dgs.com";
const int httpsPort = 443;
String url = "/ccs-int/v1/applicationdatalogging/1.0";
String msg = "";

WiFiClientSecure client;

Serial.print("connecting to : '");
Serial.print(host);
Serial.println("'");
Serial.printf("Using fingerprint '%s'\n", fingerprint);
client.setFingerprint(fingerprint);

client.connect(host, httpsPort);

Serial.print("requesting URL: '");
Serial.print(url);
Serial.println("'");

client.print(String("POST ") + url + " HTTP/1.1\r\n" +
    "Host: " + host + "\r\n" +
    "Connection: close\r\n" +
    "Content-Type: application/json" +
    "Authorization: Bearer " + authorization_code + "\r\n" +
    "Content-Length: " + msg.length() + "\r\n" +
    "\r\n" +
    msg + "\r\n");

Serial.println("request sent");
unsigned long timeout = millis();
while (client.available() == 0) {
    if (millis() - timeout > 5000) {
        Serial.println(">>> Client Timeout !");
        client.stop();
        return;
    }
}


texts:
I have TM1812 addressable LED strip (1meter long 96 LED). I am looking a way to program it and i found this http://www.deskontrol.net/blog/arduino-based-artnet-node-for-led-pixels/
and its mentioned in article that it doens't work with current version of Arduino IDE.

Is there some other lib/api available to program it or another method?

UPDATE
As mentioned by @dlu FastLED support wide variety of LEDs. I contacted developers of FastLED on google + and they have updated there documentation for support of TM1812 its similar to TM1809


texts: Error while trying to drive relay through the state of a digital input pin in Arduino

texts:
I'm trying to change the state of a relay according to the state of a digital input in an Arduino with an ethernet shield. It works sometimes and some other times it doesn't work.

My code:

const int led1 = 2;
const int enable1 = 4;
boolean led1_OnOff;

void setup() {
  led1_OnOff = false;
  pinMode(enable1, INPUT);
  digitalWrite(enable1, LOW);
  pinMode(led1, OUTPUT);
}

void loop() {
  if(digitalRead(enable1) == HIGH) {
    if(led1_OnOff == true) {
      led1_OnOff = false;
    } else {
      led1_OnOff = true;
    }
  }

  if(led1_OnOff == true)
    digitalWrite(led1, HIGH);
  else
    digitalWrite(led1, LOW);
}

My schematics:

Relay 5v -> arduino 5v
Relay gnd -> arduino gnd
Relay in -> digital pin 2
Relay com -> 220 AC
Relay NC -> 220 AC
Push button pin 1 -> Arduino 5v
Push button pin 2 -> digital pin 4

Pin 2 is connected to the relay enable pin and pin 4 is connected to a push button and the boolean is used for saving the state.

Can anyone tell me what the problem is, and why the relay doesn't work most of the time?


texts: Project: Relay is ticking, but not actually switching

texts:
I'm trying to make an automatic planter for herbs etc. I finally got everything 3D printed and wired together. But for some reason, the relay I'm using refuses to switch or enable certain connections. I'm confused because it worked perfectly - continuity-wise - during my initial testing or installation.

The relay model HERE. The relay is to be controlling the ground connection of both an 12v indoor grow light and 12v small water pump. I was a bit confused with the relay's wiring itself. First time using this type of relay. Anyway, I got it working; well previously.

Here are some video to help explain the issue:
https://www.youtube.com/watch?v=GUiHs28bvK8
https://www.youtube.com/watch?v=-xaj8q537x4

(After uploading, I hear that my phone's mic stops the tone of the multimeter a few seconds into each video. But trust me, the tone is constant throughout the duration of both videos. You may be able to hear it?)


texts:
I am trying to learn more about arduino programming, and recently i've written functions for randomizing and then modifying a single array. Now i'd like to do the same for four individual arrays. This is where i'm getting stuck. My questions:

Am i right to assume that it's not possible calling a function for multiple individual arrays?

Perhaps a separate question, but if a class or struct would be more suitable for multiple instances, what are the major differences worth considering to choose the right approach?


texts: How to get Arduino to talk to two seperate motors wirelessly?

texts: I have an Arduino Uno and I also have two Servo Motors. Say I have a room that is 15 feet wide, and I want to be able to place the Arduino in the center of the room and control two servo motors placed at each end of the room using a button on the Arduino. Is it possible to wirelessly communicate with these two servo motors using just one Arduino and bluetooth transmitters/receivers? Or will I have to use three Arduinos, one for the center with the button and one for each servo. If so, will I be able to substitute the two servo Arduinos with an ATtiny chip?


texts: Where can I find the code for Arduino's "attachInterrupt"?

texts:
Where can I find the code for Arduino's attachInterrupt function?

A search on the Arduino's Github repo yielded nothing.

I suspect it might be a wrapper for some avr-libc function but nothing in the avr-libc docs stands out to me...


texts:
I need some information for the TFT screen 2.8 and arduino mega.
The screen works very well and displays the data.
The small problem I encounter is for the text display, the page is reloading every second and this makes a small black screen every second.
I would like to know if it was possible to reload only one part of the screen display?

See in video
https://youtu.be/vxSa6xkH0vU

My loop()

void loop(void) {
   tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setRotation(3);
  dt = clock.getDateTime();
  clock.forceConversion();

  // Go
  tft.println();
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Info");
  tft.println();
  tft.setTextSize(2);
  tft.println(clock.dateFormat("d-m-Y H:i:s", dt));
  tft.println();
  tft.setTextSize(2);
  tft.println("Temperature: ");
  tft.println(clock.readTemperature());

  delay(1000);
}


texts:
I would like to timestamp the data collected from AnalogBinLogger.ino on an Arduino Uno. The sketch uses 512-byte buffers, and I have read that writing data in 512-byte chunks is 'better' in terms of write latencies.

The sketch uses this structure for the buffers:

// Data block for 10-bit ADC mode.
const size_t DATA_DIM16 = 254;
struct block16_t {
  unsigned short count;    // count of data values
  unsigned short overrun;  // count of overruns since last block
  unsigned short data[DATA_DIM16];
};

Since I want to add the timestamps which are of unsigned long type, I would have to modify the structure as follows:

// Data block for 10-bit ADC mode.
const size_t DATA_DIM16 = 254;
struct block16_t {
  unsigned short count;    // count of data values
  unsigned short overrun;  // count of overruns since last block
  unsigned short data[DATA_DIM16];
  unsigned long  milli[DATA_DIM16]; // time in milliseconds
};

Now, this structure exceeds 512 bytes and is 1528 bytes. Due to unavailability of enough free stack, my program doesn't run (sketch reports FreeStack to be 1135 bytes). How can I go about this?

PS: My root problem is to achieve time-synchronisation among multiple data-collecting Arduinos which sample at high rates like 8kHz. Due to clock drifts, even if I sync the start times, the timestamps collected afterwards would not be relative to each other. Hence I plan to have a master Arduino send its time to the others in regular intervals.


texts: Mega 2560 pin output power and control question

texts:
I am trying to determine the total pin power requirements for my Mega 2560 project; it will connect to 3 1m Neopixel strips and 5 RGB laser fiberoptic lights, and control them via PWM. Each strip and light will have its own external power supply. The laser lights will be controlled by an Adafruit TLC5947 LED Breakout board with 3 (R,G,B) inputs. Further, each laser light is turned on by a logic high command.

My questions are:
How can I determine the total pin outputs? Can all this be controlled safely from the Mega, or will I need to add transistors? I have read 200mA is the maximum for the Mega, however I have found a seemingly definitive post on Arduino.cc that states 800mA is the maximum.
https://forum.arduino.cc/index.php?topic=327742.0

here's my rough schematic:

Thank you in advance!


texts: Read/write data from 2 Arduinos simultaneously with Python

texts:
So for my project I have one Arduino Mega hooked up with a quadrature rotary encoder which is connected to the computer. An Arduino Uno is connected to a circuit I built, which in turn is connected to a valve and a touch connector (also connected to the computer via USB). Both of them should be controlled with a Python script.

If the rotary encoder is moved, I can read out a value via the serial port. The value of the rotary encoder is used in Python to move a dot on the screen. If the dot on the screen reaches a certain point, I want to give a signal to the valve to open (something like pin.write(1) to turn on or pin.write(0) to turn it off). At the same time I want to be able to detect the touch sensor if the circuit is closed.

The issue is now that I need to somehow need to read the rotary encoder, process the data and send it to the valve, as well as reading the touch sensor simultaneously. So far I have not found a way how to achieve this as my code does not function.

At the moment I have custom code on My Arduino Mega and a StandardFirmata on the Arduino Uno, but I am open to other suggestions that could work.

Arduino Mega code:

/*
by Ben-Tommy Eriksen
https://github.com/BenTommyE/BenRotaryEncoder
*/

// Encoder connect to digital pin 2 and 3 on the Arduino.

int counter = 0;
//This variable will increase or decrease depending on the rotation of encoder

void setup() {
  Serial.begin (4600);
  //Setting up interrupt
  //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
  attachInterrupt(0, ai0, RISING);
  //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
  attachInterrupt(1, ai1, RISING);
}

void loop() {
  // Send the value of counter
  Serial.println (counter);
}

void ai0() {
  // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
  // Check pin 3 to determine the direction
  if(digitalRead(3)==LOW) {
    counter++;
  } else {
    counter--;
  }
}

void ai1() {
  // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
  // Check with pin 2 to determine the direction
  if(digitalRead(2)==LOW) {
    counter--;
  } else {
    counter++;
  }
}

Python code:

import pyfirmata
import serial
import time

#Associate pyfirmata with python for my UNO board
port='COM5'
board= pyfirmata.Arduino(port)
#Use iterator thread to avoid buffer overflow
it = pyfirmata.util.Iterator(board)
it.start()

#Define pins (giving roles to pins: i.e. d=digital,7=pin number,i=input)
lickPin = board.get_pin('d:10:i') #records signal from the touch sensor
outPin1 = 12 #passes the signal to the valve

s = serial.Serial('COM4',4600)
while time<60s #generalized:
    rotary = s.readline() #reads the counter of the rotary encoder form arduino

    #convert the rotary to an integer try/except is needed to work
    try:
        var = long(rotary)
        last_var = var
    except:
        var = last_var
        pass

    value1 = lickpin.read()

    # Here I move the cursor up and down depending on the rotation of the encoder
    # if the cursor moves above a certain value
    if y>-18:
        board.digital[12].write(1) #should open the valve

Unfortunately the code above does not trigger the valve to be opened, and I do not know why. Help is greatly appreciated. Thanks!


texts:
I am trying to set up a CAN-bus with its two nodes on the same Arduino. By Using an Arduino DUE without any transceivers. As my first experiment, I want to send a message from one CAN unit to the other. But so far I have not been successful to see any signal on the bus. (I am using an Oscilloscope)

Here is the detail of my effort:

I have used this(1) library, and I want to run the CAN_EchoTest example(2).
As for the physical layer, I have created a circuit, according to a Method that is suggested here(3), here(4), and here(5). I set the transmission rate to 5Kbps, (lowest possible value provided by the library), to make sure that noise and propagation effects are minimal.

I implemented this mentioned Method to the Arduino board, using the Board's Schematics(6). In other words, I assumed that:

CANTX1 in the schematics, refers to PIN with the label '53' on the board.
CANRX1 in the schematics, refers to PIN with the label 'DAC0' on the board.
CANRX0 in the schematics, refers to PIN with the label 'CANRX' on the board.
CANTX0 in the schematics, refers to PIN with the label 'CANTX' on the board.

And I assumed the library that I am using configures the mutual PINS (DAC0 and 53), in a way that CAN controllers will be using them exclusively. I am not sure about the pair of diodes that I used: Vishay SS34A.

what is missing/wrong? Please be patient regarding any rookie mistakes. I can Provide further information if requested.

Thank you in advance

(1) github.com/collin80/due_can

(2) github.com/collin80/due_can/tree/master/examples/CAN_EchoTest

(3) www.mikrocontroller.net/attachment/28831/siemens_AP2921.pdf

(4) electronics.stackexchange.com/questions/30564/is-a-can-enabled-microcontroller-sufficient-to-drive-a-can-bus

(5) www.keil.com/download/files/canprimer_v2.pdf

(6) www.arduino.cc/en/uploads/Main/arduino-Due-schematic.pdf


texts: Adafruit CC3000 WiFi Module working together with MFRC522 RFID Module Issues both SPI over Arduino

texts:
I'm asking if how can I implement this one. I'm aware about multiple devices being connected over SPI, like having to select individual SS pin for each. Adafruit's CC3000 works fine alone along with the default Adafruit library. CC3000 uses SPI. MFRC522 RFID module by sonmicro (bought at Sparksfun) uses SPI too. It works fine too, independently. But whenever I connect them together, only WiFi works perfectly. I dont want to turn on and off the wifi to make way for the RFID to communicate since it takes some time for it to be connected in a wireless network. I want the two to work synchronously (or having to be scheduled but really fast that's unnoticeable by the user)

here's my code as of now. i cannot post it here as strange things happen i don't know why haha https://drive.google.com/file/d/0B0bZsYo0xMH8YV9uWXJaRFdPT3M/view?usp=sharing

I'm thinking of replacing the RFID with SonMicro's SM130 RFID Module w/ SparkFun Eval board with UART (convertible to I2c) or Adafruit's PN532 with I2c by default. Are these okay to be paired with SPIs like the CC3000? Or should I change CC3000 with the Official WiFi module (UART) or WiFly Module (SPI-to-UART)


texts: Can I control Arduino functions via PWM?

texts:
I want to control small functions from an Arduino, things like moving servos or toggling lights. The purpose of these is to decrease the number of channels on a rover I'm constructing.

Using the PWM output of a channel from the receiver of the rover, can I assign certain pulse widths to functions the Arduino can perform? Thank you for reading, even if I sound a little inexperienced.


texts:
for programming my ESP-01 chip I bought an "USB Uart", but it looks different to all the ones in all tutorials. I don't know how to connect the uart to the esp.
The uart i bought has following pins: 3V3, DTR, RXI, TX0, GND, +5V. The ESP01 has the known layout (http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family#esp-01).

Once connected: Do I need an external power source, or do i just connect the usb uart to my computer?

Many thanks


texts: Is it possible for Arduino to send a message to the internet without using a GSM shield?

texts:
I need an Arduino to send a message, to be displayed on the web, after pressing a push button, which is connected to an Arduino [or shield], without using a GSM shield.

I need to send a message just by using HTML/PHP code included in the Arduino IDE. This displayed message should contain two buttons. One button is used to turn a LED ON/OFF and the other to open a streaming video.

Can anyone help me with the Arduino code and explain how I should do that? Is there any third party device, apart from a GSM shield, that can help me to send that message?


texts: MPU6050 - Why is my gyro integration incorrect?

texts:
My situation:

I am able to communicate over i2c with my MPU6050 IMU
I can get accelerometer and gyro data
I can compute the sensor's orientation using my accelerometer

Issue:

when trying to compute the sensor's orientation using my gyroscope my values seem to be totally incorrect. I am computing the orientation using a complementary filter.

This is the code I use https://paste.ubuntu.com/p/vZmbnc23gj/

This is the computed orientation, when the sensor is lying on a table: https:https://paste.ubuntu.com/p/W7DzVKR9c7/
Those measurements are totally incorrect, because when moving the senor randomly around its axis it never goes above 1.8. (even when I do an 180 degree turn)

Could somebody give me some hints or explanation on why my results are incorrect and drifting so much?


texts:
i'm still new to arduino and also to C++ and have a short question.
What i want to do is to write a function (in my case to parse the query-string of an URL) to get the parameter names and values (varying number of parameters).

My function looks like the following:

String function readParams()
{
   String params[x]; // x: number of params

   // fill params[0]... params[x] with parameter names

   return params;
}

void loop()
{
   // do some stuff

   String params[x] = readParams();

   for(int i=0; i < x; i++)
   {
      debug(params[i]);
   }
}

What is the correct return-type for the readParams() function in this case?
And how to access the params in the main (loop) -function?

I hope the code makes it clear what i want to do.

Thanks,
Marius


texts: connection between two ARDUINO with xbee

texts:
I have a setup where two XBEES modules are talking to each other, both using XBEE shields, one attached to an UNO ARDUINO and the other a MEGA ARDUINO. One XBEE sends the data and the other receives it and switch on or off a LED.
The problem is the receiver one don't work.
This is the sender code

int led = 13;
const int bouton = 2; String inputString;
void setup() {
pinMode(led, OUTPUT);
Serial1.begin(9600);
Serial.begin(9600);
digitalWrite(led, LOW);
}
void loop() {
while (Serial.available() ) {
// get the new byte:
delay(3);
char inChar = Serial.read();
// add it to the inputString:
inputString += inChar;
}
if (inputString.length() >0) {
Serial.println(inputString);
Serial1.println(inputString);
inputString="";
}
}

This the receiver one

int led = 13;
String inputString;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
while (Serial.available() ) {
// get the new byte:
delay(3);
char inChar = Serial.read();
// add it to the inputString:
inputString += inChar;
}

if (inputString.length() >0) {
Serial.println(inputString);
if (inputString == "on"){
digitalWrite(led,HIGH);
Serial.println("LED ON");
}

if (inputString == "off"){
digitalWrite(led,LOW);
   Serial.println("LED OFF");
}
inputString="";
}
}

I get on the serial monitor of ARDUINO UNO what i wrote in the serial monitor of ARDUINO MEGA but the LED don't switch on or off :/


texts: Simple Speed question - Mapping PWM values

texts:
I am working on an Arduino project for school to power a 12V DC cooling fan.

I want to adjust the speed of the fan. The instructions say to set the motor pin at an equation of (0 to 9) * 10 + 150 to get a range of 150 to 240.

I need to write a mathematical equation but can not figure out what 150 to 240 means.  Is this voltage, resistance...?  Thanks for the help.


texts: Accelerometer MPU-6050 marks timeout in Unity

texts:
I've been having this problem, that I am trying to use an accelerometer MPU-6050 to get the rotation and pass that information to Unity.

I also have some buttons in the same Arduino. I'm using an Arduino Uno. With those buttons, everything works well, but the moment I put something related to the accelerometer in the Arduino code, Unity marks a time out. When I run it on Arduino it sends me all the info I'm asking, so I don't really know what's the problem. I really appreciate if someone could help me.

Here is code on Arduino:

#include<Wire.h>
#define A_R 16384.0
#define G_R 131.0
 #define RAD_A_DEG = 57.295779
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int AcX,AcY,AcZ,GyX,GyY;

float Acc[2];
float Gy[2];
float Angle[2];
int button = 0;
int button2 = 0;
int button3 = 0;

float arriba=0, abajo=0,mouse=0;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  pinMode(7, INPUT); // declare pushbutton as input
pinMode(6, INPUT);
pinMode(5,INPUT);
  Serial.begin(9600);
}

void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  //Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers

  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
 AcZ=Wire.read()<<8|Wire.read();

  Acc[1] = atan(-1*(AcX/A_R)/sqrt(pow((AcY/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
   Acc[0] = atan((AcY/A_R)/sqrt(pow((AcX/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;

  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)

  Angle[0] = 0.98 *(Angle[0]+Gy[0]*0.010) + 0.02*Acc[0];
   Angle[1] = 0.98 *(Angle[1]+Gy[1]*0.010) + 0.02*Acc[1];

        button = digitalRead(7);
  button2 = digitalRead(6);
  button3 = digitalRead (5);

   //Mostrar los valores por consola
   if(button == HIGH){
 arriba=1;
  }else if(button==LOW){
  arriba=0;
  }

  if(button2 == HIGH){
    abajo=1;
  }else if(button2==LOW){
    abajo=0;
  }

  if(button3 == HIGH){  //boton 3
    mouse=1;
  }else if(button3==LOW){
    mouse=0;
  }
  Serial.print(arriba);
  Serial.print(",");
  Serial.print(abajo);
  Serial.print(",");
  Serial.print(mouse);
   Serial.print(",");

   Serial.print(Angle[0]);
   Serial.print(",");
   Serial.println(Angle[1]);

  delay(200);
}

I know this isn't an Unity forum, but here is the code in Unity. The only thing it does, is read it and put the results in an array.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO.Ports;
using System.Globalization;
using System;

using UnityEngine;

public class ConectarArduino: MonoBehaviour
{
    string Recibidos;
    public string Linea, Linea1,Linea2;
    public int Arrib, Abajo,Boton;
    SerialPort stream;
    // Use this for initialization

    void Start()
    {
        stream = new SerialPort("COM3", 9600);
        //  stream.
        stream.Open();
        stream.ReadTimeout = 300;

    }

    // Update is called once per frame
    void Update()
    {
        try
        {
            Recibidos = stream.ReadLine();
            Debug.Log(Recibidos);
        }
        catch (System.Exception e)
        {
            Debug.Log(e.Message);
            throw;
        }

        string[] Values = Recibidos.Split(',').Select(str => str.Trim()).ToArray();
        Linea = Values[0];
        Linea1 = Values[1];
        Linea2 = Values[2];


texts: How to read CPU temperature into Arduino?

texts: I'm not sure about this and if it is possible. I need to read CPU (normal computer) into an Arduino. This could be possible (at least I think) by connecting some kind of sensor that can be placed between the heatsink and the CPU, where the thermal paste is placed. Or, the second option is to read values from the system somehow, or from the motherboard. I hope I'm not talking about stupid things. I need some advice about this.


texts:
HC-05 Bluetooth module does not send or receive data when its on-board light blinks(light blinking after its connected to a device)
as soon as the on-board led starts glowing it does not send or receive data but when the light turns off it works perfectly.


texts: Double clap sensor not working as intended

texts:
I have this double clap sensor code written, it seems it would work but it seems to trigger the double clap even on a single clap, any ideas?

int soundSensor = A1;
int relay = A2;
int relay2 = A3;
int relay3 = A4;
int relay4 = A5;
int claps = 0;
long detectionSpanInitial = 0;
long detectionSpan = 0;
boolean clapState = false;
int doubleClap = 0;

//Light sensor
int photocellPin = A0;     // the cell and 10K pulldown are connected to a0
int LEDbrightness;

//int delayValue = 100;
int photoSensor = 0;

// sound sample
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;

//other
boolean isRelaysOn = false;
void setup() {
  pinMode(soundSensor, INPUT);
  pinMode(relay, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  turnRelayOff();
  Serial.begin(9600);
}

boolean state = false;
boolean lastState = true;
boolean lightTurnedItOff = false;
void loop() {

  /////////////
  // photo sensor
  ////////////////////

  photoSensor = analogRead(photocellPin) > 623;

  /////////////
  // clap sensor
  /////////////////////
  double sensorState = getSoundLevel();
  Serial.println(sensorState);
  double threshold = .2;

  if (sensorState > threshold)
  {
    if (claps == 0)
    {
      detectionSpanInitial = detectionSpan = millis();
      claps++;
    }
    else if (claps > 0 && millis()-detectionSpan >= 50)
    {
      detectionSpan = millis();
      claps++;
      Serial.println(" CLAP ADDED!!!!");
    }
  }

  if (millis()-detectionSpanInitial >= 400){

    if (claps == 2)
    {
      claps++;
      doubleClap = 1 - doubleClap;
      state = !state;
      Serial.println("TWO claps!");

      if(lastState == state ){
        relayControl(doubleClap);
        lastState = !lastState;
      }
    }
    claps = 0;
  }

  if(isRelaysOn == true && photoSensor == 1){
    turnRelayOff();
    lightTurnedItOff = true;
  }
  if(isRelaysOn == true && photoSensor == 0 && lightTurnedItOff == true){
    turnRelayOn();
    lightTurnedItOff = false;
  }

}

void relayControl(int doubleClap){
  /////////////
  // relay control
  /////////////////////

  if(doubleClap == 1){
    turnRelayOn();
    Serial.println("on");
    isRelaysOn = true;

  }
  else{
    turnRelayOff();
    Serial.println("off");
    isRelaysOn = false;
  };

}

void turnRelayOn(){
  int delayAmount = 100;
  digitalWrite(relay, LOW);
  delay(delayAmount);
  digitalWrite(relay2, LOW);
  delay(delayAmount);
  digitalWrite(relay3, LOW);
  delay(delayAmount);
  digitalWrite(relay4, LOW);
  delay(100);
  digitalWrite(relay4, HIGH);
  delay(100);
  digitalWrite(relay4, LOW);
}

void turnRelayOff(){
  digitalWrite(relay, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
}

double getSoundLevel(){

  unsigned long startMillis= millis();  // Start of sample window
  unsigned int peakToPeak = 0;   // peak-to-peak level

  unsigned int signalMax = 0;
  unsigned int signalMin = 1024;

  // collect data for 50 mS
  while (millis() - startMillis < sampleWindow)
  {
    sample = analogRead(soundSensor);
    if (sample < 1024)  // toss out spurious readings
    {
      if (sample > signalMax)
      {
        signalMax = sample;  // save just the max levels
      }
      else if (sample < signalMin){
        signalMin = sample;  // save just the min levels
      }
    }
  }
  peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
  double volts = (peakToPeak * 3.3) / 1024;  // convert to volts

  return volts;
}

Serial monitor:

  0.02
  0.02
  0.02
  0.02
  0.01
  0.01
  2.20
  0.30  CLAP ADDED!!!!
  0.13
  0.09
  0.04
  0.02
  0.02
  0.01
  0.02 TWO claps! on
  1.11
  0.06
  0.05
  0.07
  0.15
  0.10
  0.03
  0.10
  0.06
  0.03
  0.04
  0.06


texts: Undefined functions send() and receive() on TwoWire/SPI

texts: I have downloaded a sketch that uses SPI.  The sketch includes the Wire library but at compilation time, I am getting errors that TwoWire doesn't have methods called send() and receive()?


texts:
Do I Have to Change Internal Interrupt Setups when I Change Clock Speed? The reason I ask is because I am trying to modify this code:

https://github.com/DccPlusPlus/BaseStation/blob/master/DCCpp_Uno/DCCpp_Uno.ino (Beginning at Line 289)

so that if will work on an ATmega328P-derivative board running at 3.3V and 8 MHz. I need the waveforms to be generated at the same speed, so is there anything I have to change? The original code is written for a 16 MHz uno or mega.


texts:
My fellow programmers,

I'm planning on creating a fan controller for my PC using an Arduino Duemilanove and a generic motor sheild. (Fan controllers are not exactly cheap here and i'd rather spend my money on an SSD than on a fan controller =)

On a normal scenario, I want my fans to spin slowly, just to keep some air flowing but not enough to make too much noise. Obviously, they should turn on at full speed (or so) during a demanding scenario, like playing a game.

My idea is to use a usb port to communicate with Windows, so that my arduino knows when a demanding application was started. Is there an easy way to do this or should I buy myself some cheap temperature sensors, place them on the more important parts and control my fans with these temperature readings?

I'd also like to have an option to turn of the communication between the arduino and whatever informs it about the computer usage, so that I can program it in order to test a different algorithm.

Thanks for any help!


texts: Can you current-limit Arduino 101 GPIO pins?

texts:
A number of questions ask about max possible in/out current on a GPIO pin, that's not my question here. I'm asking if it's possible to set a maximum current limit on a GPIO pin, such that any attempts to draw more than that current would result in the Arduino entering a constant current mode e.g. reducing the pin voltage?

I've read this, this, this, and skimmed the Curie datasheet, but I don't see a feature like this mentioned anywhere.

The only half-answer I have seen is on the Ruggeduino website, which explains that they have added a fuse to each GPIO pin to avoid overcurrent draws due to short circuits.

For context - I have an external sensor that claims to be more reliable with a small amount of constant current. I didn't know if I could easily add that limitation (e.g. max 15mA at 3.3V) into the GPIO pin as a safety measure, so I went on a search to find out which has eventually led me here


texts:
I am looking for something like a multiway "relay dimmer".
Which lets me dim a light using an Arduino and a manual dimmer.

(The manual dimmer should work without any computer!)


texts:
I am trying to write a program that fopen()s an image so I can use it later.
I've wired my SD card adapter exactly the way shown here:
[![enter image description here][1]][1]
And I'm using the following code to fopen():
FILE *streamIn;
streamIn = fopen("pic.bmp", "r");

When  I compile, I get the following error:

In function main:
ccA5H011.ltrans0.o:(.text.startup+0x29a): undefined reference to `fopen'

I have the most up-to-date Arduino software.
I am using the Arduino MEGA.
The image "pic.bmp" is 100x100 and is not in any folder of the SD card, it is located right in it instead (If I click on the SD Card in "My Files" when it is plugged into my computer, pic.bmp is there).


texts: Arduino 2560 as an Interface to 4 Serial Hardwares

texts:
I am writing a software that runs on the PC that has a Arduino 2560 connected to it via USB. This PC needs to communicate with multiple devices through RS232.

Is it possible to use the Arduino's 4 UARTs to communicate with 4 different hardware that uses RS232 serial communication, using just 1 USB connection between the PC and the Arduino 2560?

The Arduino 2560 will basically act as an interface for 1 USB to talk to 4 RS232 devices.


texts: How to get my Arduino to say specific things

texts: So, I am designing an Arduino with a machine learning model to detect the objects around it. I want the model to make a sound if it 100% detects an object through the speaker that is connected to it. How do I go about doing it?  I am fairly new to Arduino and any help would be really appreciated.


texts: Simulating Raspberry Pi Robot using software

texts:
I have to make a simple Raspberry Pi Robot that can be controlled from a mobile/ desktop app as a college project. The problem is due to COVID-19 I don't have access to any hardware and so I will have to do all the work online.
Please see this 3 min video here. If I had hardware access then this is what I'd have made. Please suggest me some ways to do the same on software.
Thank you.


texts: cant figure out how to fix this compile error

texts:
evrything worked for a bit and changed to much to get it working again. dont really understand the error.

[![C:\Users\bavob\AppData\Local\Temp\ccyfrkaL.ltrans0.ltrans.o: In function `loop':

C:\Users\bavob\Documents\Arduino\counte_up/counte_up.ino:96: undefined reference to `num_Write(int)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Fout bij het compileren voor board Arduino/Genuino Uno]1]1

  { 1, 1, 1, 1, 1, 0, 1 }, // 0
  { 0, 1, 1, 0, 0, 0, 0 }, // 1
  { 1, 1, 0, 1, 1, 1, 0 }, // 2
  { 1, 1, 1, 1, 0, 1, 0 }, // 3
  { 0, 1, 1, 0, 0, 1, 1 }, // 4
  { 1, 0, 1, 1, 0, 1, 1 }, // 5
  { 1, 0, 1, 1, 1, 1, 1 }, // 6
  { 1, 1, 1, 0, 0, 0, 0 }, // 7
  { 1, 1, 1, 1, 1, 1, 1 }, // 8
  { 1, 1, 1, 0, 0, 1, 1 }  // 9
};

int pin = 2;
int buttonState = 0;
const int button = 12;
int led = 13;
int randVal;
bool pressVal;
void num_Write(int);
void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  pinMode(button, INPUT);
}

void loop() {
  buttonState = digitalRead(button);
  if (buttonState == LOW) {
    turnOff();
    pressVal = false;
  }
  else
  {
    if (pressVal == false)
    {
      randVal = rand() % 10;
      pressVal = true;
    }
    Serial.println(randVal);
    if (randVal == 0)
    {
      void zero(int number);
      num_Write(0);
    }
    else if (randVal == 1)
    {
      void one(int number);
      num_Write(1);
    }
    else if (randVal == 2)
    {
      void two(int number);
      num_Write(2);
    }
    else if (randVal == 3)
    {
      void three(int number);
      num_Write(3);
    }
    else if (randVal == 4)
    {
      void four(int number);
      num_Write(4);
    }
    else if (randVal == 5)
    {
      void five(int number);
      num_Write(5);
    }
    else if (randVal == 6)
    {
      void six(int number);
      num_Write(6);
    }
    else if (randVal == 7)
    {
      void seven(int number);
      num_Write(7);
    }
    else if (randVal == 8)
    {
      void eight(int number);
      num_Write(8);
    }
    else
    {
      void nine(int number);
      num_Write(9);
    }
  }
}

void zero(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}

void one(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}

void two(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void three(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void four(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void five(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void six(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void seven(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void eight(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void nine(int number)
{
  for (int j = 0; j < 7; j++) {
    digitalWrite(pin, num_array[number][j]);
    pin++;
  }
}
void turnOff()
{

}


texts: How do I convert this program to assembly from c++

texts:
I am trying to implement a program in assembly code for an Arduino UNO. A potentiometer is used on an ADC pin for variable time (t). LED1 flashes for t seconds, then stays on for t seconds, then goes off and another LED(LED2) goes on for t seconds and then the cycle repeats (t is variable time that comes from potentiometer). I have a working program in c++ but I want to convert it to assembly. I have just started learning assembly and am not very good at it.

The part I am really stuck on is the analogRead() function. I do not know how to implement this on assembly. Anyone know how to do this?

#define led 3
#define led2 2

void setup()

{

Serial.begin(9600);

//initializing pins
pinMode(led,OUTPUT);

pinMode(led2,OUTPUT);

}
void loop()

{

// read the input on analog pin 0:
int sensorValue = analogRead(A0);

// Convert the analog reading(which goes from 0 - 1023) to a voltage(0-5V):
int voltage = sensorValue * (5.0 / 1023.0);

// print out the value you read:
Serial.println(voltage);

for(int i=0;i<2*voltage;i++)

{

digitalWrite(led,LOW);

delay(100);

digitalWrite(led,HIGH);

delay(100);

}

//red stays on
digitalWrite(led,HIGH);

delay(voltage*500);

digitalWrite(led,LOW);

//green stays on
digitalWrite(led2,HIGH);

delay(voltage*500);

digitalWrite(led2,LOW);

}


texts:
Can I use Bluetooth Low energy devices as micro controllers directly instead of communicating to Arduino e.g. HM-10/11 or even HC-05/06 ? If so what are limitations e.g. can  I hook sensors or control other stuff like LEDs or transistors with PWM ?

I have built a motion sensor, which consists of Arduino, Bluetooth Low energy HM-11, battery and sensor itself. It worked just fine, but one guy told me that Arduino may be completely unnecessary and that Bluetooth module could replace its functionality !
I then started digging for information, and either it's impossible or I am terrible at googling. Everything I found was info about some kind of development kits for HM-10/11, also pin outs of those boards. They do have some IO pins, which can mean it's possible, but I found no tutorials nor examples on how to program those boards and use with other components.


texts: Arduino DC motor causes disturbance. What can cause it?

texts:
I tried to fix this problem the whole weekend but, after no success I decided to post it here. I would really appreciate any help.

The problem

The Wi-Fi module activates the DC motor and lets it run for 3 seconds, but when the DC motor stops after that 3 seconds, the Wi-Fi module and display don't respond anymore.  It only works once.  (After I push the reset button the same thing happens.)

Question

What causes this disturbance? Any advice on my circuit? (I included a Fritzing Diagram because I am bad at drawing schematics)

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial ESP8266(9, 8); // RX = 8 en TX = 9

#define DEBUG true

boolean FAIL_8266 = false;
int LED = 13; // led op 13

int secondeAan = 3000;

String my_AP_SSID = "myID";
String my_AP_Pass = "myPass";

void setup()
{
  // -- stel led in --
  pinMode(LED, OUTPUT);

  // -- lcd scherm --
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 1);

  do {
    ESP8266.begin(115200); // start communicatie met esp8266

    //Wait Serial Monitor to start
    while (!Serial);

    lcd.clear();
    lcd.print("--- Start ---");

    ESP8266.print("AT\r\n");
    delay(500);

    if (ESP8266.find("OK"))
    {
      FAIL_8266 = false;
      sendData("AT+RST\r\n", 4000, DEBUG);
      sendData("AT+CWMODE=3\r\n", 2000, DEBUG);
      sendData("AT+CWJAP=\"" + my_AP_SSID + "\",\"" + my_AP_Pass + "\",9,4\r\n", 2000, DEBUG);
      sendData("AT+CIFSR\r\n", 2000, DEBUG);
      sendData("AT+CIPMUX=1\r\n", 2000, DEBUG);
      sendData("AT+CIPSERVER=1,80\r\n", 2000, DEBUG);

    } else {
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("Module have no response.");
      delay(500);
      FAIL_8266 = true;
    }
  } while (FAIL_8266);
}

void loop()
{
  // Get the number of bytes (characters) available for reading from the serial port
  if (ESP8266.find("+IPD,"))
  {
    lcd.clear();
    lcd.print("Nieuwe connectie");
    // -- sluit connectie --
    motorToggle();
    sendData("AT+CIPCLOSE=0\r\n", 100, DEBUG);
    sendData("AT+CIPCLOSE=1\r\n", 100, DEBUG);
    sendData("AT+CIPCLOSE=2\r\n", 100, DEBUG);
  }
}

void motorToggle () {
  digitalWrite(LED, HIGH);
  lcd.clear();
  lcd.print("eten gegeven");
  delay(secondeAan);
  digitalWrite(LED, LOW);
  delay(200);
}

String sendData(String command, const int timeout, boolean debug)
{
  String response = "";

  ESP8266.print(command); // send the read character to the esp8266

  long int time = millis();

  while ( (time + timeout) > millis())
  {
    while (ESP8266.available())
    {
      char c = ESP8266.read();
      response += c;
    }
  }

  if (debug)
  { lcd.clear();
    lcd.print(response);
  }

  return response;
}


texts: Re-use smartphone/tablets parts like a camera

texts:
For learning and hacking purposes, I plan to study and use parts from smartphones and tablets like Galaxy or iPhone. They are really efficient and pretty cheap...

Did anybody do this before? If yes, can anybody tell me what kind of connector is this one on the galaxy camera, Galaxy Tab S 10.5 Front Facing Camera (Wi-Fi), and whether it can be found for attaching it to an Arduino project?

Edit: Someone else asked a similar question here, How to reuse quality camera from old / broken phone.


texts:
I used 2 relay modules. One single channel 5 volt and  another 2 channel 5 volt. On connecting 5v of arduino uno the relay modules arent getting on(led on modules not on). 2 channel once worked with 9volt dc adapter supplying to arduino board.By work i mean the led on relay blinked as per code but no clicking sound.The next time i made the exact same connection and code it didn't work..Single channel arent working with 9v adapter also.Sometimes the led on single channel module is on but no switching and most of the times its not even getting on.i used 9 volt battery to supply vcc and ground to single channel module.This turned on the led on it but no switching.i don't understand how 9 volt powered 5 volt single channel relay without burning it.
Connection :: vcc to 5 v (arduino)   gnd to gnd on arduino
Digital pin 8 to in of module.
I used the blinking led type code and tried with and without serial.begin. Arduino is working as serial monitor was giving on /off output at every 2 second.
Load::200 watt bulb from 220 volts AC...under the limit of my modules i.e. 10A 230 volts
I tried 4 different single channel modules and 1 double channel.


texts: How to connect more than one arduino serial port together

texts:
The idea is to connect more than 1 arduino slave to master as shown in schamatic

simulate this circuit – Schematic created using CircuitLab
The problem is TX slave can not just combine to master RX.
It need to done some trick like tri-state buffer to make slave TX one at time.
Anyway, avr port can config as tristate buffer.
(Q1)Is there any software solution to done this?
Second If I connnect TX to RX for half-duplex communication (using 1 data line). How to make Rx stop listenning to its self while transmiting data?


texts: I want to hook up a potentiometer to my arduino (Leonardo) as a voltage divider with the middle pin to an analog pin. I want to use the highest resistance to save power. I looked on the datasheet and it said the maximum output impedance is 10kOhm (§24.7.1 on Atmega32u4 datasheet). I also found another question that said I should use a 10kOhm potentiometer. What doesn't make sense is if the knob was turned towards the middle so that there is 5k on both sides, it's not the maximum capable resistance. So should I use a 20kOhm potentiometer?


texts: This is mostly a conceptual question. Is it possible to have two scripts running on an Arduino, where one is a Julia script, and one is a Python script or something like that?


texts: Global Variable not able to be accessed in function?

texts:
I am trying to compile an Arduino program that takes analog input. However, when I declare multiple global variables, it often will not compile and because it throws an error that the variables aren't within scope of the functions within the program. I am not super familiar with Arduino IDE, but this doesn't programmatically make sense to me.

This is the program:

/*
*  By Hannah Perner-Wilson, www.plusea.at
*  Modified 3/30/2012 By Brian E Kaminski, www.AdvancerTechnologies.com
*
*  IMPORTANT!!:
*  Scroll down to set your serial port
*  Scroll down to set your thresholds
*/

import processing.serial.*;

// definition of window size
// you can change the size of the window as you like
// the thresholdGraph will be scaled to fit
// the optimal size for the thresholdGraph is 1000 x 400
int xWidth = 1200;
int yHeight = 750;

// xPos input array, using prefix
int[] xPosArr= {0,0,0,0,0,0};

//
int[] messageArr= {0,0,0,0,0,0};

// Arrays for threshholding
int[] threshMax= {0,0,0,0,0,0};
int[] threshMin= {0,0,0,0,0,0};

// variables for serial connection. portname and baudrate are user specific
Serial port1;

//Set your serial port here (look at list printed when you run the application once)
String V3 = Serial.list()[1];
String portname1 = V3;
int baudrate = 9600;

int prefix = 10001;
boolean myCatch = false;
String serialIN = "";
String serialINPUT = "";
String buffer = "";
int value = 0;

// ThresholdGraph draws grid and poti states
ThresholdGraph in;

void setup(){
  // set size and framerate
  size(xWidth, yHeight);
  frameRate(25);
  background(255);
  strokeWeight(5);
  stroke(0);
  smooth();
  strokeCap(ROUND);

  // establish serial port connection
  port1 = new Serial(this, portname1, baudrate);
  port1.bufferUntil('\n') ;
  println(Serial.list());  // print serial list

  // create DisplayItems object
  in = new ThresholdGraph();

  // THRESHOLD VALUES:
  // using the thresholdGraph you can determine the MIN and MAX values
  // of your sensors. Enter these here. They must lie between 0 and 1000.

    //MIN trashhold
    threshMin[0] = 20;   // one
    threshMin[1] = 20;   // two
    threshMin[2] = 20;   // three
    threshMin[3] = 20;   // four
    threshMin[4] = 20;   // five
    threshMin[5] = 20;   // six

    //MAX trashhold
    threshMax[0] = 600;   // one
    threshMax[1] = 600;   // two
    threshMax[2] = 600;   // three
    threshMax[3] = 600;   // four
    threshMax[4] = 600;   // five
    threshMax[5] = 600;   // six
}//end setup

// draw listens to serial port, draw
void draw(){

  // listen to serial port and trigger serial event
  while(port1.available() > 0){
        serialIN = port1.readStringUntil('\n');
        //println((int)float(serialIN));
        if(serialIN != "")
          serialEvent(serialIN);
        else
          Serial.println("found empty");
        }

  // threshold serial input
  threshHolding();

  // draw serial input
  in.update();
}//end draw()

The error that are being thrown are:

testproject.ino:100:17: error: 'threshHolding' was not declared in this scope
testproject.ino:103:3: error: 'in' was not declared in this scope
Error compiling.


texts: Arduino Yun - not enough i2c & interrupt pins?

texts:
I'm trying to build a small personal weather station. The rain sensor, and wind speed sensor use interrupts. The barometric sensor uses i2c SDA and SCL.

Reading the Arduino Yun manual, it says there are 5 interrupt pins, but 2 of them are SCL/SDA (pins D2 and D3), and 2 of them are serial comms between Linio and the 32U4 (pins 0 and 1).

This leaves me with 1 interrupt pin left (pin 7).

Is there a work around to get my 2 digital sensors AND SDA SCL pins connected?

If I do use pins 0 and 1 (Linux serial), what do I risk? I will need to use the Bridge to relay information to the internet.


texts: Trying to send data to the server and AT+CIPSEND not working correctly

texts:
Sending data to the server(thingspeak.com/184.106.153.14) with AT commands on serial monitor works fine but whenever i upload the sketch ,the following always return false if(Serial.find( ">" ) ). I am not sure if AT+CIPSEND is not working correctly or what. I am using Arduino with ESP8266. Any help will be appreciated.Thanks you in advance. Here is my code.

  #include <SoftwareSerial.h>
  SoftwareSerial softSerial(2, 3); // RX, TX

  #define SSID "myssid"
  #define PASS "Mypass"
  #define IP "184.106.153.149" // ThingSpeak

  void setup()
  {
   uint32_t baud = 9600;
   Serial.begin(baud);
   softSerial.begin(baud);

   connectWiFi();
   }

   void loop()
   {
    updateTS();
    }

    void updateTS()
    {
    String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
    cmd += IP;
    cmd += "\",80";
    sendDebug(cmd);
    delay(2000);

    String url = "GET /update?key=P55Z0BDASNQBFQKT&field1=15&field2=25\r\n\r\n"; //hard code value 15 and 25
    String stringLength="AT+CIPSEND=";
    stringLength +=String(url.length( ));
    Serial.println(stringLength);
    //delay(10000); I even tried to delay for few seconds

   //Here is where it fails,it jumps to closing the connection
   if(Serial.find( ">" ) )
    {
     softSerial.print(">");
     softSerial.print(cmds);
     Serial.print(cmds);
    }
    else
    {
     sendDebug( "AT+CIPCLOSE" );//close TCP connection
    }

    }

   void sendDebug(String cmd)
    {
      softSerial.print("SEND: ");
      softSerial.println(cmd);
      Serial.println(cmd);
     }

     boolean connectWiFi()
    {
      Serial.println("AT+CWMODE=1");
      delay(2000);
      String cmd="AT+CWJAP=\""; // Join accespoint
      cmd+=SSID;
      cmd+="\",\"";
      cmd+=PASS;
      cmd+="\"";
      sendDebug(cmd);
      delay(5000);
      if(Serial.find("OK"))
      {
       softSerial.println("RECEIVED: OK");
       return true;
      }
      else
      {
       softSerial.println("RECEIVED: Error");
       return false;
       }
     }


texts: How does one build an arduino version of a slime controlled robot?

texts: Recently robots controlled by the emotions of biological slime have been built. See for example the New scientist article titled robot move by fear of slime mould. The hard part of building an arduino version of this robot is ro figure out a DIY method-that works as well as thier method-to interface the slime to an arduino and workik out a algorithm to communicate with the slime-so how is this interfacing done?


texts: How to run led and buzzer at the same time?

texts:
I am making a police light and siren but the delay on light (); affects the buzzers  delay tone

This is the code:

//PIN 9 - Buzzers
int f,d;
int t =0;

void setup()
{
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
}

void loop()
{
    buzzer ();

}

void buzzer () {

  for(f=635;f<=912;f++)
    {
        tone(9, f);
        delay(d);
        d=10;

        light ();
    }

    for(f=911;f>=634;f--)
    {

        light ();
        tone(9, f);
        delay(d);
            d=9;

    }

}

void light() {
 digitalWrite(5,HIGH);
  delay(t);
  digitalWrite(5,LOW);
  delay(t);

  digitalWrite(5,HIGH);
  delay(t);
  digitalWrite(5,LOW);
  delay(t);

  digitalWrite(5,HIGH);
  delay(t);
  digitalWrite(5,LOW);
  delay(t);

  digitalWrite(7,HIGH);
  delay(t);
  digitalWrite(7,LOW);
  delay(t);

  digitalWrite(7,HIGH);
  delay(t);
  digitalWrite(7,LOW);
  delay(t);

  digitalWrite(7,HIGH);
  delay(t);
  digitalWrite(7,LOW);
  delay(t);

  digitalWrite(5,HIGH);
  digitalWrite(6,HIGH);
  digitalWrite(7,HIGH);

  delay(t);

  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  digitalWrite(7,LOW);

  delay(t);

  digitalWrite(5,HIGH);
  digitalWrite(6,HIGH);
  digitalWrite(7,HIGH);

  delay(t);

  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  digitalWrite(7,LOW);

  delay(t);

  digitalWrite(5,HIGH);
  digitalWrite(6,HIGH);
  digitalWrite(7,HIGH);

  delay(t);

  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  digitalWrite(7,LOW);

  delay(t);

  digitalWrite(5,HIGH);
  delay(t);
  digitalWrite(5,LOW);
  digitalWrite(7,HIGH);
  delay(t);
  digitalWrite(7,LOW);
  delay(t);

  digitalWrite(5,HIGH);
  delay(t);
  digitalWrite(5,LOW);
  digitalWrite(7,HIGH);
  delay(t);
  digitalWrite(7,LOW);
  delay(t);

  digitalWrite(5,HIGH);
  delay(t);
  digitalWrite(5,LOW);
  digitalWrite(7,HIGH);
  delay(t);
  digitalWrite(7,LOW);
  delay(t);

  digitalWrite(5,HIGH);
  delay(t);
  digitalWrite(5,LOW);
  digitalWrite(7,HIGH);
  delay(t);
  digitalWrite(7,LOW);
  delay(t);

}


texts: Compilation error when trying to give pointer to a function to another function

texts:
I'm trying to write a library for Arduino using the Wire library.
Here's my code:

PiCom.h:

#ifndef PiCom_h
#define PiCom_h

#include "Arduino.h"
#include <Wire.h>
class PiCom
{
public:
    PiCom(int address, int* integers[], double* doubles[]);
    static void onReceiveCallback(int numbytes);
    static void onRequestCallback();
private:
    //Actually arrays of pointers to the data to be sent, has to be declared that way cause the size of the array isn't known at compile time
    int** _integers;
    double** _doubles;

    void onReceive(int numbytes);
    void onRequest();

    static PiCom instance;
};

#endif

PiCom.cpp:

#include "Arduino.h"
#include "PiCom.h"

static void onReceiveCallback(int numbytes)
{

}

PiCom::PiCom(int address, int* integers[], double* doubles[])
{
    _integers = integers;
    _doubles = doubles;

    Wire.begin(address);
    void (*receiveFunction) (int);
    receiveFunction = &PiCom::onReceiveCallback;
    Wire.onReceive(receiveFunction);//Here i get an error
}

I want the  constructor to be created when a new instance is created. A mehtod in this object should be called when data is requested or received. When trying to pass onRequest(int) directly to Wire.onRequest(void (*) (int)) an error is thrown. Same happend when saving it to receiveFunction.

This problem was solved by using a static function (onReceiveCallback(int). I wanted this static function to call onRequest(int) in the object saved into PiCom::instance.

But now i'm getting another error:

PiCom\PiCom.cpp.o: In function `PiCom':
C:\Program Files\Arduino\libraries\PiCom/PiCom.cpp:26: undefined reference to `PiCom::onReceiveCallback(int)'
C:\Program Files\Arduino\libraries\PiCom/PiCom.cpp:26: undefined reference to `PiCom::onReceiveCallback(int)'


texts: Is there some better documentation somewhere for Arduino classes and API's?

texts:
For example, it looks like Serial extends HardwareSerial, which extends Stream, which extends Print. But I don't think you can figure this out by reading the reference documentation on https://www.arduino.cc/ and it doesn't appear that you can easily navigate the class hierarchy in the Arduino IDE. They seem to go out of their way to hide the class hierarchy?

I guess I'm spoiled by modern languages that have automatically generated documentation, but it seems like there should be a more complete reference somewhere?


texts:
So I am doing a project where a bunch of servos are moving from 90 - 120 degrees and slowly speed up over time until they reach their max speed and so stay at that speed.
This is being done by editing the delay under the servo sweep for loop.
However though this works it doesn't work with the next component.

WHat I want to happen next is an MFRC522 RFID reader to always be scanning and at any time it detects a card and verifies it the servos from whatever speed they are now at start to slow down.
The problem is I can't get the two functions to run simultaneously. IF the servo is running its sweep function it must finish before the RFID tag can scan. This makes the whole device look very lagy.
Is there a way I can get the RFID scanner to be reading all the time even when the servo sweep for loop is working?

Here is the code:
Please note that I have put printins everywhere to see how often the RFID is scanning etc just while I test the code out.
I essentially have two functions one called nocardservo and yescardservo each one activating if there is a card there or not.
Any help would be fantastic!!

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

#define RST_PIN     9       //
#define SS_PIN      10      //

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

Servo myservo;
int pos = 0;
int y = 15;
int z = y;
void setup() {
  myservo.attach(6);
  myservo.writeMicroseconds(1518);
  Serial.begin(9600);       // Initialize serial communications with the PC
  while (!Serial);      // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();       // Init MFRC522
  //ShowReaderDetails();    // Show details of PCD - MFRC522 Card Reader details
  //Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
}

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
nocardservo();
    return;
  }
  delay(20);
  Serial.println("carddetected");
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {

  }
  Serial.println("correctcard");
  yescardservo();
delay(20);
return;
}

//***If card not detected this function runs**//

void nocardservo() {

  for (pos = 90; 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 >= 90; pos -= 1) // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);

  }
}
}

//***If card is detected this function runs**//

void yescardservo() {

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

  }

}


texts: Arduino Mega - I2C pins (20/21) unreliable

texts:
Has anybody else noticed that the Arduino Mega pins 20/21 are exceedingly unreliable over long periods of time? It has been the case four times now where I have hooked up no more than 3 I2C devices to these pins and had them fail after approx. 10 days of light use on average.

For example, my team and I had 3 sensors hooked up and were successfully running tests for about two weeks, then right before our launch, I2C stopped working entirely, returning completely incorrect (all zero) data every time.

Again, I have had this issue four separate times in the past, some where pull-up resistors are present, others not.

I seem to be unable to find related information on the web.

Has anyone else noticed this?


texts:
Increase the number of digital pins

There are many post that explain how to use more than just the standard pins on the various arduinos but none of them explain the limitations and the proplems properly.

Arduino Uno:

1.You can use the analog pins

Pin 14 = Analog in 0
Pin 15 = Analog in 1
Pin 16 = Analog in 2
Pin 17 = Analog in 3
Pin 18 = Analog in 4
Pin 19 = Analog in 5

digitalWrite(14,HIGH);
or
digitalWrite(A0,HIGH);

2.You can't use both SDA , SCL & A4 , A5 as they are basically the same (18,19).

3.You can also use the TX/RX.

  "Don't do it, you break the serial communication..."

  "Never use pins 0 and 1"

  "you can't use the TX/Rx Pins"

You can... but you need to take precautions. Which ones?

It should have software serial over USB, right?

Or do i break the USB serial?

Are there internal Chip problems if i use TX/RX?

As i use those TX/RX pins in the code i probably should not use Serial.print()?

What happens if i forget to remove Serial.print() after uploading the code that use pins 0,1?

How to hardware reset the arduino/bootloader if something goes wrong?

As there are various other Arduino's that use different chips, is the above valid for all Atmel chips?

So, what shuold i know before using those TX/RX or also maybe the other analog pins?

  There are cheap shiftregisters, pwm drivers, led drivers, spi, i2c and
  more ic's to expand your I/O

But if there are not to big problems it means that the arduino has 20 I/O pins...

You could theoretically control:

17x3 = 51 = 17 RGB leds (multiplexing, pwm sourcing&sinking);
14x6 = 84 leds (multiplexing, pwm on 6 rows/colums );
10x10 = 100 leds (multiplexing, high low);
20x(20-1) = 380 leds (charlieplexing, high low);
// yes it would flicker

Correct me if i'm wrong. That means you are able to control 380 "Whatever" using diodes and one arduino.


texts: Make an Xbox 360 controller with an Arduino Uno

texts: I was thinking of making a custom Xbox 360 controller (racing wheel) with the Arduino Uno plugged into the Xbox. How would I emulate the buttons/triggers on the original controller with the Arduino? Is there a library that can help me do this?


texts: softwareserial between arduino uno and esp8266

texts:
I have an Arduino UNO and HUZZAH ESP8266  module.  I need to send data between Arduino UNO and ESP module via Software Serial.  Right now I have the ESP module write data and Arduino UNO display data, but not working. When I run the Arduino UNO  and open its Serial Monitor, nothing is printed using below source code.

ESP8266 RX PIN connected to Arduino UNO PIN 2.
ESP8266 TX PIN connected to Arduino UNO PIN 3.
Using the FTDI cable that came with HUZZAH ESP8266 to power this module.  I just individually connected the RX and TX pins to the ARDUINO PIN 2 and 3 as mentioned above.

Any ideas what why not working? Below is code for both modules. Thanks,

Arduino UNO

#include <SoftwareSerial.h>

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

void setup(void){
  //Start hardware Serial communication
  Serial.begin(115200);

  //Start the software serial for communication with the ESP8266 component
  ESPserial.begin(57600);

}

void loop(void){

if (ESPserial.available()){
  Serial.println("ESP available!!!");
  Serial.println(ESPserial.read());
}

}

HUZZAH ESP8266

#include <ESP8266WiFi.h>

#include <SoftwareSerial.h>

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

void setup(void){
  //Start the software serial for communication with the Arduino UNO component
  ESPserial.begin(57600);

  //TODO: setup Wifi
}

void loop(void){
   ESPserial.write("This message generated by ESP module.");
   delay(500);
}


texts: Switch two or more digital outputs of ESP8266 at the same time

texts:
I'd like to control some digital ICs with a ESP8266-12.

How can I switch 2 pins to HIGH in the same moment?
How can I switch one to LOW and the other to HIGH in the same moment?
Is it possible with every port or only with grouped ports and how are the groups?


texts:
I'm trying to send a byte from an Arduino Nano I2C slave to a Raspberry Pi 3B Master by directly connecting the two I2C pins of each device with no external pull-ups or level converters. It mostly works but the high bit is sometimes misread as a 0 when it should be a 1.

It seems to be caused by that bit being put on the data line at the same time as the clock rising edge so it's not clearly a 0 or a 1. Here's a scope trace showing what I think the problem is for slave address 4 (binary 0000100) and data 231 (binary 11100111). Why is it doing that and how can I fix it?

Another guess is that the Raspberry Pi might be holding the data line low and blocking the slave's value.

Using Wire library on the Arduino and SMBus on the Pi.

EDIT: I added a level converter and the problem is still there, so it's not caused by the 3.3V/5V difference.


texts: I'm using a PWM port and outputting a freq. Is it possible to pulse the PWM port using software to simulate a pulse gate. For example, I'd like to output a freq of 111hz, but would like to gate that freq at .5-7hz. Is this possible to do all in software without external hardware. I'm using a Teensy board which is similar to an Arduino, but has 3 independent PWM ports. Any ideas on whether this possible?


texts: Minimum circuitry required to program an AVR

texts:
Where is the information what is the minimum-required circuitry to program any AVR via ICSP?

Sometimes I see schematics that show just the chip and the six wires for the ICSP header (RESET, VCC, GND, MISO, MOSI, and SCK).

Other times, I see some passive components connected to some of the pins.

So why is it different some times? How do people know when to use extra components when wiring up the chip for programming? Do the datasheet for these MPU's provide the details?


texts: Constantly read analog in in SWITCH/CASE setup

texts:
I'm writing a program with three different cases. Case one an LED is off, in another it is on and in the last case the brightness is controlled by a potentiometer. Each case works as I press the button. The issue I am having is with the third case. The potentiometer is read only once and the LED is set accordingly. I would like the LED to be adjusted continuously until the button is pushed again and the case is switched to off. I used the Serial.print to see the valves read from the potentiometer. I verified its only read once on each cycle through the different cases. I also changed from a SWITCH/CASE to If statements and it only reads the potentiometer once.

CODE HAS BEEN UPDATED

//-------------------------------------------------------
// BUTTON AND POT - TEST
// KNOWN ISSUE - POT ONLY TAKES ON READING
// vonderasche
// 7/28/2016
//-------------------------------------------------------

const int BUTTON_PIN = 9;
const int LED_PIN = 3;
const unsigned long DEBOUNCE_TIME = 50;

int val = 0;
int pot = 0;

int state = 0;

void setup()
{
    pinMode(BUTTON_PIN, INPUT_PULLUP);
    pinMode(LED_PIN, OUTPUT);
    Serial.begin(9600);
}

bool button_press()
{
    static bool last_state;
    static unsigned long last_state_change;
    unsigned long now = millis();

    if (now - last_state_change < DEBOUNCE_TIME)
        return false;

    bool state = digitalRead(BUTTON_PIN);
    if (state != last_state) last_state_change = now;
    bool press = last_state && !state;
    last_state = state;
    return press;
}

void loop()
{

    unsigned long now = millis();
    static enum { OFF, ON, POT } state;

    if (button_press()) switch (state) {
    case OFF:
        analogWrite(LED_PIN, 255);
        state = ON;
        Serial.println(state);
        break;
    case ON:
        analogWrite(LED_PIN, 0);
        state = POT;
        Serial.println(state);
        break;
    case POT:
        Serial.println(state);
        int Mode = button_press();
        while (val < 1023) {
            val = (analogRead(pot) / 4);
            analogWrite(LED_PIN, val);
            Serial.println(val);
            state = OFF;
            break;
        }
    }
}


texts: Does the Arduino deteriorate after shorting the voltage regulator?

texts: I mistakenly connected a 7.4V battery backwards to an Arduino Nano via the Vin pin. The Arduino still works (I can upload code) connecting it to the PC using the USB cable. Here's my question: will the Arduino deteriorate using this method or can I continue using it (I'm soon going to buy a new voltage regulator)?


texts: Arduino UNO two SoftwareSerial ports communication

texts:
I am working on a project involving bluetooth and wifi communications. Both of them are wired up to the Arduino and communicate to it using two software serial port.
The scenario is the one in the picture attached.

What I am doing is:

retrieve the sensor value
send it from the BT slave module to the master one (wired up to Arduino)
take it and send it, using AT commands, through the WIFI channel (the WIFI module is a ESP8266-01) to a web server.

The problem is that if I start listening to the BT serial port (BTSerial.listen()) I am not able to properly send the sensor values through the WIFI connection. But if I comment out the lines related to the BT sotware serial, and try to send fixed value to the web server, the sending terminates succesfully.

In my opinion there are some problems with the BTSerial.listen() and WIFISerial.listen() calls, since they are not able to switch from one the the other correctly.

I saw the TwoSerialPort example provided into the Arduino IDE and I tried to apply it into my code but it still not works to me.

Does anyone have a idea which would be the problem? Does anyone already faced with this problem or a similar one?

Hoping to be as much clear as possible, thanks in advance to anyone would help me.

Filippo

[EDIT] Added two code snippets

// This method prepares the AT commands will be send to the ESP8266-01 module in order to upload the values on the web server
void send2server(String ip, int port, String file, int t, int h, int p) {

  String queryString = "temp=";
  queryString.concat(t);
  queryString.concat("&hum=");
  queryString.concat(h);
  queryString.concat("&press=");
  queryString.concat(p);
  Serial.println(queryString);

  // Prepare and exec the AT+CIPSTART command provideing the TCP connection init
  String CIPSTART_cmd = "AT+CIPSTART=\"TCP\",\"" + ip + "\"," + port + "";
  exec_cmd(CIPSTART_cmd, 1000);

  // Prepare the POST request
  String httpPOST_cmd = "POST /";
  httpPOST_cmd.concat(file);
  httpPOST_cmd.concat(" HTTP/1.1\r\n");
  httpPOST_cmd.concat("Host: ");
  httpPOST_cmd.concat(ip);
  httpPOST_cmd.concat("\r\n");
  //httpPOST_cmd.concat("Accept: */*\r\n");
  httpPOST_cmd.concat("Content-Length: ");
  httpPOST_cmd.concat(queryString.length());
  httpPOST_cmd.concat("\r\n\r\n");
  //httpPOST_cmd.concat("Content-Type: text/html\r\n\r\n");
  httpPOST_cmd.concat(queryString);

  // Calculate the POST request length
  unsigned int len = httpPOST_cmd.length();

  // Prepare and exec the AT+CIPSEND statement with the POST request length just calculated
  String CIPSEND_cmd = "AT+CIPSEND=";
  CIPSEND_cmd.concat(len);
  exec_cmd(CIPSEND_cmd, 1000);

  // Exec the HTTP POST request
  exec_cmd(httpPOST_cmd, 1000);

  // Close the connection
  exec_cmd("AT+CIPCLOSE", 1000);
}

// This method execute each AT command in the previuous method
void exec_cmd(String cmd, int delayTime) {
   byte i = 0;

   while(1) {
      Serial.println("invio comando");
      WIFISerial.println(cmd);
      while(WIFISerial.available()) {
         if(WIFISerial.find("OK")) {
            i = 8;
         }
      }
      delay(delayTime);

      if(i > 5)
         break;

      i++;
   }

   if(i == 8) {
      Serial.println("OK");
      //return true;
   } else {
      Serial.println("ERRORE");
      //return false;
   }
}

The problem is the code goes properly till the AT+CIPSEND command, then the POST request is sent but no good feedback arrives, ending with the "ERRORE" error message.

[EDIT 2] Attached serial monitor output
This is the serial monitor output when I execute the skecth. It seems to work properly but it does not upload any value.


texts:
I'm trying to optimize the communication (minimize wires) on a project where I can control a motor and toggle some 230V devices by using RS485 and I2C.

On this project, I'm using an Arduino (Mega) for the control panel (buttons, potmeters, LED segment display (I2C) etc.).

I'm using the RS485 protocol (Modbus RTU) to control an inverter by using a MAX485 TTL converter. Now I also have a relay board (8 channel) to be able to toggle some lightning and sound devices. Both the inverter and the relay board, as well as the power supply, are located in another box, which I call the power box. Between the control panel and the power box will be a cable.

[Control Panel (with arduino mega)] <--cable--> [power box (with inverter, 8 channel relay board and 230V devices)]

I've got the following requirements:

The cable should have a minimum amount of wires (5V, Ground, 485+(A) and 485-(B) for sure)
The total length of the cable varies from 1 to 3 meters.
The signal should be reliable.

Now the relay board uses 8 channels. I've bought an I2C expander (PCF8574) to minimize that to 2 wires (SDA, SCL).

I'm thinking of using the existing 485 lines to control the inverter AND the relay board. So no additional wires are required. But theoretically I can't get it to work. So before I try to invent it.

Can I do I2C communication over the RS485 as well somehow by putting another converter?
If you recommand to just go with 6 wires (power, RS485 and I2C), how reliable is my I2C line going to be on 3 meters? What pull-up values do you recommand? (24AWG wire in mind, but also using a close-by LED segment display, so 2 I2C devices on different distances). I've read posts saying:

  The rule of thumb is maximum 50 cm for a normal 100 kHz to 400 kHz I2C bus.

Or can I use some other protocol/trick? Either minimalize wires, or boost signal by a I2C buffer? (recommendations?)


texts: Can regular Arduino pins be used during SPI?

texts: I have a circuit in which I'm using an Arduino Pro Mini to interface with an RF69 radio via SPI. The SCK pin on the Pro Mini is pin 13, which also happens to be the LED pin. Is it possible to write pin 13 high and low in the same sketch that I'm interfacing with the radio? I don't need to do SPI communication simultaneously with the LED. I can put the radio to sleep then use the LED. I'm wondering if this will some how mess up the SPI communication or if everything will be OK.


texts:
On a Pi, to execute a C++ code, you'll need a Makefile.

Is there an equivalent with the Arduino? Where I have some valid C++ files to upload without the IDE's help, but instead with an executable?


texts:
On my Arduino UNO the chip part number is ATMEGA328P-U, i recently bought a ATMEGA328-PU to make a standalone Arduino. realized the part number differences after receiving the package...

I noticed that some arduino UNOs have the chip with part number of ATMEGA328P-PU! I'm totally confused!

Those chip are the same? can i use the one that i bought for an standalone Arduino?

If no what are the differences?