texts: Undefined reference in Eclipse of .h and .cpp files

texts:
I'm trying to create a linked list for use on the Arduino, in the Eclipse IDE with the Arduino/Sloeber plugin. The linked list is written in a .h and .cpp file, and included locally in the project.

However, when building, I get the error undefined reference to Structures::LinkedList<int>::LinkedList().

And despite the fact that I've added the local folder to the list of includes (and it can find the top level file containing setup() and loop()), the problem persists;

My relevant file listings are below. Any ideas of what settings I can add to Eclipse in order to solve this? Potentially, could it be something to do with the use of template<typename T> in the header file?

Thanks very much,

David

FYI: This problem does not occur with the core libraries i.e. I can run examples like Serial and Blink.

My top level .cpp is pretty simple:

#include "LinkedList.h"
#include "RAStarSearch.h"
#include "Arduino.h"

using namespace Structures;
void setup() { }

void loop() {
  LinkedList<int> list = LinkedList<int>();
  return;
}

And the referenced .h is:

#ifndef LINKEDLIST_H_
#define LINKEDLIST_H_
#include "Arduino.h"

namespace Structures {
template<typename T>
class LinkedList {
  public:
    /// Struct inside the class LinkedList
    struct Link {
      T value;
      Link *next;
    };

    LinkedList<T>(); ///< Default constructor
    void addValue(T val); ///< prepends new value at beginning of list
    T popValue(); ///< returns first element and deletes Link.
    Link* peekLink(); ///< Looks at first value
  private:
    Link *head; // this is the private member variable. It is just a pointer to the first Node
};
const int ERRNUM = 0x8000000; ///<Error number used, as exceptions not supported
}
#endif /* LINKEDLIST_H_ */

EDIT

On request I have included my code for LinkedList.cpp

#include "LinkedList.h"
#include "Arduino.h"

namespace Structures {
  template<typename T>
  LinkedList<T>::LinkedList() {
    head = NULL; // set head to NULL
  }
  template<typename T>
  void LinkedList<T>::addValue(T val) {
    Link *n = new Link();   // create new Node
    n->value = val;             // set value]

    if (head == NULL) { //i.e. if list is empty
      n->next = head;         // make the node point to the next node or NULL
      head = n;    // last but not least, make the head point at the new node.
    } else {
      Link *it = head;
      Link *oldIt = NULL;
      //TODO check edge cases i.e. insertion at beginning and end of list
      while (n->value > it->value){ //until place in list is found, needs T to have > operator
        oldIt = it;
        it = it->next;
      }
      oldIt->next = n; //Set pointer to n
      n->next = it; //Set n pointer to next
    }
  }
  template<typename T>
  T LinkedList<T>::popValue() {
    T retval = ERRNUM;
    if (head != NULL) {
      Link *n = head;
      retval = head->value;
      head = head->next;
      delete n;
    }
    return retval;
  }
  template<typename T>
  typename LinkedList<T>::Link* LinkedList<T>::peekLink() {
    return head;
  }
}


texts: Arduino menu coding problem by Keypad and 128*64 graphic LCD

texts:
I am trying to modify on the menu code to be able to use a keypad shield and arduino for scrolling between lines. after uploading and trying the code the following has happened:
1- I can not scroll more than 2 lines.
2- If I press D, I can scroll to another 2 lines.
What is the problem in this code?

include "String.h"
include"AccelStepper.h"
include "Keypad.h"
include "U8glib.h"
U8GLIB_ST7920_128X64_1X u8g(12, 11, 10, 13);

//Keypad setup

const byte ROWS = 4;

const byte COLS = 4;

char hexaKeys [ROWS][COLS] = {

{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} };

byte rowPins [ROWS] = {5, 4, 3, 2};

byte colPins [COLS] = {9, 8, 7, 6};

Keypad customKeypad = Keypad (makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

define KEY_NONE 0
define KEY_PREV 1
define KEY_NEXT 2
define KEY_SELECT 3
define KEY_BACK 4
uint8_t keycode1 = KEY_NONE;

uint8_t keycode2 = KEY_NONE;

uint8_t keycode = KEY_NONE;

void keymode(void){

keycode2 = keycode1;

char keypressed = customKeypad.getKey();

if (keypressed != NO_KEY){

switch (keypressed){

case 'A':

keycode1 = KEY_PREV;

Serial.println("A");

break;

case'B':

keycode1 = KEY_NEXT;

Serial.println("B");

break;

case 'C':

keycode1 = KEY_SELECT;

Serial.println("C");

break;

case 'D':

keycode1 = KEY_BACK;

Serial.println("D");

break;

}

if (keypressed != 'A' && keypressed != 'B' && keypressed !='C' && keypressed != 'D')

keycode1 = KEY_NONE;

}

if (keycode2 == keycode1)

keycode = keycode1;

else

keycode = KEY_NONE;

}

define MENU_ITEMS 4
const char *menu_strings[MENU_ITEMS] = {"Start", "Hello", "Let's Go", "End"};

uint8_t menu_current = 0;

uint8_t menu_redraw = 0;

uint8_t Last_key_code = KEY_NONE;

void drawmenu(void){

uint8_t i, h;

u8g_uint_t w, d;

u8g.setFont(u8g_font_6x13);

u8g.setFontRefHeightText();

u8g.setFontPosTop();

h = u8g.getFontAscent()-u8g.getFontDescent();

w = u8g.getWidth();

for( i = 0; i < MENU_ITEMS; i++ ) {

d = (w-u8g.getStrWidth(menu_strings[i]))/2;

u8g.setDefaultForegroundColor();

if ( i == menu_current ) {

u8g.drawBox(0, ih+1, w, h);

u8g.setDefaultBackgroundColor();

} u8g.drawStr(d, ih, menu_strings[i]);

} }

void updatemenu(void){

if (keycode != KEY_NONE && Last_key_code == keycode) {

return; } Last_key_code = keycode;

switch(keycode){

case KEY_NEXT:

menu_current ++;

if (menu_current >= MENU_ITEMS)

menu_current =0;

menu_redraw = 1;

break;

case KEY_PREV:

if (menu_current ==0)

menu_current = MENU_ITEMS;

menu_current --;

menu_redraw = 1;

break;

} }

void setup (){

Serial.begin(9600);

menu_redraw = 1;

}

void loop (){

keymode();

if (menu_redraw !=0) {

u8g.firstPage();

do{

drawmenu();

}while(u8g.nextPage());

menu_redraw = 0;

} updatemenu();

}


texts: How can I create analog signal which is similar to PMT(Photo Multiplier Tube) pulse using analog write?

texts: I have developed a circuit to process the PMT pulse output, For the testing, I need an artificial signal which is similar to the PMT pulse.How can i use the AnalogWrite() to create such type of signal.


texts: 434 RF Transmitter and Receiver for distance measurement problem

texts:
As a student I'm working on a project where we use 434 MHz RF Transmitter and receiver pairs for distance measurement. I know that this technology is not a good choice for this, but we have to deal with this problem due to external constraints.

Here is the receiver: RF Link Receiver - 4800bps (434MHz).

I did a little bit of research how these receivers works, but I found it a bit overwhelming to understand them bit by bit.

We want to use the signal strength for distance measurement. So we tried sending pulses of signals from one transmitter to a receiver. If the amplitude of the signal received is higher than a certain value (let's say 3V), it sends back a signal (let's call it trigger signal) in the gap between the two pulses.

The problem is that that these signals seems to affect each other even though they are not in the same time (so it's not superposition that we are talking about). When there is a signal sent back, the next pulse will be lower, which results in false distance measurement.

The whole difficulty is (to me it seems) that we are not using these signals to send data, we are using it for distance measurement. My idea is that we are using too long pulses and the AC coupling in the receiver doesn't tolerate it, but again, I don't have enough electrical knowledge to safely say that.

I know this is not descriptive, but I don't know how to make it more descriptive, so I'm happy to answer more questions on demand.


texts: No power from Breadboard Power Supply Module

texts:
Components

Breadboard Power Supply Module IM120525004
1 kOhm resistor
Green LED
Arduino Nano
LiPo 7.4V battery

LED Lights Up Fine with USB power from the Arduino

LED Does Not Light Up with power from the Supply Module

What am I doing wrong?

The Lipo battery is brand new and is charged as the terminals showed about 7.6V on my multimeter. This is confirmed by the LED on the supply module itself lighting up fine.
I think I can smell just a little bit of burn whenever the supply module is connected and there is power in the circuit.
The positive jumper wire is connected to the 5V VCC pin on the Arduino, not the VIN pin on the Arduino, not that it matters, because if I remove the Arduino from the breadboard the LED still does not light up


texts: Why does this button have a connection to ground?

texts:
I am testing this basic button example  from the Arduino tutorial page.

This circuit lets power flow to pin 2 when the button is pressed. When the button is not pressed, the power goes through the resistor to ground, but my question is: why would you even need the connection to ground?

Can't you have power flow from 5V to pin2 or just have NO connection at all when the button is not pressed?


texts: How can one use the SPI hardware on the Arduino Nano?

texts:
I recently prototyped and programmed a system that used some SPI sensors on an Arduino Uno. I wanted to get the size down a bit, so I was thinking I might buy an Arduino Nano and re-wire my system around that. The problem is that I have seen mention of SPI not working on the Nano. From the Nano product page:

  These pins support SPI communication, which, although provided by the underlying hardware, is not currently included in the Arduino language.

Yet I have also seen mention of SPI working on this board, or at least people saying that it should. Someone asked a similar question on Stack Overflow and was told that it should work with the same level of support as I2C, even if it isn't built in to the core framework. But that answer does not definitively answer the question of whether SPI does work, and it doesn't explain any caveats that one may come across. In this question, the OP's premise is that their SPI device works on the Nano but not on other boards; this seems to be a strong indication that SPI does work.

I figured it would be worth it to buy a Nano 3 and see if it worked. SPI devices did not work on that board, including the same radio module mentioned in the question linked to above. So, I am inclined to believe the Arduino product page when they say it isn't supported. But that still isn't satisfactory, and it is the opposite conclusion from that of the other questions: The hardware is all there and the software framework is in place, so what does one need to do to make SPI work on the Arduino Nano? Why is it that some sources say it works while others say it doesn't?


texts: Why is my Analog Input channel adding voltage to my signal?

texts:
EDIT: Here are the links to the sensor spec sheet (http://www.omega.com/temperature/pdf/HX71.pdf) and manual (http://www.omega.com/Manuals/manualpdf/M4543.pdf) for your reference.

I'm using a relative humidity (RH) sensor with an Arduino Mega. The RH sensor runs off of +/- 24V  (which is being sourced by a power supply), and outputs a signal from 0-5VDC. Naturally, I am plugging this output signal into my A0 channel. There is a bare Earth Ground wire that is wired to the power supply's earth ground (possible error?) Arduino's GND is connected to the power supply's EARTH GND, fyi.

I compared the voltage reading in my Arduino Serial Monitor to a reliable Fluke multimeter, and the analog input channel is adding ~.2 Volts!

From some research, I have read about "high impedance" "source impedance" "internal wiring of Arduino" etc, but unfortunately I am failing to grasp the reason why this is happening. I'd like to know so then I could figure out a solution on my own.

Below is a schematic of what I'm dealing with so that it may better illustrate my issue (also my code). Thank you for your time, and I appreciate your help!

)

void setup()
{

Serial.begin(9600);

}

void loop()
 {

  float hs1 = ((( analogRead(A0) * ( 5.0 / 1024.0) ) )* 20.0 );

  Serial.print("RH%");
  Serial.print(":");
  Serial.print(hs1);
  Serial.print(";");
  Serial.println();
  delay(1000);

}


texts: Which platform is better to debug Arduino memory problems? Linux or Windows?

texts:
I am developing a product. I developed every module in the firmware individually. Now I am integrating them but getting memory issues. I am not able to see how the memory is allocated inside the MCU during the runtime.

Can Linux help me debug issues better, using its command than Windows platform?

Thanks in advance.


texts:
How do you specify a custom location for your sketch?

I want my code to be located in a src folder, but when I try to compile my main.ino, arduino complains "The file main.ino needs to be inside a sketch folder named "main". How do I disable this arbitrary restriction?


texts: Write to file in SD card in wave shield V3

texts:
I just started tinkering with Arduino. I'm curious to know though, is it possible to read and write to a file stored in the SD card in the Wave shield v3 by Elechouse? I'm able to play files stored in said SD card, but I don't know how I'd go about writing some logs. I'm using an Arduino Mega.

Thanks in advance.


texts:
After programming Arduino Nano with the DIY Headtracker code, after trying to plug the Arduino to the receiver and some time, the LED stops flashing and now it's not recognized by the computer anymore.

When I plug it, it only lights the power LED.

The worst thing is that I've already tried with another Nano and it bricked also, can't use them any more. Anyone know any fix to this?

This is the error given when trying to upload the blink sketch to the board...

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


texts: How do I control the buttons on an Arduino LCD keypad shield?

texts:
I have just bought a 16x2 LCD display with buttons. I can get the display to work and do various basic sketches included in the Arduino IDE. However, I cannot figure out how to control the buttons.

The buttons work using analog pin 0 and from what I was able to understand from what I have read online, it is something to do with the values you receive when the buttons are pressed. I can't seem to find out what values mine gives, I have found a sketch that is supposed to map the buttons, but I cannot get it to work, as I don't really understand what it is doing, I am very new to this.

The code I am using is as follows:

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons() {
  adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 250)  return btnUP;
  if (adc_key_in < 450)  return btnDOWN;
  if (adc_key_in < 600)  return btnLEFT;
  if (adc_key_in < 920)  return btnSELECT;
  return btnNONE;
}

void setup() {
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Push the buttons");
}

void loop() {
  lcd.setCursor(9, 1);
  lcd.print(millis()/1000);
  lcd.setCursor(0, 1);
  lcd_key = read_LCD_buttons();
  switch (lcd_key) {
    case btnRIGHT: {
      lcd.print("RIGHT ");
      break;
    }
    case btnLEFT: {
      lcd.print("LEFT   ");
      break;
    }
    case btnUP: {
      lcd.print("UP    ");
      break;
    }
    case btnDOWN: {
      lcd.print("DOWN  ");
      break;
    }
    case btnSELECT: {
      lcd.print("SELECT");
      break;
    }
    case btnNONE: {
      lcd.print("NONE  ");
      break;
    }
  }
}

If anyone can give me any pointers it would be greatly appreciated.

Liam


texts: Running Arduino code for Bluefruit LE on bare ATMega328

texts:
I need to hook up Bluefruit LE Breakout (nRF8001-based) to ATMega328 chip (to use it as wireless UART), and it seems like the library provided is for Arduino.

What I have is just bare ATMega328 (note the lack of "p"), which I am going to program (using avrispmkii directly). As I already have the MCU assembled, I do not want to change to, say, Arduino Uno to be able to use the library. Most likely, I will "play" with the Bluefruit on Arduino first to get the feel of it, but the code needs to be run on the "bare" ATMega328. The other part of the program (which prepare data to be sent from atmega) is trivial, so I will have no problem to rewrite it from C to Arduino. Porting Adafruit library from C++ to C is probably much more difficult.

Thus, one of the possible approaches is to compile the my code + Bluefruit LE code for Arduino, but upload to the ATMega328.

And this is where I need help:

How to make Arduino (command line tool is ok) to compile to the MCU I have? I guess, the result should be some kind of hex-file for flash (and eeprom?).

And, may be useful, which flags to use with avrdude, if there is anything specific for the Arduino-generated code. (I do not need any bootloaders on the chip, just the program, and I do not have UART-USB connected to atmega).

Of course, please, mention if there are better ways I overlooked, like some Arduino-compatible gcc toolchain to compile C++/C mix into avr code (avr-g++?). Or maybe there is some C-library for the component atmega needs to talk to.

UPDATE: Similar question: http://www.avrfreaks.net/forum/using-arduino-ide-general-atmel-microcontroller-no-bootloader-no-cristal


texts:
I'm trying to find a way to set a -D compiler option from within the boards.txt file. Basically set a #define for use in code. There are already some special ones like board.vid but is there a generic way to do it?

Somehow the Teensy add-on adds a little magic that allows the IDE to recognize options like:
.board.define0=-DHELLOWORLD
.board.option0=-DHELLOWORLD

In other words, add the -DHELLOWORD (#define HELLOWORLD) to the command line for GCC.

BUT, I can't get this to work without the Teensy add-on installed.

Is there a way to do this with the stock IDE?


texts: How do I use an Arduino as a USB output device for a 2x16 display?

texts:
Can I make a USB 2x16 display using an Arduino?
I want to control a 2x16 character lcd display using USB, not com port/serial.

I need it to appear as a HID device when connected to the computer.

Please advise me.

Thanks


texts: What is wrong with my code? Did you forget '()'?

texts:
#include <SimbleeBLE.h>

// constants won't change. They're used here to set pin numbers:

const int ButtonPlayPause = 15;
const int ButtonNext = 12;
const int ButtonPrevious = 11;
const int OBled = 29;
       int Playp = 1;

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup()
{

  pinMode(ButtonPlayPause, INPUT);
  pinMode(ButtonNext, INPUT);
  pinMode(ButtonPrevious, INPUT);

  pinMode(OBled, INPUT);

  SimbleeBLE.deviceName = "GBAND";

  Serial.begin(115200);

  SimbleeBLE.begin();

  SimbleeBLE.txPowerLevel = +4;
}

void loop()
{
  buttonState = digitalRead(ButtonPlayPause);
  if (buttonState == HIGH)
  {
    SimbleeBLE.begin();
    SimbleeBLE.deviceName = "GBAND";
    //More code here to establish connection with android
     SimbleeBLE.sendInt = (Playp);
    digitalWrite(OBled, HIGH);
    SimbleeBLE.end();
    digitalWrite(OBled, LOW);
  } else  {
            buttonState = digitalRead(ButtonNext);
            if (buttonState == HIGH)
            {
              SimbleeBLE.begin();

              //More code here to establish connection with android

              digitalWrite(OBled, HIGH);
              SimbleeBLE.end();
              digitalWrite(OBled, LOW);
            } else  {
                      buttonState = digitalRead(ButtonPrevious);
                      if (buttonState == HIGH)
                      {
                        SimbleeBLE.begin();
                        //More code here to establish connection with android

                        digitalWrite(OBled, HIGH);
                        SimbleeBLE.end();
                        digitalWrite(OBled, LOW);
                      }
                    }
          }
    }

This is the error I keep getting:

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Simblee"

C:\Users\Lestat\Desktop\SD PROJECR PAPERWORK\Sketch programs\sketch_mar20a\sketch_mar20a.ino: In function 'void loop()':

sketch_mar20a:42: error: invalid use of member function (did you forget the '()' ?)

     SimbleeBLE.sendInt = (Playp);
                        ^
exit status 1
invalid use of member function (did you forget the '()' ?)

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


texts: Can I connect a NEO-6M GPS Module and ESP8266 to the same Arduino? I think both modules require the use of the RX and TX pins.


texts: How to improve incoming serial communication time?

texts:
I have a webpage on Flask that sends a serial message to Arduino whenever a user presses the button to turn on an LED. The thing is, average time between pressing the button and turning on the LED is 15-30 seconds which is eons.
How can I decrease the time for Arduino to receive incoming bytes?  It cannot be the webpage, since when I use it with Rapsberry Pi, it is almost instantaneous.
int fromPi = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(10, OUTPUT);
}

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

  if(Serial.available() > 0) {
    fromPi = Serial.read();

  Serial.print("I received: \n");
  Serial.print(fromPi, DEC);

      if(fromPi == 'H') {
        digitalWrite(10, HIGH);
      } else if (fromPi == 'C') {
        digitalWrite(10, LOW);
      }
  }
}

Python/Flask code
from flask import Flask, request, jsonify
import serial
import time

app = Flask(__name__)

ser = serial.Serial('/dev/ttyACM0', 9600)

# {{url}}/led?status=on
@app.route('/', methods=['GET'])
def led():
    status = request.args.get('status')
    if status == "on":
        exteriorOn = 'H'
        exteriorOnEncode = exteriorOn.encode()
        ser.write(exteriorOnEncode)
        return jsonify({"message": "Led successfully turned on"})
    elif status == "off":
        exteriorOff = 'C'
        exteriorOffEncode = exteriorOff.encode()
        ser.write(exteriorOffEncode)
        return jsonify({"message": "Led successfully turned off"})
    else:
        return jsonify({"message": "Not a valid status"})


texts: Sensor to measure distance on inverted pyramid filled with maize

texts:
I'm struggling with the following problem:

I have an inverted pyramid, supported in four points, filled with maize up to 600KG.

I want to keep track of the level of maize inside the inverted pyramid.

I've thought about using a load cell but this can be expensive and I need a cheap solution to implement. I also thought about using a sensor centred on top of the inverted pyramid.

The problem here is that I really dont't know what kind of sensor can be used to get correct values.
Can ultrasonic sensors give me bad values? The pyramid form is tricky...

PS: Theoricly can mill be too reflective and influence the result of measures?

I'm sorry for the English :P. I'm still learning.

If anyone can help I really appreciate.

Best Regards


texts: Accelstepper.runToPosition() is working fine. Accelstepper.run() does nothing

texts:
I have a complex sketch with Arduino Uno, Bluetooth Serial Com using altSoftSerial, serial com using SoftwareSerial and Serial communication with PC.

I want to move one stepper motor and stop it when a signal is received.
I use A4988 Pololu driver and NEMA 17 bipolar stepper motor.

This code is working fine.
      MyStepper.moveTo(position);
      MyStepper.runToPosition();

If I change the code to
      MyStepper.moveTo(position);
      MyStepper.run();
so that the running does not block my code the motor does nothing
Absolutely no movement.

The ground of the motor power supply is connected with the ground of Arduino. The motor is working fine with blocking movements.


texts: Why serial communication does not work on atmega168/328p?

texts:
I expect from the following program serial.c to light the led on if I send key 1 from terminal, and light the led off when I send key 0 from terminal:

#define F_CPU 16000000UL
#define BAUD 9600
#include <avr/io.h>
char data;
void main(void) {
  #include <util/setbaud.h>
  UBRR0H = UBRRH_VALUE;
  UBRR0L = UBRRL_VALUE;
  UCSR0B |= (1<<RXEN0);
  UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
  DDRB |= (1<<PB1);
  while(1) {
    while(!(UCSR0A&(1<<RXC0)));
    data = UDR0;
    if (data=='0') PORTB &= ~(1<<PB1);
    if (data=='1') PORTB |= (1<<PB1);
  }
}

I 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

The output of avrdude is the following:

$ avrdude -c usbasp -p atmega328p -U flash:w:serial.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "serial.hex"
avrdude: input file serial.hex auto detected as Intel Hex
avrdude: writing flash (12 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 12 bytes of flash written
avrdude: verifying flash memory against serial.hex:
avrdude: load data flash data from input file serial.hex:
avrdude: input file serial.hex auto detected as Intel Hex
avrdude: input file serial.hex contains 12 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 12 bytes of flash verified

avrdude: safemode: Fuses OK (E:07, H:DE, L:FF)

avrdude done.  Thank you.

For serial connection I tried PL2302 and FT232RL usb-com adapters - the effect is always the same.

Terminal settings on the computer are correct (9600,8N1).

avr-gcc version 4.8.1
avrdude version 6.1

Why the very first program in this question does not work as needed and what should be changed in it to achieve the desired behavior?


texts: Assigning an empty array row to reference

texts:
int colors[][3] = {
  { 255, 0, 0 },
  { 0, 255, 0 },
  { 0, 0, 255 },
  { 253, 7, 210 }
};
int (*EXCLUSIVE_COLOR)[3];

I have a two-dimensional array to store some color values.
I have a 2nd array, which I am using to assign an "EXCLUSIVE_COLOR" from the first colors array.

What is the best method to assign a null or empty value to the "EXCLUSIVE_COLOR" array to be used upon initialization and when the "EXCLUSIVE_COLOR" is unset?

Initially I tried just assigning a default value to the array upon initialization:

int (*EXCLUSIVE_COLOR)[3] = {0,0,0};
//Produces an error: scalar object ‘EXCLUSIVE_COLOR’ requires one element in initializer

int (*EXCLUSIVE_COLOR)[3] = {0};
//assigns non-zero values to all three elements

I know that I can add a "dummy" record to the colors array to reference, when there isn't an "EXCLUSIVE_COLOR" set.

int colors[][3] = {
  { 255, 0, 0 },
  { 0, 255, 0 },
  { 0, 0, 255 },
  { 253, 7, 210 },

  { 0, 0, 0, }   //dummy record
};
int (*EXCLUSIVE_COLOR)[3] = &colors[4];

However I wanted to know if there was a cleaner way to be able to assign an empty value to reference when a color is not set, and when the array is initialized.


texts: Understanding datasheet of a HCHO gas sensor

texts:
I have a gas sensor whose datasheet is attached:
DS-HCHO

Now it says that UART communication is needed (P2P) where it (module) waits for Data Frame before tx the data frame to host which I need.

All i know is that I can send start bit in I2C but how shall I proceed.
Also if I have multiple sensors how shall I connect them to ESP-32?


texts: where to syphon off voltage from a 25 pin serial?

texts:
I have a mircocontroller that's looking to be powered by a 5v source.

I am trying to 'cypher off' some of this power from a 25 pin serial port, which is being powered by a constant power source.

Are there any pins that could give me that sort of voltage, or enough to power the board?

Please note, I'm not an electrical person at all, and so hope this is actually possible (otherwise my 3 months + program's work doesn't really add to anything).

I've tried a 9v battery, but it didn't seem to hold its charge?

I'm reading these labels going "what the ..." so you can probably tell coding the board wasn't the easiest, either.

Edit History

I would like to clarify this is an existing serial lead
I understand this may be deemed verging off topic, but due to the need to 'power' a microcontroller, I thought this could be answered here
If this isn't possible, (as an alternative, possibly) would a 9V/battery be able to power this board reliably for around 2-3 weeks?


texts: Software serial conflict with WiFi on ESP8266

texts:
I'm trying to use an ESP8266 (Wemos D1 mini) to read from a 19.2K serial port and report the results over WiFi. Programming is via Arduino IDE. The code to read the port works just fine if WiFi is not enabled. Once WiFi is enabled I lose chars from the input stream. I've seen several posts in various places that point to problems with using SoftwareSerial and WiFi at the same time, apparently having to do with timing conflicts. My latest attempt calls

WiFi.disconnect();

before the code that reads the chars from the serial stream, then calls

WiFi.reconnect();

after reading the serial stream but before making the calls to send data over the web. This did not work.

My code is reading from the serial port in a (blocking) loop, which other posts suggest is the problem. This is not a problem when there is no WiFi object connection. I could restructure the code to create a non-blocking read, but that would be a significant effort (and make the code much harder to understand), so before I go that route I'm wondering if there is a different solution.


texts:
I am new to programming. kindly bear with me. I am trying to use ESP8266-01 device for serial read and write application. Before writing the full program for my application, i wanted to test how it functions. I programmed the ESP8266-01 device to read the data from its Rx pin and write it to Tx pin. I used a standard USB-TTL cable to send and receive data from PC using Hterm. The ESP device does not read the data available at the Rx pin. what am i missing ?. Also kindly help me in understanding the difference between serial.println and serial.write with respect to ESP8266-01 device. As per the program if i check the data from the Tx pin of the ESP8266 device, i get only "No data received". I am using arduino IDE 1.6.11. Kindly provide some guidance

regards

Sriniketh

#include <ESP8266WiFi.h>

void setup() {

Serial.begin(9600);
}

void loop()
{
  byte serin=0;
  if (Serial.available()>0)
  {
    serin=Serial.read();
    delay(100);
    Serial.println(serin);
    delay(100);
    Serial.write(serin);
  }
  else
  {
    Serial.println("No data received");
    delay(5000);
  }

}


texts: Measure LiPo / Li-Ion SOC or the ever standing question of how much juice is remaining in my battery?

texts:
So I have a project in which an arduino runs on a two cell LiPo battery and I need a fast, straight forward way to determine remaining battery charge (with an accuracy of 10% so I only have a readout with 10 LEDs on it) without using any major extra components (so using an external battery charge meter IC is cheating :P). How should I go about this?

(using arduino mini, LiPo is two cells: 7,4V 150mAh)


texts:
I have read several articles an datasheets, but I couldn't find an affordable answer...

This is my problem: I need to power a NodeMCU (on Vin pin) with 3xAA batteries. Which is the minimum operating voltage at Vin accepted by NodeMCU? In other words, which voltage drop from 4.5 will let NodeMCU still working?
thanks.


texts: Setting the sampling rate for timer interrupt

texts:
I had performance problems with the data acquisition and after some reading on the web, someone told to define a timer with the frequency I need (50hz):

// TIMER 1 for interrupt frequency 50 Hz:
cli(); // Stop interrupts.

TCCR1A = 0; // Set entire TCCR1A register to 0.
TCCR1B = 0; // Same for TCCR1B.
TCNT1  = 0; // Initialize counter value to 0.

// Set compare match register for 50 Hz increments.
OCR1A = 39999; // = 16000000 / (8 * 50) - 1 (must be <65536)
// Turn on CTC mode.
TCCR1B |= (1 << WGM12);
// Set CS12, CS11 and CS10 bits for 64 prescaler.
TCCR1B |= (0 << CS12) | (1 << CS11) | (1 << CS10);
// Enable timer compare interrupt.
TIMSK1 |= (1 << OCIE1A);

sei(); // Allow interrupts.

But with that, I was unable to achieve good performance; I was expecting 50 reading / seconds. Luckily, I've changed for 8 bits prescaler instead of 64 and I've start to get better performance:

// Set CS12, CS11 and CS10 bits for 8 prescaler.
TCCR1B |= (0 << CS12) | (1 << CS11) | (0 << CS10);

But, honestly, I'm a newbie and I don't understand why!


texts:
I would like to proto thread two functions to run pseudo-simultaneously. One function takes the input of a force sensor and moves a servo accordingly, and the other takes the input of a gyroscope (MPU650) and moves a different sensor accordingly. Below is my code where I attempt to use timers to handle this.

#include <Wire.h>
#include <Servo.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Servo.h"

int FSR_Pin = A0;
bool isClosed = false;
unsigned long lastMillis = 0;
unsigned long lastMillis2 = 0;

MPU6050 mpu;

int16_t ax, ay, az;
int16_t gx, gy, gz;

Servo handServo;

Servo wristServo;

int pos = 0;
int val;
int prevVal;

void setup(){
  Serial.begin(9600);
  handServo.attach(9);

  Wire.begin();
  Serial.begin(38400);

  Serial.println("Initialize MPU");
  mpu.initialize();
  Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");
  wristServo.attach(8);
}

void handleFingers () {
  int FSRReading = analogRead(FSR_Pin);
  Serial.println(FSRReading);

if (FSRReading > 9) {
 if (pos < 90) {
     handServo.write(pos);
      pos ++;
 }
  isClosed = true;

} else if (isClosed == true && FSRReading < 10) {
  pos = 0;
  handServo.write(pos);
  isClosed = false;
}
}

void handleWrist() {
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

    val = map(ay, -17000, 17000, 0, 179);
    if (val != prevVal)
    {
        wristServo.write(val);
        prevVal = val;
    }

}

void loop(){
  if (millis() - lastMillis > 1000) {
    handleFingers ();
  }
   lastMillis = millis();

 if (millis() - lastMillis2 > 1000) {
    handleWrist();
  }
   lastMillis2 = millis();

}

When I run the code above, the servos move a few degrees each and then do nothing at all. It appears that none of the servos are responsive to the sensor feedback. Something is wrong with my timing or my method of proto threading. I would really appreciate your help, thanks.


texts:
I want to create a device that interfaces with the Light Strike Lasertag system using an Arduino Leonardo.

The Light Strike system uses not laser but regular infrared signals. According to a site that I found (http://www.meatandnetworking.com/projects/hacking-at-the-light-strike-laser-tag-game/) it uses 37.8 khz signals. I only found IR-receivers using 37.9 or 38 khz. Can I use them? How far can the modulation frequency differ?

Is there anything else I need to watch out for when creating an IR-interface?


texts: Did I fry my DUE by powering it from a external source and USB at the same time? If so, why?

texts:
I guess I just fried my second DUE in a week. The first I didn't really see what happened, but I couldn't upload any sketches, even if the computer could recognize it, and the SAM would get really hot.

Now, I had it powered by a 12V External supply, through a regulator bringing it down to 9V, and in the exact moment I plugged the USB, with power still on, I got a lot of smoke, smelling of fried electronics :p. Afterwards, I have the same symptoms as I had in the other boards: Green and orange LEDs on, chip very hot, computer recognizing it as a Arduino DUE but not being able to upload any sketches.

What just happened?


texts: Receive SMS using Arduino Nano and Quectel EC25

texts:
I'm trying to use an Arduino Nano to communicate with a Quectel EC25 module from this Raspberry Pi 4G HAT. I'm using Arduino's pins 8 and 7 to communicate with RX and TX from the Quectel module. I'm able to establish communication and send AT commands.

The problem is that when I start to listen for incoming SMS, the available method does not change status, even if an SMS is received. There is the code I using:

#include <SoftwareSerial.h>

#define DEBUG Serial
SoftwareSerial EC25(8,7); // RX, TX - 9600 baud rate

#define AT_RESPONSE_LEN 100
#define TIMEOUT 1000

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

  sendATComm("ATE1","OK\r\n");
  sendATComm("AT","OK\r\n");
  sendATComm("AT+IPR?","OK\r\n");
  sendATComm("AT+CGSN","OK\r\n");

  sendATComm("AT+CNMI=2,1","OK\r\n");
  DEBUG.println("listennig");

}

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

  if (EC25.available()){
    DEBUG.println("Available");
  }

}

// function for sending at command.
const char* sendATComm(const char *command, const char *desired_reponse)
{
  uint32_t timer;
  char response[AT_RESPONSE_LEN]; // module response for AT commands.

  memset(response, 0 , AT_RESPONSE_LEN);
  EC25.flush();

  sendATCommOnce(command);

  timer = millis();
   while(true){
    if(millis()-timer > TIMEOUT){
      sendATCommOnce(command);
      timer = millis();
    }
    char c;
    int i = 0;

    while(EC25.available()){
      c = EC25.read();
      DEBUG.write(c);
      response[i++]=c;
      delay(2);
      }
      if(strstr(response, desired_reponse)){
        return response;
        memset(response, 0 , strlen(response));
        break;
      }
  }
}

// send at comamand to module
void sendATCommOnce(const char *comm)
{
  EC25.print(comm);
  EC25.print("\r");
}

That gives the following output:

ATE1

OK
AT

OK
AT+IPR?

+IPR: 9600

OK
AT+CGSN

860548040717545

OK
AT+CNMI=2,1

OK
listennig

I also tried this example by changing the default RX and TX pins but does not work at all.


texts:
This is a somewhat theoretical question:
Let's say I have some sensor that sends digital signals to one of Arduino's digital ports.
Now, I don't know the frequency it sends those signals in.
For example, the frequency of the sensor output could be 100Hz, so every 1/100 of a second it varies the voltage (or keeps the old voltage if the next signal is the same as the previous one), but it could just as well be 200Hz.
Would Arduino be able to faithfully read the digital signal regardless of its frequency? Or is there a conventional frequency that digital devices usually use for output?
Wouldn't it be the case that if Arduino expects 100Hz signal, but the signal is 200Hz it would miss half the inputs?
For: (1 0 1 0 0 1...) wouldn't it see: (1 1 0) - that is skip every other input because it's sampling rate would be too slow by half?
Thanks kindly for your help..


texts:
I am working on a project in which I have to connect my Arduino with a GPS module. In this project I need to get longitude, latitude, time and date from the GPS module and need to send these values via USB to a computer.

On this computer, I am going to design software in Microsoft Visual Studio 2010, which will receive this data and display it on a map.

Now, before designing it in hardware, I want to simulate it on Proteus. I have searched in Proteus but there's no GPS module in it, so does anyone know any GPS module library for Proteus?


texts: Suggest me a power source for my Arduino UNO project

texts:
I am working on a Project with:

1 Arduino UNO
5 micro 9g servos (Only one Working at a time)
2 small LED bulbs
1 MicroSD reader module
1 Speaker

Can I power my Arduino UNO with a common 9v Battery?

I also have in mind to use an external power supply for servos... but what to use?

Please suggest me a perfect power supply system


texts:
I have received an ESP8266 (ESP-07) Wi-Fi module from DealExtreme (Link: http://bit.ly/2dFJdxE).
It is a 4-pin module with the following pins: RX, TX, VCC and GND.
The module has a switch so you can switch between the following modes: Program & UART. The module also has a RESET-button.
Here's a picture of my module:

I've connected the module to my Arduino Uno like this:
RX > RX,
TX > TX(TX>RX & RX > TX, like mentioned in manuals, results in no connection),
VCC > 3.3v (not using any level shifters because the module has on board level shifters),
GND > GND.

I found a lot of manuals to test the module, but apparantly I can't get my module working. I am using Windows with the Arduino IDE.
The boards mentioned on the manuals/tutorials also seem to differ from my module because most of the manuals are talking about a board that has 8-pins (with an extra GPO0, GPO2 CH_PD and RST pin).
I've tried to upload the BareMinimum sketch to the module, which only finishes uploading if I disconnect and reconnect the 3.3v input that's feeded to the ESP-board when the Arduino IDE says "Uploading...... " while the ESP-board is in Program-mode.
I have installed the ESP8266 library within the Arduino IDE and the Generic ESP8266 Module is selected.
Then when I open the serial monitor in the Arduino IDE, to test the AT commands (on different BAUD values), it does not respond (neither in Program-, nor in UART-mode).
Strange thing is when I keep the serial monitor on at 74880 BAUD (and UART-mode on the module) and I push the RESET button on the module, it gives the following message:

ets Jan  8 2013,rst cause:2, boot mode:(3,7)
ets_main.c

I've tried several things.  But none of them seem to work; like trying to flash new firmware (for example 'v0.9.5.2 AT Firmware.bin' and 'esp8266-2016-05-03-v1.8.bin') with esptool.py with the following command:

esptool.py -b 115200 -p COM3 write_flash 0 FIRMWARE.bin

It says that the writing is finished and no errors appear after running the esptool. This is what is printed + command that is used:

esptool.py -p com3 -b 115200 write_flash 0 firmware.bin
esptool.py v1.2-dev
Connecting...
Running Cesanta flasher stub...
Flash params set to 0x0000
Writing 520192 @ 0x0... 520192 (100 %)
Wrote 520192 bytes at 0x0 in 44.2 seconds (94.1 kbit/s)...
Leaving...

A strange thing is when I open the serial monitor in the Arduino IDE after that moment (without resetting the module/unplug from 3.3v or change to UART mode), it keeps printing the following at 115200 BAUD:

Fatal exception (28):
epc1=0x4000228b, epc2=0x00000000, epc3=0x00000000, excvaddr=0x000000b5, depc=0x00000000

I even tried it with the erase_flash before and 0x00000 instead of 0. Also tried to run the command with a variety of flash_sizes (with the command --flash_size=Xm).
Esptool looks like the only tool where I can flash new binaries successfully, tried some others that where on some manuals but without success.
When I run esptool.py -p flash_id

I get the following response:

Connecting...
Manufacturer: e0
Device: 4014

Who knows how to fix this problem so I can send AT commands to the module through the serial monitor in the Arduino IDE.
Thanks in regards (this is my first post so if some things are unclear, please let me know)
Edit: Note that I have to disconnect and reconnect the 3.3v to the module EVERY time to successfully run a command (like write_flash, flash_id et cetera). Also tried connecting it to 5v and using an external power supply next to the USB.


texts: How to detect lipo battery % charge left?

texts:
I am currently working with a few robotic projects where i use lipo batteries. Currently I am working with a 1500 mah 3s lipo.

With my current setup I am using a arduino uno and a power distribution board. I put my lipo charger in my power distribution board which has two connections where I put two cables that goes to the VLN and GND.

(If needed I can make a quick schematic to explain it better!)

How can I now see the current battery percentage of the lipo?

I came across a project that uses this codesnippet:

long previousMillis = 0;

long interval = 1000;

int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);

unsigned long currentMillis = millis();

if (currentMillis - previousMillis > interval) {
  previousMillis = currentMillis;
 if (voltage <= 3.5)
      Serial.println("Low Battery");
     else
      Serial.println(voltage, DEC);
}

This snippet works with the A0 and I do not have anything connected there so I assume not.

Appreciate every help! :)


texts: Library to send large amount of data over 433 MHz

texts: I am trying to communicate between two Arduinos using two RF 433 MHz modules (transmitter receiver). I found that the library Wildewire.h allows a maximum of 77 bytes so is there any another library that allows to send a more than that?


texts: Accelerometer sensor gy-61 convert to m/s2

texts:
I have a problem calibrating my GY-61 accelerometer on an Arduino Uno to get values in m/s2.

Analog-reading code:

const int xPin = A5;
const int yPin = A4;
const int zPin = A3;
// ...
void loop() {
   int xRead = analogRead(xPin);
   int yRead = analogRead(yPin);
   int zRead = analogRead(zPin);

   float xData = (((float)xRead - 337.92) / 61.44 * 9.81);

   accData= sqrt((xData*xData)+(yData*yData)+(zData*zData));

xData should show values in m/s2.
What do those values  337.92  and  61.44 mean and how can I calibrate them to get right values?

Values I get (in one position without moving):

xData   yData   zData    accData
-11.16   1.61   -0.79    11.31
-0.79  -11.48    0.01    11.51
-0.47   -0.63  -10.68    10.71

accData should be near 9.81 m/s2, also x or y or z, depending on rotation.


texts:
I am using a SIM800L Module with esp32. I am using a 3.7V 2800mAh lipo battery to power the sim800L but the LED is not blinking. I am lookng for answers in web but evryone seems to have a different problem than mine. In other case the sim800l is at least blinkng or blinked once.
I have tested the led with multimeter and it glows so hopefully the board is okay.
Is the power supplied by the battery is not sufficient? I followed this tutorial

I am sure about the sim card as it is a working sim card in INDIA (of IDEA) and works fine in my smart phone.


texts: Can i use PL2303 USB to TTL Serial Converter Module send keystrokes using Arduino nano?

texts:
If I can, which library to use (an example code will be great).
Here is the module:


texts: Can I solder wall cord directly to servo?

texts: I have a servo which requires 7.4v and a wall power cord which says the output is 7.4v but the connector does not fit that of the servo. Is it safe to snip off the end of the wall cord and solder the internal wires directly to the servo?


texts: Arduino Nano /Uno USB is not getting recognized

texts:
I have multiple Unos and Nano and recently due to some bad configuration the USBs are not getting recognised on my Mac Air Laptop. These were working models for almost 1-2 years. I used it to control motors and something must have happened and it stopped.

But strangely the small boot up LEDs on the Nano/Uno light up when connected so it seems that the connection from the laptop USB to the device is good - but the driver ports are not showing up on the Arduino IDE.
How do I go about resolving that it is not just a software issue and is a hardware issue ?

I reinstalled the CH340G driver.img and yet the device when plugged in - does not show the USB port on the IDE ?
Any thoughts or ideas on how to resolve this.

The Uno/Nano are Chinese Clones and have CH340 chipset on them.
Is there some firmware that may have gone wrong and can be reset ? or new boot loader that can be burnt to bring them back to life.

I want to be able to see the Tools-> Port -> /dev/cu.usbserial1410
and also be able to see /dev/cu.usbserial on the command xterm prompt .


texts: Need a sensor to make ball roll away from pet but which sensor?

texts:
Having recently entered the world of Arduino I am seeking to make, as my first project, a ball that will sense my dogs approach and roll away.

I can handle the rolling part but I have been unable to find a sensor that will work when fully embedded in the ball (so the dog cannot bite or swallow it). This means no ultrasound or infra red or normal proximity sensor will do.

My best bet - an inductive proximity sensor (with a metal object attached to dog's collar) is only effective at a maximum distance of 8 cm and that is far too little. I need something that activates at say 1 foot.

Any ideas anyone?


texts: Cannot program Arduino Micro in OSX without hard resetting the board every time

texts:
I am experiencing a problem when programming Arduino Micro in OSX Mavericks. I have tried to reproduce this problem in XCode and Arduino IDE and it is persistent. I need to make a hard-reset at the same time as a click the "program" button.

I have tried to use the new Leonardo bootloader to see if it solves my issue, but its still persistent.

I am running avrdude 6.1, what is the problem?

Stacktrace:

---- Size ----

Binary sketch size:   24162 bytes (of a 28672 byte maximum)
Estimated SRAM used:  733 bytes (of a 2560 byte maximum)
Elapsed time: 5.2 s

---- Reset ----

screen -X kill

No screen session found.

make: [reset] Error 1 (ignored)

sleep 1

9.2-RESET:  <   micro   ./ ./

stty -f /dev/tty.usbmodem1411 1200

---- Upload ----

10.6-UPLOAD:  <     micro   ./

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -patmega32u4 -C/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -D -cavr109 -b57600 -P/dev/tty.usbmodem1411 -Uflash:w:Builds/embeddedcomputing.hex:i

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding


texts: Using MQTT to send time stamp - to Arduino

texts:
In previous question in this forum - I asked about updating clock on an ESP8266, using MQTT broker to send a time stamp on demand, in following manner:

1) ESP8266 sends a publish containing the payload :"sync",

2) broker answers in string format ( this part is python )

def on_message(self, client, obj, msg):
    self.arrived_msg = msg.payload.decode()
    if self.arrived_msg == "sync":
        a = datetime.datetime.now()
        b = "%d,%d,%d,%d,%d,%d,%d" % (a.year, a.month, a.day, a.hour, a.minute, a.second, a.microsecond) .  <------ here a string time format is created
        self.client.publish(topic=self.topics[0], payload=b, qos=self.topic_qos)

3) on a terminal (MAC OS), subscribed to relevant topic- cant see publish results. which are OK:

sync                           <----- ESP sends request
2018,9,18,12,44,18,903242      <----- string answer from broker

4) BUT when Arduino code get this time stamp:

void callback(char* topic, byte* payload, unsigned int length) {
        char incoming_msg[50];
        // ledBlink(30, 5);
        Serial.print("Message arrived [");
        Serial.print(topic);
        Serial.print("] ");
        for (int i = 0; i < length; i++) {
                Serial.print((char)payload[i]);  <----- print #1
                incoming_msg[i] = (char)payload[i];  <----- generate incoming msg
        }
        Serial.println("");

        if (strcmp(topic,clockTopic)==0) {       <------- detect relvant topic for clock sync
                Serial.print(incoming_msg);  <------ Print #2
        }

5) I get this result on serial monitor :

Message arrived [HomePi/Dvir/Clock] 2018,9,18,13,48,5,230009 <---- here time stamp is OK , Print #1
2018,9,18,13,48,5,230009$��?O: @ . <----- Print #2

EDIT1:

6) I tried adding a null termination in time stamp, but it just added \0 to time stamp
Appreciate any help

Guy


texts:
This sketch:

#include <SPI.h>
#include <Wire.h>
#include <U8g2lib.h>

//  OLED display.
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
void setup() {
  u8g2.begin();
}
void loop() {
}

Compile OK with Arduino 1.8.3, but under UECIDE 0.8.9-pre15 fails to link, with this message:

Compiling...
• Preprocessing...
• Compiling sketch...
• Compiling core...
‣ arduino
• Compiling libraries...
‣ U8g2 [/home/look/Documents/UECIDE/libraries/U8g2]
‣ SPI [/home/look/.uecide/libraries/Communications/arduino/SPI]
‣ U8g2 [/home/look/Documents/UECIDE/libraries/U8g2]
‣ Wire [/home/look/.uecide/libraries/Communications/arduino/Wire]
• Linking sketch...
/tmp/build-47290781-bacc-48e0-bc90-833910b26209/borrar.cpp.o: In function `U8G2::write(unsigned char)':
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:248: undefined reference to `u8g2_DrawGlyph'
/tmp/build-47290781-bacc-48e0-bc90-833910b26209/borrar.cpp.o: In function `U8G2::initDisplay()':
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:101: undefined reference to `u8x8_InitDisplay'
/tmp/build-47290781-bacc-48e0-bc90-833910b26209/borrar.cpp.o: In function `U8G2::clearDisplay()':
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:104: undefined reference to `u8g2_ClearDisplay'
/tmp/build-47290781-bacc-48e0-bc90-833910b26209/borrar.cpp.o: In function `U8G2::setPowerSave(unsigned char)':
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:107: undefined reference to `u8x8_SetPowerSave'
/tmp/build-47290781-bacc-48e0-bc90-833910b26209/borrar.cpp.o: In function `U8G2':
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:62: undefined reference to `u8x8_ascii_next'
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:62: undefined reference to `u8x8_ascii_next'
/tmp/build-47290781-bacc-48e0-bc90-833910b26209/borrar.cpp.o: In function `U8G2::home()':
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:278: undefined reference to `u8x8_utf8_init'
/tmp/build-47290781-bacc-48e0-bc90-833910b26209/borrar.cpp.o: In function `U8G2_SSD1306_128X64_NONAME_1_HW_I2C':
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:679: undefined reference to `u8g2_cb_r0'
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:679: undefined reference to `u8g2_cb_r0'
/home/look/Documents/UECIDE/libraries/U8g2/src/U8g2lib.h:679: undefined reference to `u8g2_Setup_ssd1306_i2c_128x64_noname_1'
collect2: error: ld returned 1 exit status
Compiling Fail

Both IDEs are set for Arduino Pro Mini 3.3V 8Mhz. In UECIDE I'm using GCC 4.9.2 for AVR. I copied the same U8g2 source code to both Arduino and UECIDE own libraries directory.

U8g2 library is version 2.15.2 by Oliver, installed via Arduino IDE and copied to the UECIDE libraries directory,

The problem, so far, only happens with U8g2 and not other libraries.

How do I solve this problem?


texts:
I've got an Si4703 breakout from Sparkfun, which communicates via I2C. I have gotten it to work very easily using a regular 3.3V Arduino Pro Mini, but am now trying to move everything over to an ATtiny85. It seems this should be possible, but my I2C knowledge is basically zero.

SETUP
I have everything laid out on a breadboard:

ATtiny chip with 3.3V power and ground from a good power supply
Si4307 on the breadboard too
SDIO on digital pin #0 (pin 5 on the chip) with a 4.7K pull-up running to 3.3V and out to the breakout
SDLK on digital pin #2 (pin 7 on the chip), same as SDIO
A reset pin for the breakout, running from digital pin #1

I've verified this with the Pro Mini and it works great, so I'm doubtful the problem is here.

SOFTWARE
My ATtiny is set up using the TinyWireM library for I2C, and using a customized version of the Sparkfun Si4703 library. <-- if I had to guess, this is where the problem probably is... I think

My modded library files are here (too long to paste in the forum):
https://gist.github.com/jeffThompson/5e48c8915148e6e0bac7d85c9a3da948
https://gist.github.com/jeffThompson/10934cf8f07b3000e7e61601266b2b2c

And my Arduino code:

#include <TinyWireM.h>
#include <Si4703_ATtiny.h>

int SDA =   0;       // I2C data pin on ATtiny85
int SCK =   2;       // I2C clock pin on ATtiny85
int reset = 1;       // can probably be any digital pin

Si4703_ATtiny radio(reset, SDA, SCK);

void setup() {
  TinyWireM.begin();    // need this?
  radio.powerOn();
  radio.setChannel(937);
}

void loop() {
  radio.setVolume(15);
  delay(1000);
  radio.setVolume(0);
  delay(1000);
}

TESTING
I've tested both the Pro Mini and ATtiny85 version using my scope, but I'm pretty new to that tool, especially for I2C. I see similar clock and data patterns from both versions, and can see that there is readable I2C data from the ATtiny on my scope (it is finding readable hex data and sees it is ACK-ed, at least some of the time). I have programmed ATtiny chips through the Arduino IDE before, so I'm pretty familiar with that process, and double-checked things are outputting using an LED.

TLDR
I'm not anywhere near an I2C expert, and have never built an Arduino library, so I'm guessing I need some help with my modded library (unless I'm missed something else obvious).


texts: What pins to use on a Teensy to get data from multiple peripherals?

texts:
I'm using a Teensy to keep records on the location, speed, altitude, and direction of a weather balloon I'm hoping to launch. I have an Adafruit LSM9DS1 and a Ublox NEO-M8N with compass (HMC5833L) so to get all the data from these I need to connect to a total of 6 pins to get the data. I also want to use a Pixhawk radio telemetry unit to send these data to the ground so I can see them in realtime, so that will involve at least 2 more pins I believe.
The Teensy appears to have plenty of IO pins for all of this, but I've noticed that in all the libraries I've installed to try to use with these things, the pins to use aren't explicitly set. The libraries I've played with include the Adafruit LSM9DS1 library, NeoGPS, Pixhawk Arduino link, RadioHead, Grove HMC5833L, and others. I've been able to get some serial data in by using pins 18 and 19, but I can't attach all the periperhals to the same pin.
It feels like I'm missing something very basic here but I haven't been able to figure out how to use these libraries with inputs on different pins. Even when I look into the code of the libraries themselves, I can't find where the pins are being set. Most of the documentation that mentions which pins things use is written for specific Arduino models, like the Uno, and don't mention the Teensy.
What pins do I use if I want to read and write on more than one peripheral from my Teensy? How can I get data on more than just the two "default pins" that these libraries seem to expect?


texts: How to count the number of rising edges on DS3231 rtc?

texts:
I am using a DS3231 rtc and I would like to get millisecond accuracy from it so I decided to use the 32kHz generated clock from it. I wrote a code that would count the rising edges or falling edges using an interrupt with (RISING or FALLING parameters) but I get only zeros on my Serial board for the count.

Here is the code I am using :

#include <DS3231.h>
#include <RTClib.h>
#include <Wire.h>
#include "rtc.h"
#define InterruptPin 3

volatile long lcnt = 0;

RTC_DS3231 rtc;

void setup() {
  Wire.begin();
  Serial.begin(74880); // init serial port
  pinMode(InterruptPin, INPUT_PULLUP);
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
  attachInterrupt(digitalPinToInterrupt(InterruptPin), fcnt, FALLING);
}
void loop() {
  unsigned long a=millis();
  if (a<1000){
  Serial.println(lcnt);
  }
}

void fcnt(){
  lcnt+=1;
}

I just want to check how many rising edges I have in 1s. What is strange is that this code used to work and now it doesn't ^^'... I don't know if I changed something by mistake or deleted something useful.

Can somebody help me to resolve this little problem ?

Thanks a lot for your time !


texts: What does this lines mean in RFID UID Card Reader Code?

texts:
I'm currently doing a project using RFID. I'm wondering how this lines of the code work. I know that this has something to do with getting the UID of a scanned/tapped card, but can someone please explain or elaborate to me each line, how it executes? Thank you very much.

  String ID = "";
  for (byte i = 0; i < 4; i ++) {
    ID += (rfid.uid.uidByte[i] < 0x10 ? "0" : "")
          + String(rfid.uid.uidByte[i], HEX)
          + (i != 3 ? ":" : "" );
  }


texts: Controlling a 240v AC high current relay

texts:
Should I use 2 relays, one for the hot wire and one for the neutral ?
I'm talking about 16A.


texts: Measuring the capacitance of 2 capacitors at a time

texts:
I need help with my project. In my project, I have two homemade capacitors made from 2 aluminum foil strips separated by a water bottle. I need to detect which bottle is going to become empty as people drink from it. So I plan to use the change in capacitance to detect the empty bottle. I know how to measure capacitance of 1 bottle and detect the change, but I don't know how to do it to 2 bottles at a time. Any ideas how to do this?
Here is the following code, I have been working on.

// Initialize Pins
int analogPin = 0;
int analogPin1=1;
int chargePin = 13;
int chargePin1=12;
int dischargePin = 11;
int dischargePin1 = 10;

// Initialize Resistor
int resistorValue = 10000;

// Initialize Timer
unsigned long startTime;
unsigned long elapsedTime;

// Initialize Capacitance Variables
float microFarads;
float microFaradr;
float nanoFarads;
float nanoFaradr;

void setup()
{
  pinMode(chargePin, OUTPUT);
  pinMode(chargePin1,OUTPUT);
  digitalWrite(chargePin1,LOW);
  digitalWrite(chargePin, LOW);
  Serial.begin(9600); // Necessary to print data to serial monitor over USB
}

void loop()
{
  digitalWrite(chargePin, HIGH); // Begins charging the capacitor
  digitalWrite(chargePin1,HIGH);
  startTime = millis(); // Begins the timer

  If(analogRead(analogPin)>648){
    elapsedTime= millis() - startTime;
    microFarads = ((float)elapsedTime / resistorValue) * 1000;

    if (microFarads == X) // X is an arbitrary capacitance when the bottle is empty and X is not a variable
    {
      Serial.println(" Bottle A is empty");
    }

    digitalWrite(chargePin, LOW); // Stops charging capacitor
    pinMode(dischargePin, OUTPUT);
    digitalWrite(dischargePin, LOW); // Allows capacitor to discharge
    while(analogRead(analogPin) > 0)
    {
      // Do nothing until capacitor is discharged
    }
    pinMode(dischargePin, INPUT); // Prevents capacitor from discharging
  }

  If(analogRead(analogPin1)>648){
    elapsedTime= millis() - startTime;
    microFaradr = ((float)elapsedTime / resistorValue) * 1000;

    if (microFaradr == Y) // Y is an arbitrary capacitance when the bottle is empty and Y is not a variable
    {
      Serial.println(" Bottle B is empty");
    }

    digitalWrite(chargePin1, LOW); // Stops charging capacitor
    pinMode(dischargePin1, OUTPUT);
    digitalWrite(dischargePin1, LOW); // Allows capacitor to discharge
    while(analogRead(analogPin1) > 0)
    {
      // Do nothing until capacitor is discharged
    }
    pinMode(dischargePin1, INPUT); // Prevents capacitor from discharging
  }
}


texts: When it comes to UART to RS485 communication, what is the difference between the 'MAX485' and the 'HW-0519' module?

texts:
I recently found this model with the ID 'HW-0519' on it. It can be found online (HW-0519 in Aliexpress) and is sold for the purpose of converting UART to RS485 communication using Arduino devices. The MAX485 module (MAX485 in Banggood) is the more commonly used module for this purpose and has been used in many projects. The MAX485 has the following pins DI (data in), RO (receiver out), DE (Data Enable), RE (Receiver Enable), VCC, GND and the 'A' and 'B' pins for the RS485 device (Shown below).

The HW-0519 module, has a slightly different pin configuration, and I can't seem to wrap my head around it. It has Tx and Rx pins, which I am guessing match up with RO and DI respectively, but don't have enable pins. They have the VCC and GND pins along with the 'A' and 'B' pins, but also come with this pin marked in Chinese. I translated it using Google translate and it translates to something similar to 'Ground'. Which is not connected to the GND pin though (Shown below).

Does anyone know whether I can use the HW-0519 module in the same manner as the MAX485? If so, are there any libraries written for this module? I want to use the module for communication with a pH sensor like the one in this link.


texts: Communication with ESP, HTTP requests or WebSocket?

texts:
Here is my problem. I'm working on making a wifi addressable RGB LED (like WS2812b) controller, I'm using an ESP8266 as the hardware. I'm also creating a phone application for controlling the device and setting different modes. What I'm doing right now is that I communicate with the module by sending GET commands from my phone app. For example to change the brightness I send http://192.168.4.1/I125I Then on the ESP side the code is as follows:

WiFiClient client = server.available();
  if (client) {
  String inData= client.readStringUntil('\r');
  if (inData.indexOf("I")!=-1){
 BRIGHTNESS=str2int(inData.substring(inData.indexOf("I")+1,inData.lastIndexOf("I")));
}}

It works, but I'm not sure if this way of sending data is efficient at all. if change colors too rapidly the ESP resets. I recently found another code that uses GET and POST commands but different methods are used, like the following

server.on("/brightness", HTTP_POST, []() {
    adjustBrightness();
  });

Then inside adjustBrightness function brightness is adjusted. This way it looks more professional but Is it more efficient?

I recently bought a commercial RGB LED controller that uses ESP8266 as its core. I tried to see what the phone app sends to the controller using the Drony app. For my app I could see all the get command the app was sending

192.168.4.1/I255I

192.168.4.1/R200RG90GB76B

...

but for the commercial controller I just saw one connection, something like "157.10.12.10:5172"

Is this using websockets?
Is using websocket a better way? is it more robust?

I'm writing the code in Arduino IDE.


texts:
I'm trying to see how fast I can read an Arduino IO port.  It's being toggled with an random speed /white square wave and I want to see which is faster, the Arduino or the signal.  The pin on port D is driven by an open collector comparator (LM311).

So I have this code

buffer[0] = PORTD;
buffer[1] = PORTD;
buffer[2] = PORTD;
buffer[3] = PORTD;
buff...

...fer[28] = PORTD;
buffer[29] = PORTD;

that I can read the port in burst mode.  This code is as fast as I can write I think.  I've unrolled a possible loop here.  buffer[] is a local variable as that seems faster.  I'm not an assembly expert so I can't really browse the assembly instructions.

I've added a 500 Ohm pullup resistor to the input pin that I'm interested in.  A lower value seems to give more randomly distributed values that a 10k resistor.

I tried timing buffer[0] ... buffer[29] readings and that returns 4 microseconds with interrupts off.  I hope that micros() doesn't need interrupts to function!  That would equate to 7.5 million readings /sec.  That's about 2 clock cycles per instruction on my 16 MHz board.  Can this be right?

How fast can this code run?


texts: Arduino Sending faster/more data to a web server

texts:
I'm working on a project that reads vibration on a building using an accelerometer and displaying it's data on a web server. The plan is to read 10 samples/second from the accelerometer and send that data every 5 seconds to a web server using arduino yun.

So there would be 10(samples/sec) x 5(seconds) x 3(3 axis - x,y,z) = 150 data points that will be sent to the webserver, I tried this with the client.get() command but it cannot send that much data to a web server, I also tried POST request but i've had trouble with the sending it multiple times since it needs to have a delay.

What are the other options that I can do in order to achieve this? Any suggestion would help and please if you think my question is bad or not stated properly don't report me, I'm still new here in stack exchange. Any help/suggestion is much appreciated

Arduino Code for POST request

#include <Bridge.h>
#include <HttpClient.h>
#include <YunClient.h>

//IPAddress server(192,168,1,200);
byte php_server[] = {192,168,1,9};

YunClient client;
String data = "", datax="", datay="", dataz="";
unsigned long ts_0 = 0, tr_0 = 0, t_read = 100;
int counter=0;

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

}

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

  if((millis()-tr_0>=t_read)) {

    if(counter<49) {
      counter++;
    }
    else if(counter == 49) {
      //Serial.print("sent");
      String dat = "0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12";

      send_to_ws(dat);
      Serial.println(dat);

      counter = 0;
    }
    tr_0=millis();
  }
}

void send_to_ws(String data) {
  if(client.connect(php_server, 80)) {
    Serial.println("Connected");
    client.println("POST /arduino/add.php HTTP/1.1");
    client.print("Content-Length:");
    client.println(data.length());
    Serial.println(data.length());
    Serial.println(data);
    client.println("Connection: Close");
    client.println("Host:192.168.1.9");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println();
    client.println(data);
  } else {
    Serial.println("Connection error");
  }
}

Serial monitor output when running this sketch, It prints it in the serial monitor but only blank data is being pushed in the database of the server


texts: What Ohm Termination Resistor is needed for this schema ? What, Where and How?

texts:
I'm building a Master-Slave system using some arduino pro mini as slaves and a Mega 2560 as Master to communicate over RS485 config via MAX485. Since i'm newbie in RS485 i know that i need to put some termination resistor somewhere is the line but i don't know where and how, also i don't know how much ohm should it be. My Baud rate is 9600 and i'm using twisted pair cable (CAT5) and it's 120 meters long.

UPDATE 1:
My goal is to get data from each slave time to time, every slave is connected to a temperature sensor and sends temperature value to master on demand (when master asks for it.) The master asks for temperature value from all slaves separately (of course!) and repeatedly every 500 ms. First it asks slave 1 to send data and then slave 1 sends data to master, then master asks slave 2 to send data and slave 2 sends data to master and so on. after 500 ms, it does this again.

UPDATE 2:

Master side code (Mega 2560):

#include <AltSoftSerial.h>
#define DE 2 //RS485 Data enable pin. HIGH=Transmit, LOW=Receive
String inputS = "";
boolean stringComplete = false;
AltSoftSerial altSerial;

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

void loop() {
 digitalWrite(DE, HIGH); //Transmit
 altSerial.println("MEGA:ProMini1");
 altSerial.flush();
 digitalWrite(DE, LOW); //Receive
 CheckAndReceiveFromMax(); //Check if data received
 if(stringComplete){
   inputS.trim();
   if(inputS.equals("ProMini1:ACK"))
    Serial.println("MEGA: ProMini1 Acknowledged: " + inputS);
   else
    Serial.println("MEGA: Not valid On ProMini1: " + inputS);
   stringComplete = false;
   inputS = "";
 }
delay(100);
digitalWrite(DE, HIGH); //Transmit
altSerial.println("MEGA:ProMini2");
altSerial.flush();
digitalWrite(DE, LOW); //Receive
CheckAndReceiveFromMax();
if(stringComplete){
  inputS.trim();
  if(inputS.equals("ProMini2:ACK"))
    Serial.println("MEGA: ProMini2 Acknowleged: " + inputS);
  else
    Serial.println("MEGA: Not valid On ProMini2: " + inputS);
  stringComplete = false;
  inputS = "";
}
delay(500);
}

void CheckAndReceiveFromMax()
{
 while (altSerial.available()) {
 char inChar = (char)altSerial.read();
 inputS1 += inChar;
 if (inChar == '\n')
  stringComplete1 = true;
 }
}

Slave side code (Pro Mini1):

#include <AltSoftSerial.h>
#define DE 7
String inputS = "";
boolean stringComplete = false;
AltSoftSerial altSerial;

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

void loop() {
 digitalWrite(DE, LOW); //Receive
 CheckAndReceiveFromMax(); //Check if data received
 if(stringComplete){
  Serial.print("String received: ");
  inputS.trim();
  Serial.println(inputS);
  if(inputS.equals("MEGA:ProMini1")){
   Serial.println("ProMini1: Mega called me!");
   digitalWrite(DE, HIGH); //Transmit
   altSerial.println("ProMini1:ACK");
   altSerial.flush();
   digitalWrite(DE, LOW);
  }
 stringComplete = false;
 inputS = "";
 }
}

void CheckAndReceiveFromMax()
{
 while (altSerial.available()) {
 char inChar = (char)altSerial.read();
 inputS += inChar;
 if (inChar == '\n')
  stringComplete1 = true;
 }
}

And the same code for ProMini2, ProMini3 and so on.

OUTPUTS:
When master calls ProMini1, the ProMini2 answers, and when master calls ProMini2, ProMini1 aswers. Also, received data is not always in correct format.

Server Serial Monitor:

 MEGA: Not valid On ProMini1:  roMini1:ACK
  :
MEGA: Not valid On ProMini2: ProMini1:ACK
MEGA: Not valid On ProMini1:  roMini1:ACK

MEGA: Not valid On ProMini2: ProMini1:ACK

MEGA: Not valid On ProMini2:  roMini1:ACK

.
.
.


texts:
I have a RFID module using NXP RC522 chipset.

I have no idea that is it correct the module using 27.120 mHz

And I have 4 IC card,

A) 0005302176, (Blue color tag, come with the RFID module)
B) 0008846830 134,65006 (White card, come with the RFID module)
C) 0004189112 063,60344 (White card)
D) White card, no number print on the card. Only this card UID can be read.

Here is the pinout

Which I connected to Arduino UNO R3

     RFID         UNO R3
(Pin Name, Pin)    (Pin)
SDA        1        10
SCK        2        13
MOSI       3        11
MISO       4        12
IRQ        5        -No Connect-
GND        6        Ground
RST        7        9
3.3V       8        3.3V

PS: I am using this library, and this example.

PS: The serial return this information MFRC522 Software Version: 0x91 = v1.0


texts: How do you remove dependencies from a library?

texts:
I'm writing a library for a project i created, but it depends on the Neopixel library from adafruit. I want to remove this dependency and have my library be a stand-alone library.

Is there a way to run a ws2811 chip without the neopixel or similar library?


texts: How to make Serial.read() return an integer instead of an ascii value?

texts:
I want Serial.read() to return an integer instead of an ASCII value. For example, in the below code if I input 2, I want the output as 2 instead of 50
void setup(){
    Serial.begin();
}

void loop(){
    if(Serial.available()){
    int t = Serial.read();
    Serial.println(t);
}


texts: How to map PID output to actuator control?

texts:
I'm building a control system for the heating of a house. A sensor reads the temperature inside and is then used as the input in the PID control. The temperature is then controlled by a servo which opens and closes a shunt were water runs to the radiators. I understand all the inner workings of the PID library for Arduino and PID in general, but the thing I don't understand is what I'm exactly supposed to do with the output signal I receive. In what way should the output signal correspond to how open or closed the shunt is?

I understand I can simply map the output signal to the servo signal, but is this the correct way? And with what angle coefficient should I map it with, cause that is basically set with the P parameter, isn't it? Is there some standard way to map the output signal to the actuator "signal", so that that tuning parameters are somewhat "standard".

Hope someone understands anything of what I tried to explain :)


texts:
I have a rather simple question, which I cannot seem to find the answer to online.

I would like to host a wireless network using an arduino. Other devices could connect to and communicate with the arduino. Could I do that with a shield like this?

Also, once a device (say a phone) is connected, how would it go about requesting a web page, or other information?

Thank you!


texts:
Is there anything built into the Arduino Uno or the XBee Pro 2 radio module that I can poll within my Arduino script to act as a unique identifier? Mac address or otherwise? If anyone has a code snippet that can do this it'd be extremely appreciated.

Currently my Arduino nodes are broadcasting only to my node.js server, but my server is broadcasting to all the nodes, so if they're all waiting to be assigned an identifier number through the handshake function I wrote, they all receive the same one. If I stagger powering them up this is avoided and they each get a unique ID, but I hope there exists a cleaner solution.


texts:
I'm trying to add a bootloader hex to Nick Gammon's Atmega Board Programmer sketch, and I can't seem to get a hex file to convert.

I need to convert "Arduino-usbserial-atmega16u2-Uno-Rev3.hex", but that wasn't working so I thought I'd try converting one that's already used in the sketch, "Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex", but that's not working either. I've followed the instructions from http://www.gammon.com.au/bootloader

I've tried it using Wine and Paralells. Clicking the copy button when using Wine causes the program to stop responding.

Here is a screenshot of the error:

Thank you


texts:
I have a question about connecting a Arduino with Raspberry Pi.

What is the benefit of connecting the two?


texts: Problem with passing string pointer from child to parent

texts:
I am trying to pass a pointer to a const char * from a child to its parent, but I am clearly not understanding how to do this correctly. Here is the code which contains three classes:
1) parent
2) Alpha (child)
3_ Beta (child)

#pragma once
class Parent {
protected:
    char *childName;

public:
    Parent ( char* _childName ) {
        childName = _childName;
    }

    char *getChildName () {
        return childName;
    }
};

class Alpha: public Parent {
protected:
    const char* alphaName = "ALPHA";

public:
    Alpha (): Parent ( alphaName ) {
        Serial.print ( F ( "My name is " ) );
        Serial.println ( getChildName () );
    }
};

class Beta: public Parent {
protected:
    const char* betaName = "BETA";

public:
    Beta (): Parent ( betaName ) {
        Serial.print ( F ( "My name is " ) );
        Serial.println ( getChildName () );
    }
};

Alpha *alpha;
Beta *beta;
void setup () {
    Serial.begin ( 115200 );
    while (!Serial.availableForWrite ()) {}

    alpha = new Alpha ();
    beta = new Beta ();
}

void loop() {}

And here is the output I get:
My name is �

My name is �˵


texts:
I need to power an arduino uno with a battery but for a very long period of time. And I read a lot of thing about this. Some say do not use a 9V battery with a regulator some other say that it is the best way. SO I am really confused and I need to know what's the best solution for this (taking into consideration the fact that I need my board to last a week at least, if it is possible?)

Thanks!


texts: Error Compiling any coding in Arduino IDE

texts:
I was using the example code of "Blink", and when I try to compile it, it pop out an error as below.

I tried to:

uninstall and installed back the Arduino IDE
installed different versions of Arduino IDE
update the u8glib library
installed different version of Arduino AVR boards

but still doesn't work.

  Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno"

  C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs
  -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\ASUS\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files
  (x86)\Arduino\hardware\tools\avr -tools
  C:\Users\ASUS\AppData\Local\Arduino15\packages -built-in-libraries
  C:\Program Files (x86)\Arduino\libraries -libraries
  C:\Users\ASUS\Documents\Arduino\libraries -fqbn=arduino:avr:uno
  -vid-pid=0X2341_0X0043 -ide-version=10809 -build-path C:\Users\ASUS\AppData\Local\Temp\arduino_build_109130 -warnings=none
  -build-cache C:\Users\ASUS\AppData\Local\Temp\arduino_cache_111506 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr
  -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files (x86)\Arduino\hardware\tools\avr
  -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr
  -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files (x86)\Arduino\hardware\tools\avr
  -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr
  -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose
  C:\Users\ASUS\Desktop\FSR\FSR.ino

  Error compiling for board Arduino/Genuino Uno.


texts: Different behavior when Arduino Micro powered by laptop USB vs portable charger USB

texts:
I'm working on a project that uses an LM35 temperature sensor to control a few LEDs. Above 97 degrees, one LED should switch on. Below 95 degrees, it should switch off and the other should switch on. In between those temperatures, the LED state should remain unchanged.

When the Arduino Micro is plugged into my Macbook USB port, everything functions as I expect, however when I plug the same USB cable into a different USB power supply (like a portable cell phone charger), the LEDs tend to blink back and forth at the frequency at which I tell the Arduino to check which state the LEDs should be in.

The only thing I can think of that is different between the laptop USB and battery is the lack of serial data being read by the battery. Unclear, though how I can fix this issue. Any suggestions would be appreciated.


texts: How to put together an HKT30 optical rotary encoder?

texts:
I'm working on a project involving stepper motors. It is important for this project to track the position of these motors, so I decided to buy an optical rotary encoder, specifically an HKT30(HKT3005-C03G-1000B-5E) pictured here. I've found it difficult to find resources on how to put this together. I've found datasheets, like this one, but it does not seem to be made up of the same components I have. I think I've basically gotten the gist of how one puts this together from google images, but I would like to be pointed in the way of an explicit resource in case I damage my parts.
Additionally, I was hoping for an explanation on the 5 wires (red, green, black, white, and gray), their purpose and how to set one up on a board.
If any clarification or images are needed, I would be happy to provide.
Thank you!


texts:
I have recently made a shield for an arduino mega2560 with among others sensors, a CAN interface (MCP2515 and ISO1050).

The purpose is to create a CAN network with several arduino uno and one Mega.
Until now, the network is working well on all the Uno but unfortunately not on the Mega. As I have others sensors on the SPI bus, I've kept the MOSI, MISO and SCK pins unchanged (51,50,52) and I put the SS on the Analog pin A13 (number 67 for digital), which was the nearest unused pin I had during the routing process. Before making the shield I was careful and I've check if I could use it as a SS for my purpose.

Despite my caution, it appears that I'm not able to communicate within the CAN bus.

Before going futher, I'm using the SeeedStudio library made for their shield to test the connection.
I've tried to use A13 (using an #define)and 67 for the

SPI_CS_PIN = 67;

without any success.

I've also tried to force the bus to be active with a digitalWrite at the beginning of the setup().

// demo: CAN-BUS Shield, send data
// loovee@seeed.cc

#include <mcp_can.h>
#include <SPI.h>

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 67;

MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

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

while (CAN_OK != CAN.begin(CAN_500KBPS))              // init can bus : baudrate = 500k
{
    Serial.println("CAN BUS Shield init fail");
    Serial.println(" Init CAN BUS Shield again");
    delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}

unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};

void loop()
{
// send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf
stmp[7] = stmp[7]+1;
if(stmp[7] == 100)
{
    stmp[7] = 0;
    stmp[6] = stmp[6] + 1;

    if(stmp[6] == 100)
    {
        stmp[6] = 0;
        stmp[5] = stmp[6] + 1;
    }
}

CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(100);                       // send data per 100ms
}

If you have any idea on why it's not working and a way to solve this problem, please let me know :)

Undeadguy.


texts: Programming stepper motor move a fixed step till it reach the target

texts:
I have a stepper motor and try to program it like this but I kinda stuck since I'm new to Arduino.
1. The target is set to 2048, means motor have to move 2048 steps.
2. I program the motor to run 200 steps each time, every 200 steps will stop for a sec until it reach 2048.

I've been using AccelStepper library to program my motor, I found out it is very hard for me to program like this. I'm not asking to do my homework but I dunno where to start. Just wanted to ask what method can I use to program the motor to work like this. Thank you.


texts: Where are the traces connected to RESET-EN leading?

texts:
Once again, I am following this schematic, and I am confused as to where RESET-EN connects:

This is how I have it mocked up it Fritzing, but I feel like this is incorrect:


texts: Spikes in CO2 and TVOC measurements with CJMCU-811 sensor

texts:
Firstly, I'm not sure if this is the right SE to ask this question. Please feel free to direct me somewhere else if needed.

I am observing large spikes in CO2 and TVOC measurements using the CJMCU-811 sensor. When plotted it looks like this:

Nothing particular is happening around the sensor at those moments of spikes, I'm not breathing on the sensor etc.

I use Arduino Uno with the following code:

/******************************************************************************
  Read CO2 and TVOCs from CJMCU-811 sensor

  Arduino connection:
  3.3V to 3.3V
  ACC to 3.3V
  GND to GND
  WAK to GND
  SDA to A4
  SCL to A5

******************************************************************************/
#include <Wire.h>

#include "SparkFunCCS811.h"
#define CCS811_ADDR 0x5B

CCS811 mySensor(CCS811_ADDR);

void setup()
{
  Serial.begin(9600);
  Serial.println("CCS811 Basic Example");

  Wire.begin();

  CCS811Core::status returnCode = mySensor.begin();
  if (returnCode != CCS811Core::SENSOR_SUCCESS)
  {
    Serial.println(".begin() returned with an error.");
    while (1);
  }
}

void loop()
{

  if (mySensor.dataAvailable())
  {

    mySensor.readAlgorithmResults();

    delay(1);

    Serial.print("CO2 ");
    Serial.print(mySensor.getCO2());

    Serial.print(", tVOC ");
    Serial.print(mySensor.getTVOC());

    Serial.println();
  }

  delay(2000);
}

Of course I can filter and not worry about them, but I'm nevertheless curious what is causing it. Any suggestions what could be the reason for that?


texts:
My digital inputs are behaving as if they were floating, even though I've properly connected them with a resistor.  I've tried the pull-down configuration pictured below, as well as a internal pull-up.

By using digitalRead() and serial.pintln() I've collected the state of each input tested (0 to 10) and they all do the same: random 0's and 1's.  When I change a state (press or release the button), they seem to work for a second or two, then, they go crazy again.  Sometimes, they even work backwards (showing HIGH when it's supposed to be LOW) for a couple of seconds.

Is my two-day old Arduino UNO fried?


texts: Decide on baud rate for a project using Arduino Uno R3

texts:
I am using an Arduino Uno R3 with the MPU 6050 to get motion data. Different example codes use different baud rates, without any proper explanation as to why.

So how do I know which baud rate is perfect for my project?


texts: SPI MCP23S08 to Arduino: strange stop/start behaviour

texts:
I have built an Arduino minimal breadboard circuit to test some parts I recently bought and I successfully managed to get the I2C MCP23008 working perfectly with LEDs and an LCD display.
However I have just recently tried to use the SPI version of the same chip with some really odd results. I have tried searching for code examples and libraries, but struggled to get anything working.

So I studied the datasheet to create the following code to flash an LED, however the flashing seems to work only briefly and then stops. Sometimes it stops and then stays lit randomly.

// inslude the SPI library:
#include <SPI.h>
const int chipSelect = 10;

void setup() {
  // initialize SPI:
  SPI.begin();

  pinMode(chipSelect, OUTPUT);

  // set the chipSelect as an output:
  digitalWrite(chipSelect, HIGH);

  sendCommand(0x00, 0x00);
}

void sendCommand(int address,int data) {
  digitalWrite(chipSelect, LOW);
  //  send in the address and value via SPI:
  delay(1);

  // SPI addressing 0x40 with A0 and A1 set to ground and R/W bit set to output
  SPI.transfer(0x40);
  SPI.transfer(address);
  SPI.transfer(data);
  delay(1);

  // take the chipSelect pin high to de-select the chip:
  digitalWrite(chipSelect, HIGH);
}

void loop() {
  sendCommand(0x09,0xff);
  delay(1000);
  sendCommand(0x09,0x00);
  delay(1000);
}

I have a couple of these devices and they both came from a supplier on eBay. I would like to validate my code before I suspect that the devices are dodgy and are not a genuine part.
Can anyone help me validate my code, or has anyone had a similar experience with the SPI bus and other devices not behaving properly?
Edit
Could it be due to the length of my wires to the Arduino?


texts: Declaring and using array of structures in Arduino

texts:
Printing structure variables, I get default values. What is wrong with my code?

struct SCENARIO
{
  int Lamp_Pin = -1;
  int PB_Pin = -1;
} ;

SCENARIO  _red;
SCENARIO  _yellow;
SCENARIO  _white;
SCENARIO  _stop;
SCENARIO btns[4] = { _red,  _yellow, _white, _stop};

void setup()
{
  _stop.Lamp_Pin = 8;
  _stop.PB_Pin = 4;

 ///// initializing other 3 objects i.e. red & white & yellow
 ////
for (int i = 0; i < 4; i++)
  {
    Serial.print(i);Serial.print(":");
    Serial.print(btns[i].Lamp_Pin);Serial.print(":");
    Serial.println( btns[i].PB_Pin );
    //pinMode(  btns[i].Lamp_Pin, OUTPUT);
    //pinMode(  btns[i].PB_Pin, INPUT);
  }
}

The image below shows what I get. It seems I have not initialized the variables!


texts: Using WifiUdp.h on Arduino Mega and ESP8266?

texts:
I was trying to run this library on Arduino Mega, using ESP8266 as replacement of Wifi Shield, as suggested on my older thread.

The problem is, I got error in compiling, after with this code :

#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspUdp.h>

#include "AppleMidi.h"
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, appleMIDI1);
....

  exit status 1

  'WiFiUDP' was not declared in this scope

if I modified the code into this :

#include <WiFiEsp.h>
#include <WiFiUdp.h>

#include "AppleMidi.h"
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, appleMIDI1);
....

I got this error instead

  C:\Program Files
  (x86)\Arduino\libraries\WiFi\src\utility\server_drv.cpp:313:40: error:
  'WARN' was not declared in this scope

WARN("error waitResponse isDataSent");

                                    ^

  exit status 1

Full code here at pastebin.
I was pretty much stuck now. Please help! :(

Thanks :D


texts: Is there any way to prevent Arduino CLI from closing each time?

texts:
I prefer writing code in Vim, so I'd like to get a workflow going with the Arduino CLI. I used to use ino, but I didn't like the restructuring of the project, which meant anyone who downloaded the code having to use ino.

I can build and verify using /Applications/Arduino.app/Contents/MacOS/Arduino --verify MyProject.ino, which pops up a new instance of the Java IDE, then exits after verifying.

While this works, and works well, it's incredibly slow. Is there any way to keep the IDE open to save the few seconds lost from the IDE starting again?


texts: How to communicate from Python to Arduino Softserial

texts:
That is driving me nuts so I need your help.

Master : PC with Ubuntu, a USB to serial converter (chipset CP2102), connected to Arduino Uno Pin 10, 11 and GND. The Arduino Uno is plugged in the same PC.

Port for the converter is /dev/ttyUSB1
Port for the Arduino is /dev/ACM0

I tried to communicate by Serial through the converter (I do not want to use ACM0 as it is buggy and sometimes suddenly change to ACM1, messing up my big testing program).

On Arduino side :

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
int inByte = 0;         // incoming serial byte

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

void loop() {
  if (mySerial.available()) {
    char inByte = mySerial.read();
    mySerial.println(inByte);
    Serial.println(inByte);
  }
  delay(10);
}

The Python script (simple one to debug)

import serial
arduino = serial.Serial('/dev/ttyUSB1', 9600)
arduino.timeout=0.5
arduino.bytesize=8
arduino.stopbits=1
code=49 #ASCII Code for 1
arduino.write(chr(code).encode('utf-8'))
print(chr(code))
print(chr(code).encode('utf-8'))
print(arduino.readline())
print("done")
arduino.close()

When I run it, I have on Arduino Serial monitor a g

and Python script output

1
b'1'
b'Ly\x00'
done

By the way, the very same code over /dev/ttyACM0 and standard serial rather than Softwareserial works perfectly (as long as the port remains ACM0 of course)


texts: ESP8266 Stops Working After A While (Unknown Problem)

texts:
have an esp8266.

i'm trying to create a DDNS updater.

it has to wait 5 min then do a GET request to a URL.

Here's my code:

/* Code For DNS Updater.*/

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define LOOP_TIME 300000

const char* ssid = "SomeSSID";
const char* password = "SomePSWD";

const String address="http://dynamicdns.park-your-domain.com";
const String path="update";
const String pathHost="host";
const String pathPassword="password";
const String pathDomain="domain";

const String dnsName="my-example-host.com";
const String ddnsPassword="my-example-password";
const String updateHosts[]={
    "@",
    "subdomain1",
    "subdomain2",
  };

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

long nextUpdate=0;

void loop() {
  if(nextUpdate<millis()){
    if (WiFi.status() == WL_CONNECTED) {
    updateDNS();
    }else{
      connectWiFi();
    }
    nextUpdate=millis()+LOOP_TIME;
  }
}

void updateDNS(){
  Serial.println("Updating Hosts:");
  for(int host=0;host<(sizeof(updateHosts)/sizeof(String));host++){
    Serial.print(updateHosts[host]+": ");
    String assembledURL=address+"/"+path+"?"+pathHost+"="+updateHosts[host]+"&"+pathDomain+"="+dnsName+"&"+pathPassword+"="+ddnsPassword;
//    Serial.println("Host: "+updateHosts[host]+" URL: "+assembledURL);
    HTTPClient http;
    http.begin(assembledURL);
    http.GET();
    http.end();
    Serial.println("Done");
  }
}

void connectWiFi(){
  WiFi.begin(ssid, password);

  Serial.print("Connecting To ");
  Serial.println(ssid);
  Serial.print("Password: ");
  Serial.println(password);
  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {

    delay(500);
    Serial.print(".");

  }
  Serial.println();
  Serial.print("Connected To ");
  Serial.println(ssid);
}

and it stops after a couple of hours - which isnt good for a DDNS updater.

EDIT: maybe it has something to do with my timer. will try an unsigned long instead.


texts: Realistic to create a local variable as the SD buffer?

texts:
My intention is to read a file (of max. 128 KB) from an SD card and store it in (external SRAM). I will use an Arduino Mega which has 8 KB of internal SRAM but even 8 KB is not really much for some processing and keeping some administrative instances of classes always available. I don't need SD access after the copy process anymore.

Would it be a crazy idea to change the SD library buffer instead of using a global or internal buffer in the SD library, instead to pass a local variable which is removed automatically after the copy function ends?

So in other words, I create the SD buffer as local variable, I call the SD library using instead the buffer I created, and afterwards the local variable (buffer) will be removed, saving me 512 bytes.

Of course I will only do this when getting into SRAM problems, but I think there is a chance to get into this.

Update:

The reason I want this. In my project (at least initially), I want to process (fast) MIDI messages, that means receiving MIDI messages, process them and send MIDI messages. Since this needs to be done in about 10-20 ms (between receiving/sending), performance is important.

The configuration of the processing can be completely configured (via an external program). The configuration file will be written to a (micro) SD card. The typical size of such a file will be between 1 and 128 KB. Since it will be to slow for every incoming MIDI message to read the SD card, the content of the SD card (max 128 KB) will be copied to SRAM.

So after this 'copy' I do not need the SD card (reader) anymore, so the 512 byte buffer is never used anymore.

(maybe in the future I will make some way to alter the configuration on the Arduino, with an LCD/keypad, but even than the saving of a configuration file will be a very occasional task where I can make the 512 byte buffer temporarily).

During processing I might need more (internal) SRAM. SInce I expect my application will contain quite a bit of classes/functions so the stack can grow; also I need to store intermediate result. Of course I also can store this in the external SRAM, but it will be much less comfortable.


texts:
I want to control my Arduino with USB gamepad. I know that exists library for USB keyboard for Arduino but I don't know any library for usb gamepad. I have PS3 styled gamepad. I dont want to use shield.

Any solution or help?