text:
Do we need another controller when using ArduPilot?
I'm a newbie on the all Arduino platform and I'm currently building a drone with Autopilot functionality. I've heard about ArduPilot and I'm wondering if that is all I need, in terms of controllers (I'm excluding the ESC, engines, and the rest). Can I simply program the ArduPilot, connect a Wireless interface to it and merrily be able to control it ?
Cheers,
r

There are a few key points worth making before answering your question:

Ardupilot has undergone a re-branding and is now known as APM; this change was made to reflect that the technology has grown beyond strictly using an Arduino environment. You can see this for yourself at their website.
The term(s) Ardupilot/APM have been used somewhat interchangeably for both the hardware and software. This can be confusing so I'll refer to the hardware as an "APM Kit"

Can I simply program the ArduPilot, connect a Wireless interface to it and merrily be able to control it ?
Yes, 3DRobotics offers APM Kits that are plug-and-play hardware packages with preloaded firmware. They (optionally) supply all of the components needed to operate a small unmanned hobby aircraft including:

Power module
Transmitter and receiver for the APM-to-Ground-Station link
GPS module w/ compass

The user is generally expected to provide:

Airframe
Batteries
Servos
RC transmitter and receiver
An additional voltage-regulator/BEC if using high-torque servos
A computer (groundstation)

However, the unspoken question is:
How easy is it to setup Ardupilot/APM to work safely and correctly?
In truth, it takes considerable effort to put together a properly working system. The plug-and-play hardware saves you a great deal of trouble but tuning and operating an RC aircraft requires a different skillset. If you're experienced in RC, this may not be a problem.
From experience, you can expect to spend a number of weekends configuring and tuning APM (the software) even if you have a perfectly tuned RC aircraft.


text:
How can I make ultrasonic sensors resistent to splashes and dirt?
I wasn't sure where to ask this question, but since it's actually an Arduino project, I'll try it here.
I want to upgrade my old car with ultrasonic parking sensors: I've already bought HC-SR04s as sensors and started to play on my breadboard.
But what I'm still unsure about: if I place them in my car's rear bumber, how can I make them resistent to rain or dirt or something like that?
As pictured on Wikipedia, the sensor is covered with a small piece. But what could I use to cover the holes in the bumper, without interfering with the ultrasonic measuring?

I'd try thin rubber (e.g. from a latex glove). Or some other kind of thin plastic. Just try out some of the plastics from food containers you'd normally throw out.

I don't think you'll be able to cover that sensor in a way that will still allow it to work. There are waterproof ultrasonic sensors out there, here's one on Amazon, for example.
The other thing you might want to look at is IR instead of ultrasonic. That's easier to weatherproof since the IR emitter/receiver are already covered. You'll probably have less range with IR, though.

Maybe at a minimum for testing you could point the sensor downwards and then use a reflector to discourage water and dust. Something like: http://letsmakerobots.com/content/cyperbolic-reflector-review

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
How can I run two loops simultaneously on an Arduino Uno?
I'm new to Arduino and I have two devices that I'm trying to control:

A RGB LED light strip that can change colors
A light sensor that can detect the ambient light level

What I'd like to do is have the LED strip continuously cycle through a rainbow of colors, and the light sensor will adjust the brightness of the LED strip based on the ambient light level. Here are the two pieces of code by themselves, which I've tested in isolation and confirmed that they work properly:
LED strip:
j = (j + 1) % 256; // current iteration of the light cycle

// set the strip color
for(int i=0; i< strip.numPixels(); i++) {
  strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}

// display the new colors and wait 20ms before the next cycle
strip.show();
delay(20);

Light sensor:
sensors_event_t event;
tsl.getEvent(&event); // get a light measurement
strip.setBrightness(event.light); // set the brightness of the LED strip

The problem is that the light sensor takes anywhere from 100ms to 600ms to get a reading, and tsl.getEvent(&event) is a blocking call, so the end result is that the LED strip updates way too slowly. I would need to run the two side by side so that the light sensor read does not block the LED strip update. Any idea how I can accomplish this?

what library is "tsl" coming from?

100 to 600ms is excessive. Is it just for a LDR connected to an analog input?

@BrettM I think he is using the TSL2561 I2C light sensor.

You can make the sensor return data faster by lowering it's accuracy.
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */

You can also modify the library to not power-down the sensor after each reading. Just open TSL2561.cpp, find the getFullLuminosity function, and comment out the line reading disable(); and the 12 lines reading switch (_integration){ ... }
Another solution is, to have the pixels update every 20ms using a timer. You can have the timer, interrupt the main loop every 20ms and update the pixel values.
(I can't really help you with timers, as I myself set the registers for my timers, and ISRs directly, which isn't for beginners. But there are probably libraries for it, to make it more user friendly.)

http://playground.arduino.cc/code/timer1 this library should help make timers easier

See my edit above for negating the need for any delay, by leaving the tsl2561 on, all the time.

The arduino is not a multithreaded or multi-tasking device. You have to write your different functions to "play nice" with each other. Blocking code is death for this sort of multitasking. You might need to rewrite your code that reads the light sensor to be non-blocking.
If you can get that code to be non blocking then Visual Micro's post is the way to go.

Your first, biggest problem is

the light sensor takes anywhere from 100ms to 600ms to get a reading, and tsl.getEvent(&event) is a blocking call,

You need non-blocking access to the light sensor. Look at the library code to see what it is doing when it blocks. Chances are it waits for the sensor to set a 'done' bit. If so, you'll need to modify the library, either by

adding a boolean .isDone() function that tests the done bit, and don't let your main program call for a reading until isDone() == TRUE; or
making .getEvent() a non-blocking such that it immediately returns an obviously invalid reading (such as -1) instead of blocking if the sensor isn't ready yet.

That leaves your main program free to service whatever needs doing and is ready to do without holding up everything for the slow sensor.

Setup a 'state server' in your loop(). Put simply this means keeping track of the next command for each task, then doing one thing in each task per loop().
If one task needs to run at a faster speed than another task you can use a timer in your loop to decide what to do next.
If a task needs a pause then save the "Last Run" millis() to a global variable and ignore the task until the correct amount of time has passed. Do not use a delay(), always let the loop() run.
The idea is that the loop() runs as often as possible but you do one thing each time it runs.
It takes a while to get the hang of this way of working but it leaves the Arduino processor free to process all jobs evenly.
int task1Status=0;
int task2Status=0;

void loop()
{
  doOneThingOfTask1();
  doOneThingOfTask2();
}

//10 things to light the leds, but only do one
void doOneThingOfTask1()
{
  if (task1Status==10)
    task1Status=0;

  switch (task1Status)
  {
    case 0:
       //start doing a new process

    case 1:
       //do something

    case 9:
       //do the last thing

  }
}

I was going to post something similar, then I noticed that the OP said that the code for taking light measurements is blocking code.

@Duncan C Oh! Good point. I will leave the answer because I think it describes a way of working that avoids the same issue elsewhere in code. Also it might be that by examining the library call to getEvent() the same solution can be applied to reduce the delay. Obviously this means changing the library code but one can copy the library into the sketch folder and hack it as local source. a Lib change would certainly help but local source and a little hacking might produce a solution. Thanks :)

There are libraries that allow multitasking, for instance my library arduOS.
This should work:
#include <arduos16.h>
#include <arduos_core.h>
#include <roundscheduler.h>

SYS_enable_preemptive; // do NOT forget this!!!
void setup()
{
    auto sched = new SYS::RoundScheduler(2);
    sched->add(&loop1); // those 2 are functions.
    sched->add(&loop2);
    SYS::start();
}

But keep in mind that actual multitasking can be rather tricky, with very obscure bugs. (but you can find them).

This OS looks easier to use than your average arduino OS

1.Use two arduino's and have them talk to each other via serial or i2c.
Probably the simplest option (but not the cheapest - though you can get clone arduinos from US$4 ).
2.Find a light sensor that updates faster. Tried an ldr(light dependent resistor)/photocell ?  Then could use analog read.
Could also switch from using arduino to c, but thats a lot more work and you are still going to hit similar problems.

Switching to C would do nothing, really, for this issue.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Smallest package possible reading microSD
I have a project running on an arduino nano, and as part of it, I'd like to read from and write to a microSD card.  My problem is that the microSD shield for it doesn't fit my form factor (think slightly larger than a pen; definitely handheld).
I've purchased a PJS008-2003-0, and I'm wondering, assuming I have the soldering chops, is there any real reason I can't connect this directly?  What does the breakout board get me other than nicer connection points and a blinking light?  Do the example SD sketches rely on anything the shield provides, or will they work for me?

You could always take the adventurous step of moving away from Arduino and explore the PIC32-o-sphere.  The Fubarino SD would be perfect for you.

Thank you for the suggestion.  I will evaluate it as a possibility.

Running your processor at 3.3v would simplify things.  Also consider if you actually need a microSD card - how much storage do you need?  In the realm of megabytes rather than gigabytes there are spi flashes which are smaller and will cost you less than a card + socket.

I will run at 3.3v.  I did purchase the Fubarino, but I can't find any specs on its size.  I guess I will see if it will work when it gets here. @Majenko, you may want to turn that into an answer, if it isn't too large, I'll go with it.  I haven't heard of spi flash before, but I will look into that if SD doesn't work for me.

@MBurke You can get a better idea of scale with it on a breadboard: http://hackaday.com/2015/05/21/unix-on-your-breadboard/

How about an ATtiny85 in a surface mount package on a little single-layer board with the card socket?  Or even a DIP ATmega with the card off to one end.  There are of course processors which are smaller (and much more powerful) overall, but you won't get much narrower than the surface mount tiny's until you get into the harder to work with leadless packages - the relatively easy to solder TQFP's are going to be wider than a DIP, especially if you have to route them on one or two layers.

If your willing to be adventurous and step away from Arduino (as in AVR chips) and try out some of the myriad of other offerings there are around now, then you may find a better board that fits your needs.
One popular example is the Fubarino SD:

It gives you a PIC32 chip (128KB RAM, 512MB Flash, 80MHz) with a microSD card slot already on the board.  And it measures just 2.5cm x 7cm.
Of course, you may need to tweak your programming a little to get it working as you want - the IDE (MPIDE) is a bit old and the Arduino API compatibility is slightly behind the times (but catching up gradually). It's also fully supported by my UECIDE programming environment.

2.5cm wide?  That's huge.  Even a .3" DIP IC is narrower.  If the uSD card remains that will determine the minimum width at around or slightly over half that, with moderate care on the MCU side resulting in something no wider.

@ChrisStratton They do a smaller one without an SD card and a smaller chip (PIC32MX250). You can't get much thinner and still have an SD card on there...

On the contrary, you can.  This is almost twice as wide as it needs to be, on account of that row of holes along each edge well outside the uSD holder.

Well, you could sacrifice some IO pins (and hence some functionality) if you wanted to dedicate it to just SD, yes, or make it much longer.  Of course, you'd want to switch to a QFN instead of the TQFP to allow the whole board to be narrower - and that narrowness may come at the cost of needing to go 4 layer, which will make the whole thing more costly.  So it's a compromise between cost, size, and functionality. Slightly larger but keep the costs down and keep it as useful as possible.  Or are you just dissing it because it's not AVR?

I'm dismissing it because it is larger than other solutions which would not requires any platform change.  A "boarduino" type device with an uSD socket hanging on the end of it in an area where there are no pins would be around 60% as wide and better fit the asker's pen-like form factor.

So why don't you recommend one to the OP then?  Oh - maybe there isn't one...!  Stop whingeing that this doesn't meet with your utopian ideals when there is nothing better on the market (that I can find at least).  If you can find better then recommend it. If not, then **** off.  And I have pens that fat!

I'm afraid that is bigger than I'm looking for.  I don't think this will work, but I will explore it for other projects.

SD card need 3.3v for power and logic level. So most breakouts have a buffer chip to convert the logic levels from 5v to 3.3v.
PS, you could use an microSD to SD adapter, and solder some wires to its pads, if you are unable to solder the tiny pins on the part you ordered.

I am planning to run at 3.3v, the nano can run on and output this voltage.  I have also considered the SD adapter, but it is still fairly large, and it looks like its only advantage is convenience.

In that case you can just connect the SD directly to the 3.3v nano. Good luck soldering the SD socket. Shouldn't be a problem if you have some soldering experience. Rather odd 1.1mm pin pitch though. Otherwise you could use an adapter pcb board to make life a bit easier.

Most likely you will have to add at least some pullup/pulldown resistor. I would recommend having a look at the schematics of the shield.
For example this shield:
http://freematics.com/store/index.php?route=product/product&product_id=74
And it depends on which mode you want to use (SPI?):
http://en.wikipedia.org/wiki/Secure_Digital#Transfer_modes

Yes, my plan was to use SPI.


text:
Why can't I read anything but Pin 0 of PORTC?
So I am working on this lab for my Embedded Systems class, but I can't seem to read anything but the first bit of PORTC.  What's even weirder is that if any of the pins go low the first bit will go to 0, while all the others stay at 0 no matter what.
Here is my code:
 /*
 * Lab_4A.c
 *
 *  Reads the value of one distance sensor
 *  and reports if light/dark to the LCD.
 *
 *  Created on: Sep 24, 2014
 *  Author: Austin R. Bartz
 *
 *  LCD Connections:
 *  E   - PB4 (Digital 12)
 *  RS  - PB5 (Digital 13)
 *  R/W - GND
 *  Data 4,5,6,7 - PD4,5,6,7 (Digital 4,5,6,7)
 *
 *  Sensor Connections:
 *  Sensor 8 - PC0 (Analog A0)
 *  Sensor 7 - PC1 (Analog A1)
 *  Sensor 6 - PC2 (Analog A2)
 *  Sensor 5 - PC3 (Analog A3)
 */

#include <avr/io.h>
#include <inttypes.h>
#include <MSOE/delay.c>
#include <MSOE/bit.c>
#include <MSOE/lcd.c>
#include <user/initPorts.c>
#include <user/readPorts.c>
#include <user/writePorts.c>

void printBinaryLCD(uint8_t);
uint8_t readSensors();

int main(void)
{
    lcd_init();
    lcd_clear();
    while(1)
    {
        uint8_t val = readSensors();
        printBinaryLCD(val);
    }
}

void printBinaryLCD(uint8_t val)
{
    lcd_home();
    uint8_t A = ((PINC & (1<<3)) == (1<<3));
    lcd_print_uint8(A);
    lcd_goto_xy(1,0);
    uint8_t B = ((PINC & (1<<2)) == (1<<2));
    lcd_print_uint8(B);
    lcd_goto_xy(2,0);
    uint8_t C = ((PINC & (1<<1)) == (1<<1));
    lcd_print_uint8(C);
    lcd_goto_xy(3,0);
    uint8_t D = ((PINC & (1<<0)) == (1<<0));
    lcd_print_uint8(D);
}

uint8_t readSensors()
{
    DDRC = 1;
    PORTC = 1;
    delay_us(10);
    DDRC = 0;
    PORTC = 0;
    delay_ms(1);
    return PINC;
}

Any help would be much appreciated!

What kind of sensors did you plug to PORTC pins 0-3?

What Arduino board do you have? I guess you can read the port, but your sensors are not connected properly (missing supply voltage?). As you set PC0 to output High for some time (why are you doing this?), and then back to tristate, it still may have High level when reading it.

DDRx is the Data-Direction-Register-x so this can be DDRC or DDRD or anything. One register has 8 bits, 1 bit for every pin.
Making a bit 1 will result in the pin being an output. Making it 0 will result in the pin being an input.
Let's say we want to make pin 4 and 5 of port C an output.
We simply do this in the setup:
       //76543210  Pin numbers.
       //IIOOIIII  Input/Output indicator
DDRC = 0b00110000;//Code that actually does it.

So this way we can read pin 4 & 5.
But if we want to read the complete port, I suggest setting every pin of the port to input. DDRC = 0b00000000;
Then we can read the port as simply as uint8_t portValueC = PORTC;
portValueC will now have a value that represents the port's values.
It'll be binary, but you read it as decimal.
So it'll be:
0 for no inputs.
1 for only pin 0
2 for pin 1
3 for pin 0 & 1
4 for pin 2
5 for pin 2 & 0
6 for pin 2 & 1

Well. it's binary.
Let's say (pin 7,5,3,1 high)(pin 6,4,2,0 low).
This will result into the decimal value of 170.
The binary value, however, will be easier to read 0b10101010
    //76543210
  //0b10101010 (Could be the value) (pin 7,5,3,1 high)(pin 6,4,2,0 low)
//^ is decimal: 170

You should add these macros to your project to make it easier to get single bits from this value:
#define bit_get(p,m) ((p) & (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))

This way, now you can do:
if(bit_get(PINC, BIT(3)))
{
 //Do only this if PORTC pin 3 is high
}

Read this first:
Info on the registers
Info on bit fiddling

Judging from your readSensors() function, these seem to be capacitive
sensors:

you charge them to Vcc (DDRC = 1; PORTC = 1;)
you wait until they are fully charged (delay_us(10);)
you tri-state the pin (DDRC = 0; PORTC = 0)
you wait for them to partially self-discharge (delay_ms(1);)
you read the pin (return PINC;)

If my assumption is correct, and if all of those sensors are similar,
then here is your first bug: you are only charging the sensor on PC0. If
you want to charge the four sensors, you need to set bits 0 to 3 of the
port to active high. Thus, the first two statements in readSensors()
should be:
DDRC = 0x0f;   // bits 0 to 3...
PORTC = 0x0f;  // ...set to active high

Your second bug is in printBinaryLCD(). The function name, and the way
you call it, implies it is meant to print on the LCD the value passed as
a parameter. Instead, it is completely ignoring its parameter, and
reading PORTC itself. This is bad because the reading of the
capacitive sensors is time sensitive, so you should let readSensors()
do the work. You should then change printBinaryLCD() so that it
examines val instead of PORTC:
void printBinaryLCD(uint8_t val)
{
    lcd_home();
    uint8_t A = (val & (1<<3)) != 0;
    ...etc...

Nice catch on the capacitive sensors, I kinda feel the "question asker" should've mentioned that.
I also feel that  ((PINC & (1<<1)) == (1<<1)); Is wrong.
PINC&(1<<1) Should evaluate to 0b1 (or 0b0), comparing it with (1<<2) (0b100) just doesn't make sense?

@FuaZe: Comparing to 1<<1, although inelegant, does work. Say PINC == 0bxxxxxxYx, where x is “don’t care” and 1<<1 = 0b00000010. Then PINC & (1<<1) == 0b000000Y0. It’s a “bitwise and” operation.

Yes, though my remark wasn't on the syntax.
I wanted to show that the questioners: uint8_t C = ((PINC & (1<<1)) == (1<<1)); will not give the desired behaviour. But your code uint8_t A = (val & (1<<3)) != 0; did actually fix that problem.

@FuaZe: My remark isn't on the syntax either: it's on the semantics. ((x & (1<<1)) == (1<<1)) is semantically equivalent to (x & (1<<1)) != 0. I just prefer the != 0 version for a matter of style: the “do not repeat yourself” principle.

I'd say they're not equivalent. In ((x & (1<<1)) == (1<<1)) the part
(x & (1<<1) will evaluate to true/false (1 or 0?) and (1<<1) will evaluate to 0b00000010 thus they will never be equal?

@FuaZe: No. The & operator is a “bitwise and”, not a “logical and”: it's not just false or true, in the sense 0 or 1. Specifically, x & (1<<1) evaluates to either 0 or 0b00000010. If you are not convinced, try it yourself.

Ah, I see, it's not like a logic AND the (1<<1) is a mask for the bit pattern of PINC which afterwards is checked again using the same mask/pattern.
I was confused as using an mask on a pattern would always cause it to be either 0 or "true" in a way it being anything bigger than 0. But yeah, you can check the outcome of it to be like the pattern itself, didn't catch that as it feels quite unlogical (and logical differs from bitwise in this case ;D).

i can't be certain, but i reckon it has something to do with
DDRC = 1;

this equates to b000001, meaning only pinC0 is an output. i think


text:
What requirements should components have to work with Arduino (UNO in particular)
I am fairly new to the whole concept of Arduino and electronic engineering in general.
Recently I bought myself an Arduino UNO and I'm wondering what "non off the shelf" components will work when I hook them up with the UNO. I have a lot  of old electronic stuff laying around containing pushbuttons, sliders, faders, knobs etc. wich if possible, I'd like to take apart to connect them to the UNO for some fun fuzzin' around.
Many thanks in advance!
PS: this is my fist post ever on stackexchange so excuse me if the question is placed incorrectly or the tags are weird. Please DO correct me where I'm wrong.

When it comes to electronics, hypothetically anything can be connected to anything else. The only real barriers are time, cost, and practicality.
Two major things to look out for though are voltage and current requirements.
Most Arduinos operate at 5 volts, so it's often easiest to connect it to other electronic devices which also operate at 5 volts. That certainly doesn't mean you can't connect an Arduino to something that operates at 3.3 volts (for example). However, it means you may need to add some voltage level conversion circuitry (although it's not always necessary, depending on the context).
Regarding current, a critical issue to look out for is how much current something will draw. For example, a motor will often require more current than an Arduino can safely provide. That means you'd need some kind of external power supply which can be switched by the Arduino.
The most valuable thing to do is to learn to find and read datasheets. These give information about electronic components, specifying things like voltage, current, timing and so on. For situations where there's no datasheet available, you may find it useful to learn how to use a multimeter and an oscilloscope to monitor how equipment behaves.

Dear Peter, thank you so much. I could not wish for a better answer.


text:
How to Store the Value of A Sr04 Ultrasonic distance sensor (ping)?
I am using a Sr04 Ultrasonic distance sensor with Uno clone for making a Alarm. The basic idea behind this project is that In Setup, Read the distance And store it in a varibale as Threshold. And in Loop, Check the distance readings regularly and if the Reading anytime is not equal to The threshold (that means someone interrupted in front of ultrasonic sensor), then a led flashes. I Know that is system is not enough good because the real world is a bit noisy. My problem is I am storing the theshold distance in "int" variable. The compiling error is "Cant convert Long Unsigned char to Int" something like this. Please tell me how can I store the reading of my sr04 sensor in a variable. I am using NewPing Library.

First you must verify that storing the value as int is even possible: long int can represent much larger values than int. Are you 100% sure that the maximum reading you will ever get can be represented as int?
In case the answer to the previous question is "yes", then you can just cast it on the fly:
int int_val = (int)function_returning_longint();
In case the answer is "no", you can either give up the idea of using int and stick with long, which is not necessarily bad, or you can scale down the value, at the price of loosing some resolution:
int int_val = function_returning_longint() >> 8; This assumes that long is 16 bit and int is 8 bit, but it would be preferable to use explicit types, like int8_t and int16_t. And in your case you might have to shift by a different value than 8.

Either way, do not make casts of from big type to small type without being 100% sure that the max value you will ever deal with can fit in the small type.

If you want to store it as int, you have to firstly store it in a long type then convert it into int.
For instance:
long i;
int j;
i = getReading();
j = (int) i;

There are many ways to do it, for example you can also use rounding to convert it into integer variable.

It's not necessary to use an auxiliary variable.
But what is really dangerous in this answer, is that it doesn't check if the value is small enough to be represented as int.


text:
Arduino Uno not Detecting on Laptop
I have an Arduino Uno. The story is I installed Arduino IDE and Drivers before even buying an Arduino Board. I used it a little and when I bought and connected an arduino board, I was unable to make it detect. I smacked a little usimg google and was able to somehow Fix this. but again another day, It worked a little and started creatimg problems. now its not detecting. Please suggest me a way To make it work...
Should I format my windows 7 and Reinstall all the drivers as per rules?

Is this a genuine Uno or a cheap clone? Should I format my windows 7 - no, I doubt that would achieve anything.

Its a cheap clone. Can You suggset a measure to fix this ??

Clones tend to need different device drivers than a genuine board. Did it ever work?

when i first connected, it did not work. but i tried to make it work. and after 3 hours i could make it work. i tested blink programs and controlled a servo using diffrent sketches. but another day, its not detecting on my laptop. Last time I had uploaded Blink program. When i connect the board with computer, the 'ON' led and Onboard pin 13 LED blinks as per program. But my computer cant detect it at all.

I installed the driver of that clone from that link but no effect

under the IDE make sure you have set the correct board and comm port. go to tools>>board then choose your board then tools>>Comm to choose the correct comm port.
is the IDE saying anything about having problems connecting to the board?
and no re-installing all drivers should not be necessary.

When I goto tools >> comm The selection area is greyed and inactive.
should i Try to Reflash the atmega ??

That means it really isn't detecting the arduino at all. Try unplugging the arduino for about 3 minutes, then plug it back in on a different USB port.
Is the arduino a genuine one or a clone? do you have a link to where you bought it?

Slow down a bit. Don't reflash the Arduino. Don't re-install Windows 7. Do you want to change houses as well? Try to do some simple debugging. I don't understand this part: I smacked a little usimg google and was able to somehow Fix this.

Please see Have I bricked my Arduino Uno? Problems with uploading to board.

Yes, my computer is not detecting the arduino at all. Today, I re-installed Windows 7, but still not detecting. "I smacked a little usimg google and was able to somehow Fix this" means that when I got this problem, I searchd this on Googl and re-installed arduino drivers. It startd working but only for a day. Nxt day, Sam Problem. How Can I try debugging, as you said??

One more thing, Last time I had uploaded Blink program. When i connect the board with computer, the 'ON' led and Onboard pin 13  LED blinks as per program. But my computer cant detect it at all. Is my cable damaged ?? If yes then how my board can draw power from That usb and not the programming functions? Product Link : http://www.ebay.in/itm/Arduino-UNO-R3-ATmega328P-ATmega16U-compatible-Development-Board-USB-Cable-/252024502692?hash=item3aadd4b9a4


text:
Connecting MicroSd Reader with arduino uno
I am working on a Project with
(a) Arduino Uno Clone (6 PWM Pins i.e, 3,5,6,9,10,11)
(b) 6 Servos
(c) MicroSD Reader Module
(d) Speaker
As We Know that MicroSD reader modules uses pins 10, 11, 12 of an Arduino board, but my pin 11 is already being used by a servo motor.
1. Then how can I connect the MicroSD reader in my project ?
2. Which pin can I use for the speaker in this case ?
Please help me plus Provide me some additional information if needed.

The best answer is: don't use pin 11 for your servo motor - move it to another pin.
The SD card needs SPI.  SPI is pins 10/11/12/13.  You can't change that.  You can much more easily move the servo to a different pin, since there are multiple PWM pins that can support the servo in hardware. If they are all taken then software PWM is easy and there are libraries available to do it for you, so you can use any IO pin you like for that.  Much simpler than re-writing the SD card software to use bit-banged SPI on other pins (which would also be incredibly slow).

Please Give me Link to that Soft PWM. And what about the speaker? Does it also needs PWM pins ?

Tone works on any pin. I don't have a link off hand, ask Google.

The Servo library he is using is most likely already using software PWM. You can't use pins 5 and 6 as servo pwm pin without messing up the delay and millis functions.

Pin 10 is not mandatory for SPI. Slave select can be performed with nearly any other pin without complicating matters.

@Ariser Pin 10 is special.  It's the SS pin, and has to be in the right mode for SPI to work right.  If pin 10 is set to output then SPI is in master mode.  If pin 10 is set to input then SPI is in slave mode.  It's part of the SPI module and can't be changed.  Yes, you can also use any other pin as your slave select, but you still have to take care that you don't break SPI by using pin 10 wrong.

@Majenko: You are right, you have to use pin 10 as an output, or your controller will halt on a signal on this pin.


text:
Arduino Mega 2560 R3 with Shield Model Wireless SD R3 not working
Recently I've bought an Arduino Mega 2560 R3 and a Shield Model Wireless SD R3 from http://www.amazon.de/Arduino-A000065-Netzwerkkarte-Wireless-SD-Shield/dp/B00L1FO860. I try to run the example from https://www.arduino.cc/en/Tutorial/ConnectWithWPA
Before running the sketch I turn the DIP switch to the position USB.
It seems like the WIfi Shield is correct connected to the Arduino since the LEDs TX and RX are blinking during upload the Sketch.
Sadly as output I got only:
    WiFi shield not present
Currently I'm not sure if the hardware itself provide Wifi functionality. Does somebody know if it should work with this hardware?

You see that double row of 10 pin headers?  That's an XBee connector.
https://www.sparkfun.com/pages/xbee_guide
You use it to connect your XBee module of choice (there's a few to choose from) to communicate wirelessly between Arduinos using the special XBee system.
Note that XBee is not WiFi, it's Wireless.  The two are very different things (Wireless refers to any wire-free communication system, WiFi is one specific protocol on one specific set of frequencies using a specific set of encodings, etc).  XBee cannot talk WiFi in the same way that I can't talk Chinese.
For WiFi you need a WiFi shield.
https://www.arduino.cc/en/Main/ArduinoWiFiShield


text:
Wifi.status() always returns WL_NO_SHIELD
I've an Arduino Mega 2560 R3 and recently bought a Wifi Shield CC3000 from ebay http://www.ebay.de/itm/201405512301
They write that the firmware has the version ServicePack 1.11.1.
The WiFi shield is connected to the Arduino and green status light is on.
I try to run this example code:
void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
  Serial.println("WiFi shield not present");
    // don't continue:
  while(true);
}
...

It seems that Wifi.status() always returns WL_NO_SHIELD.
What can I do?
Thanks for help.

Are you using a CC3000 library, or the IDE's WiFi library that is written for the Wiznet chip?

The problem is solved now.

I imported the Adafruit_CC3000 library which can be downloaded here: https://github.com/adafruit/Adafruit_CC3000_Library
I run the example but the output was chinese nonsense
Instead of
Serial.begin(115200);
I used
Serial.begin(9600);
then the examples run without any problem

Thanks @Majenko. His question was very helpful.


text:
Arduino Mega, Ubuntu, Time.h: No such file or directory
I'm using an Arduino Mega with Ubuntu 15.10.
Sadly I've got an error during compilation, that the Time.h library cannot be found. The verbose compile output shows:

/usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall
-fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560
-DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105
-D__PROG_TYPES_COMPAT__
-I/usr/share/arduino/hardware/arduino/cores/arduino
-I/usr/share/arduino/hardware/arduino/variants/mega
-I/usr/share/arduino/libraries/LiquidCrystal
-I/usr/share/arduino/libraries/SPI
/tmp/build6998056390288565759.tmp/Home_Guard.cpp -o /tmp/build6998056390288565759.tmp/Home_Guard.cpp.o
**Home_Guard.ino:2:20: fatal error: Time.h: No such file or directory**
compilation terminated.

I've already tried to use "time.h" instead of "Time.h" but it doesn't help.

ok. It seems that the Ubuntu arduino package does not contain this library. The file Time.zip has to be downloaded from the authors website: http://www.pjrc.com/teensy/td_libs_Time.html and added in the Arduino GUI menue bar: Sketch -> Import Library -> Add Library

Since Time.h is a third party library that is not surprising.  NO Arduino package on ANY operating system contains Time.h since Time.h isn't written by Arduino.


text:
Emulating a generic Mifare USB peripheral device with RFID-RC522
Hardware
Dev Board: Arduino Nano V3.0

Module: RFID-RC522 13.56 MHz

Cable: USB A - USB Mini B

Configuration
Physical

Code
/*
 * --------------------------------------------------------------------------------------------------------------------
 * Example sketch/program showing how to read data from a PICC to serial.
 * --------------------------------------------------------------------------------------------------------------------
 * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
 *
 * Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
 * Reader on the Arduino SPI interface.
 *
 * When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
 * then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
 * you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
 * will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
 * when removing the PICC from reading distance too early.
 *
 * If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
 * So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
 * details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
 * keep the PICCs at reading distance until complete.
 *
 * @license Released into the public domain.
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 */

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

#define RST_PIN         9               // Configurable, see typical pin layout above
#define SS_PIN          10              // Configurable, see typical pin layout above

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

void setup() {
    Serial.begin(9600);                 // Initialize serial communications with the PC
    while (!Serial);                    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();                        // Init SPI bus
    mfrc522.PCD_Init();                 // Init MFRC522
    mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
    }

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
    }

    // Dump debug info about the card; PICC_HaltA() is automatically called
    mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

See: https://github.com/miguelbalboa/rfid/tree/master/examples

Goal
Generic USB-Compatible Mifare NFC Read/Writer
So, you can get these devices that just plug directly into your regular computer via USB, and basically function as an ordinary HID or peripheral device. I have various different ones from when I was investigating the security implications associated with CRYPTO-1 & MiFare Classic access control cards. They all basically work the same, and produce/dump the same standard output.
The thing is, I have little experience with Arduino, and hardware development in general. The Arduino USB Port is obviously used for serial communication with the IDE for programming the MEGA328P, and I can use the IDE's serial interface, plotter, etc. But it doesn't seem to want to play with any of the other applications (MiFare Classic Universal tooKit, etc.) that "just work" with the (unaffiliated) commercial/store-bought devices.

I would guess, that the commercial products expose a different interface to the USB host (the PC). On the Uno/Nano there is an extra chip, that exposes a virtual serial interface over USB. On the Uno it is possible to reprogram that chip, to on the USB interface, what you tell him (On Nano it might be impossible to connect to the correct pins because of the size. Haven't done this ever). Or you use an Arduino/Chip, which already has native USB support, like the Leonardo. Though I don't know, if you really would be able to imitate the Mifare interface

You have to use Arduino Mini and Keyboard.h library which comes with arduino IDE. Arduino Nano does not have HID capable processor.
Try this with mini:
#include <Keyboard.h>

void setup() {
 // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
 // connected to ground:
 pinMode(2, INPUT_PULLUP);
 Keyboard.begin();
}

void loop() {
 //if the button is pressed send the message
   if (digitalRead(2) == LOW) {

     Keyboard.print("Hello!");

   }
}

I will build same thing now, just tested Arduino Mini and will add rc522 to it.

did you try it? how'd it go?

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Fast Python to arduino communications
I've been communicating with a teensy arduino over USB using pySerial--which has been simple, but slow. With simple write commands from Python and a corresponding read command on the teensy, I can only achieve 200kHz transfer rates. I'm hoping to get over 1MHz at least, but I don't see a path towards that rate.
Are Ethernet shields capable of augmenting for rates over the MHz range? How can I get faster data transfer rates between my computer and arduino? I'm mainly interested in one-way communications (computer directs teensy).

You can't communicate faster than the MCU can respond.

@ignacio what is the MCU?

With simple write commands from Python and a corresponding read command on the teensy, I can only achieve 200kHz transfer rates. - is this serial comms we are talking about? What are you planning to do with the Teensy that it needs to be told to do something at 1 MHz?

I'm configuring hundreds of analog nodes over SPI buses.

@nick_name the MCU is the microcontroller unit. The brain. That black square-shaped plastic thing on the Teensy with all the little legs. On the Teensy 3.1 it's the MK20DX256, part of the Freescale K20 series, if you need to know. It can run at up to 96MHz (on the Teensy), so receiving data at speeds in MHz+ won't be a problem.

The fastest means of communicating with the Arduino is SPI. Ethernet shields use that (as do SD cards). It's quite fast, but it has limits. The fastest the SPI clock can go is the CPU (MCU) clock rate divided by 2 (per bit), that is one byte every 16 CPU clock cycles. There is also an overhead of a couple of clock cycles between bytes, so you can reckon on 888,888 bytes absolute maximum (ie. about 868 kHz) on an Arduino running at 16 MHz.
However that's just throwing the data away. It needs to be stored somewhere, compared to something, acted upon. That all takes clock cycles.
That is for the 16 MHz Arduinos. The Teensy 3.1 apparently runs at 72 MHz which is somewhat faster. I haven't timed SPI on that, presumably you can get a faster transmission rate, but I suspect that the ARM processors also take more instructions to do the same thing, so the 72 MHz might not be quite as fast as it looks.
Then you have the issue of how fast you can get data in and out of the Ethernet card, and how fast you can do whatever-it-is you want to do with it, in the processor.

Thank you for the detailed response! Right, so an Ethernet shield using an SPI interface is going to be best then. I'm curious--does the Ethernet transmission protocol that would link the computer and arduino support these rates, or would I be bottlenecked there?

I can't really answer that. It would depend on the Ethernet card, the library driving the card, quite possibly what your router can handle, and what the PC Ethernet card can handle. Plus, of course, the speed of communication between the Arduino and the Ethernet card, and how much time you spend doing something with the data once you get it.

First of all, khz and mhz are not data transfer rates. They are frequencies - "something per second" - did you mean kilobits/second or kilobytes/second (both, confusingly, abbreviated to kbps by various people).
If you have not already done so, you can specify a bitrate for your communications - serial.begin takes a parameter which specifies the speed - most example seem to use 9600 bits/second, you can crank this all the way up to 115,200 bits/second - 12 times the speed. I don't know if this will work with a Teensy, and/or USB. You will probably at least need to specify this in your terminal program and/or pySerial.
I wonder what you are doing that requires 1Mbyte/second communication with an Arduino, and if you can do that a little smarter?
At that rate, the 64kbytes of memory can be filled up in 1/16th of a second.
You can get a faster "information transfer" by increasing the information density - for example, the English word "True" takes up 4 characters = 32 bits , but a logical true value only takes up 1 bit.
If you are processing the data on the Arduino, at 1mbyte/second, you have 72 instructions to do something with that byte before the next one is there - not much time.
You could increase the data rate by pushing the data in in parallel, using multiple pins - e.g. 32 bits in parallel, one on each of 32 pins, one data point per cycle. There would be no practical way to assimilate data at that speed.
If you are sending this from a PC, perhaps some of the data could be processed on the PC before sending?
Another option would be to divide the work over multiple Teensies, with the PC combining the work - e.g. if you have temperature sensors that output 4 byte values, you want to read 250 of them at a rate of 1000 samples per second (= total of 1mbyte/second), then you might be able to run 25 Teensies, each sampling 10 sensors, and each pushing data at 40kbytes/second, rather than one running at 1mbyte/second.
Quite frankly, these are all fairly contrived examples - most sensors can't be read that quickly; even an Arduino's analog read is limited to 10,000 reads per second - if you do nothing else. This produces 100 kbits/second, or 20kbytes per second (each 10-bit read is returned as two bytes, with the remaining 6 bits being 0).


text:
Help Connecting MicroSD Module with Arduino Uno
I am Trying to make a MicroSD .wav file player using Arduino Uno. I have ordered a MicroSD Card Module from ebay today.
Product Link : http://www.ebay.in/itm/Micro-SD-Card-Module-SD-Storage-Board-TF-Card-Memory-Shield-SPI-For-Arduino-/161696480012?
As You can See in the Product Image, there is not mentioned on the PCB that which Pin Is ground or VCC Or any other SPI pin.
1. How will I identify the correct pins of the MicroSD Module ?
2. How can I connect a speaker to arduino to play .wav files. Is Amplifier neccessary? I am weak when it comes to electronics.
I have listened that when I connect a Capacitor in series with speaker, it will boost the output volume. There will not be music but only voice recordings in .wav files. I want to listen it clearly only.

this listing has the labels printed on the bottom. Probably identical to your.

OMG, what a vile listing!
Anyway, I think you'll probably find they are in the order listed in the description when the connector is facing south. It's probably printed on the rear of the board which they don't show.
That is, from left to right, GND, VCC, MISO, MOSI, SCK, CS.
As for connecting a speaker, that depends if you want low quality (PWM) audio, or high quality (DAC) audio.  The latter requires the addition of an audio shield, most of which have an SD card slot on them already thus alleviating the need for this SD card breakout board.
For the former there is a library and instructions here: http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio

I got my MicroSD Module today. The labels were printed At the bottom side. Dont confuse, CLK = SCK. The VCC goes to arduino 5v.


text:
Firebase.failed() returns 0 after Firebase.begin(), but returns 1 while reading or writing from/to firebase from ESP8266
The program was running fine, a few days ago, but now it just wouldn't read/write to the database. I'm running on ArduinoJson 5.13.5 and using FirebaseArduino library. I have set all the rules to true, would love to know how to debug this error. Also Firebase.error() does not give any output at all!

Apparently the Firebase's fingerprint has changed recently and has caused the above issue!
from here get the latest finger print and change it in the ...\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient.h
In the file mentioned above: update the value of static const char kFirebaseFingerprint[] to the new one mentioned above.
P.S. One issue going forward for me(planing on implementing it on a long term basis) is how to be ahead of this issue in the future, so that I can get the data uninterrupted!

It is OK to accept your own answer as the solution to the problem.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
What is the difference between running code with the scope of the void setup() or void loop() vs. outside their scope?
Good evening everyone,
I have bene playing around with making my own library, specifically for the controlling Timer1 on the Arduino Mega 2560. I'm sort of new to OOP but I am trying my hand at it here.
I wrote some code to generate a PWM wave with a 100 ms period and a 25% duty cycle, and I have Siglent SDS 1052DL, 50MHz oscilloscope that I'm using that verifies the code is successful. I am using clear-timer-on-compare-match mode and timer interrupts to generate the PWM wave. My code is below:
#include "Timer1.h"

Timer1 timer;

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

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

I made a Timer1.cpp file and a Timer1.h to go along with this file. They are below.
Timer1.cpp
#include "Arduino.h"
#include "Timer1.h"

float frequency = 10.0;
float period_ms;
float clock_pulse = 16.0;

unsigned long opening_time = 25000;

unsigned int ocr1a;
unsigned int ocr1b;

Timer1::Timer1() { // Object used to control 16-bit timer1

}

void Timer1::begin() {
  CRITICAL_SECTION_START; // Clear I bit
  CLEAR_TCCR1A; // Reset TCCR1A
  CLEAR_TCCR1B; // Reset TCCR1B
  SET_CTC_MODE; // Set to CTC mode
  DISABLE_TIMER1_INTERRUPTS; // Disable OCIE1A/B
  TCCR1B |= (1 << CS12); // 256
  period_ms = (1000.0f / frequency);
  ocr1a = 1000UL * (period_ms / clock_pulse);
  OCR1A = ocr1a;
  TIMSK1 |= (1 << OCIE1A);

  ocr1b = (unsigned int)float(opening_time) / clock_pulse;
  OCR1B = ocr1b;
  TIMSK1 |= (1 << OCIE1B);
  TCNT1 = 0; // Reset counter

  CRITICAL_SECTION_END; // Set I bit
}

ISR(TIMER1_COMPA_vect) {
  digitalWrite(13, HIGH);
}

ISR(TIMER1_COMPB_vect) {
  digitalWrite(13, LOW);
}

Timer1.h
#ifndef TIMER1_H
#define TIMER1_H

// ========== HANDY MACROS ========== //
#define CLEAR_TCCR1A                  TCCR1A = 0
#define CLEAR_TCCR1B                  TCCR1B = 0
#define SET_CTC_MODE                  TCCR1B |= (1 << WGM12)
#define DISABLE_TIMER1_INTERRUPTS     TIMSK1 &= ~((1 << OCIE1B) | (1 << OCIE1A))
#define CLEAR_CLOCK_SELECT_BITS       TCCR1B &= ~((1 << CS12) | (1 << CS11) | (1 << CS10))

#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()
#define CRITICAL_SECTION_END   SREG = _sreg

class Timer1{
  public:
  // Constructor:
  Timer1();
  // Begin:
  void begin();

};

#endif // TIMER1_H

This code works exactly as I would expect. I originally had placed the whole block of code found in the Timer1::begin() method in the Timer1::Timer1() constructor method. When I did this, I was getting a completely different signal (2.04 ms period with about an 80% duty cycle). Is there a simple explanation for what is occurring?

You are coding in C++ but have variables global to the file Timer1.cpp.  It would be better if you defined these variables with scope of the class Timer1.  Then they should be defined for member functions which should include the constructor.  What I'm wondering ... how did the code in the constructor compile in the Timer1.h file when the defined variables only had scope over the Timer1.cpp file?

In your test code, you declare Timer1 in global scope. This means its
constructor will be called right when the program starts, even before
main() is called. The first thing the Arduino main() does is
to call init(), which configures all the timers for PWM
operation, as expected by analogWrite(). Then, any initialization of
Timer1 done by the constructor will be undone by init(). That's why
you want to defer that initialization until setup().
Edit: I took the liberty to do a code review on your post. Below are
a few suggestions. I hope some of them might be useful.

Put the empty constructor in the .h file, this avoids it being
compiled into a real empty function.
Qualify frequency, clock_pulse and opening_time as const,
and make period_ms local to Timer1::begin(). This way all the
floating point operations are performed at compile time and you
don't get all the floating point support compiled into your program.
Your CRITICAL_SECTION_* macros are redundant with
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) from avr-libc. But
then, do you really need to block the interrupts the whole time?
I don't find the other macros in Timer1.h really useful either: just
put comments next to each access to a hardware register.
I would set TCCR1B last: the timer starts counting the moment you
set this register.
You should subtract 1 from the values you set in OCR1A and
OCR1B: the period and HIGH time are OCR1A+1 and OCR1B+1
respectively.
You may want to round the period and HIGH time to the nearest
integer. It may make no difference here but you users may want to
change frequency and opening_time.
Your variables ocr1a and ocr1b serve no useful purpose, they
just needlessly eat RAM.
You casting opening_time to float, then back to unsigned int,
serves no useful purpose either.
You may want to replace digitalWrite() with direct port access, as
this function is really slow and you are calling it from an ISR.

Below is my throw at Timer1.cpp. Note that port and bit could be
made private data of the class, and the pin number could be a parameter
to the begin() method.
#include "Arduino.h"
#include "Timer1.h"

/* The three constants below can be tuned to taste:  */

const float frequency    = 10;  // hertz
const float opening_time = 25;  // milliseconds
const int   pin          = 13;

/* Nothing should need to change below this line. */

const uint16_t prescaler = 256;
const float f_timer = float(F_CPU) / prescaler;
static volatile uint8_t *port;
static uint8_t bit;

void Timer1::begin() {
    // Prepare the output.
    port = portOutputRegister(digitalPinToPort(pin));
    bit = digitalPinToBitMask(pin);
    pinMode(pin, OUTPUT);

    // Configure Timer 1.
    TCCR1A = 0;  // undo the configuration done by...
    TCCR1B = 0;  // ...the Arduino core library
    TCNT1  = 0;  // reset counter
    OCR1A  = round(f_timer / frequency) - 1;
    OCR1B  = round(f_timer * opening_time * 1e-3) - 1;
    TIMSK1 = _BV(OCIE1A)   // enable TIMER1_COMPA interrupt
           | _BV(OCIE1B);  // enable TIMER1_COMPB interrupt
    TCCR1B = _BV(WGM12)    // CTC mode
           | _BV(CS12);    // prescaler = 256
}

ISR(TIMER1_COMPA_vect) {
    *port |= bit;
}

ISR(TIMER1_COMPB_vect) {
    *port &= ~bit;
}

Thanks for all the helpful comments and suggestions! I will definitely use some of your tips. Some of the other things you pointed out, were as a result of trying to reduce a code down enough to show the problem and exclude the portions that I felt didn't relate to the question. In the end, I want the user to be able to change the frequency/period, the reason for which the Arduino will need to calculate the values.

I mean to say that the user will change the values while the Arduino is running via Serial.

What about setting the TCCR1B starts the counting? Is it the enabling of the CTC mode, or the setting of the prescaler?

@SebastianFreeman: It's the prescaler. When the three CS1x bits are set to zero (which happens when you clear TCCR1B), the timer stops counting. It starts again when you change any of these three bits.

I believe you should be able to put your code back into the constructor if you move all the variable you defined with file scope in Timer1.cpp:
float frequency = 10.0;
float period_ms;
float clock_pulse = 16.0;

unsigned long opening_time = 25000;

unsigned int ocr1a;
unsigned int ocr1b;

...to the Timer1 class definition (either in the public or private section).  This way all the variables will have the scope of the class and the code should work the same regardless where in the class it is.


text:
Convert INT to Array of Strings
My sensor outputs an int. I would like this to be an array of strings so I can send it with my 433MHz transmitter.
Converting an int to a string to an array of strings seems to be extremely complicated. I've tried multiple approaches.
The error is always:

array must be initialized with a brace-enclosed initializer

#include <VirtualWire.h>

const int led_pin = 11;
const int transmit_pin = 12;
const int receive_pin = 2;
const int transmit_en_pin = 3;
int mostureSensor = 0;

void setup()
{
  // Initialise the IO and ISR
  vw_set_tx_pin(transmit_pin);
  vw_set_rx_pin(receive_pin);
  vw_set_ptt_pin(transmit_en_pin);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(1000);   // Bits per sec
}

byte count = 1;

void loop()
{
  // read the input on analog pin 0:
  String sensorValue = String(analogRead(mostureSensor));

  char charBuf[7];
  char msg[7] = sensorValue.toCharArray(charBuf, 7);

  //char msg[7] = {'h','a','l','l','o',' ','#'};
  Serial.println("sending");
  msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msg, 7);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  delay(1000);
  count = count + 1;
}

toCharArray is a method. It will copy the value from SensorValur to charBuff, it won't return the char array.
Line:
 char msg[7] = sensorValue.toCharArray(charBuf, 7);

Should be:
 sensorValue.toCharArray(charBuf, 7);

charBuf will already have the sensorValue copied.
Check more about "toCharArray" method :
https://www.arduino.cc/en/Reference/StringToCharArray


text:
ESP8266 cannot handle struct
The following code works on a range of Arduino's but not on ESP. It returns random data for ID and Pin. The other two fields are always empty.
I use the Arduino IDE for both the ESP and the Arduino's. It looks like the ESP has it's own idea when it comes to struct.
#include <RH_ASK.h>
#include <SPI.h>

#define BAUD 2000
#define RX 2
#define TX 5

RH_ASK driver(BAUD, RX, TX);

struct data {
  int id;
  int pin;
  int value1;
  int value2;
} myData;

void setup()
{
    Serial.begin(9600);
    Serial.println("Starting..");
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);

    if (driver.recv(buf, &buflen)) {

      memcpy(&myData, buf, buflen);

      Serial.print("ID: ");
      Serial.println(myData.id);

      Serial.print("Pin: ");
      Serial.println(myData.pin);

      Serial.print("Value1: ");
      Serial.println(myData.value1);

      Serial.print("Value2: ");
      Serial.println(myData.value2);

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

Bad Data
ID: 263145
Pin: 18350364
Value1: 0
Value2: 0

Should be
ID: 1001
Pin: 4
Value1: 267
Value2: 843

This looks like it's nothing to do with structs; this appears to be about the RadioHead packet radio library (which you never mention). When using a library you need to tell people what library you're using and give them an idea of what you're trying to do. I would also guess that you have some sort of hardware hooked up to pins 2 and 5 on the Arduino that you're keeping secret from us to make the question harder to answer.

try short int instead of int in the struct (looks like int's are 32bit in esp8266 and 16bit in arduino boards? perhaps? - For portability use uint16_t and int16_t for ints - https://github.com/mysensors/MySensors/issues/223

note: 263145 = 1001 + 4 * 65536

Awesome! You are my hero, I will dress like you when I go to comic-con Jaromanda X

Curt J. Sampson, thank you for your feedback, I will improve my questioning next time!

@Thijs - note: I seriously do look like Glen Quagmire :p

@Thijs - to be honest, there's nothing wrong with the question, the issue had nothing to do with the RadioHead packet radio library, nor anything to do with what's connected on pins 2 and 5 - in fact, that sort of information would distract from the actual problem as it is irrelevant to your problem.

The issue is that Arduino boards (8 bit ones at least), an int is 16 bits, where as the ESP's (8266 and 32) and possibly other non-arduino hardware, an int is 32bits
The safest way to declare structs in any case is to use variable types with known sizes, in your case, for signed 16bit ints
struct data {
  int16_t id;
  int16_t pin;
  int16_t value1;
  int16_t value2;
} myData;

or for unsigned 16bit ints
struct data {
  uint16_t id;
  uint16_t pin;
  uint16_t value1;
  uint16_t value2;
} myData;

Note: there's also short int which I believe is "guaranteed" to be 16bit (and "long int" is always 32 bit) - but having the bit size in the declaration is a far better (future proof) solution


text:
Arduino ESP8266 Webserver
What I would like to do is control my garden lights using the ESP8266. For this I use the Arduino approach from here. This works great, I use bootstrap and jquery even :D all is well!
Switching lights on and off using my code is fine but now I'd like to switch some continues routines, like blinking. I can start the blinking from the webpage but this code is a loop so I cannot get back to turn it  off again.
I could make it blink for a set amount of loops, so eventually it will stop blinking and show the control webpage again.
Or I can add the blinking to the hardware, maybe use a 555 for the first time?
But there might be a better way of implementing this..
Using Google I found information about Break and Interrupts, not yet what I am looking for.
#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char *ssid = "mynetwork";
const char *password = "mypassword";

ESP8266WebServer server ( 80 );

const int led = 5;
String webPage =
"<!DOCTYPE html>\
\
\
  <title>Funny Bunny Control</title>\
  <meta charset='utf-8'>\
  <meta name='viewport' content='width=device-width, initial-scale=1'>\
  <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>\
  \
  \
\
\

\

\

Funny Bunny v0.1
\

\

Omdat snuffelen er bij hoort.
\

Niet voeren aub.
\

\

aan
\

uit
\

\

\
\
";

void handleRoot() {
  server.send(200, "text/html", webPage);
}

void aan() {
  digitalWrite ( led, 1 );
  server.send(200, "text/html", webPage);
}

void uit() {
  digitalWrite ( led, 0 );
  server.send(200, "text/html", webPage);
}

void setup ( void ) {
  pinMode ( led, OUTPUT );
  digitalWrite ( led, 0 );
  Serial.begin ( 115200 );
  WiFi.begin ( ssid, password );
  Serial.println ( "" );

  // Wait for connection
  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  Serial.println ( "" );
  Serial.print ( "Connected to " );
  Serial.println ( ssid );
  Serial.print ( "IP address: " );
  Serial.println ( WiFi.localIP() );

  if ( MDNS.begin ( "esp8266" ) ) {
    Serial.println ( "MDNS responder started" );
  }

  server.on ( "/", handleRoot );
  server.on ( "/aan", aan );
  server.on ( "/uit", uit );
  server.onNotFound ( handleRoot );
  server.begin();
  Serial.println ( "HTTP server started" );
}

void loop ( void ) {
  server.handleClient();
}

Take a look at the SimpleTimer [http://playground.arduino.cc/Code/SimpleTimer] library in the Arduino IDE environment.
You can have timers to:

call a function at a consistent interval,
call a function once after a set delay,
call a function a set number of times with a consistent interval
between.

Looks great! It works fine but I cannot get the timer to stop, I can name the time and disable it I guess but the documentation does not show how to type the variable that holds the timer. something like this? int blinky = timer.setInterval(1000, RepeatTask);

The type of the timerId is int. You could call timer.disable(blinky); to turn off one repeating timer.


text:
Arduino mini pro as ISP for Atmega329P-PU serial monitor failing
After trying a lot of tutorials and manuals around the web including at least 20 solutions here on StackExchange, I don't know what to try anymore.
My goal is to write a message in the serial monitor window of the Arduino IDE from my ATMEGA328P-PU.

I have written the Arduino bootloader (tried 8 and 16MHz) to the ATMEGA and I use a 'blink' sketch as follows:
void setup()  {
 Serial.begin(9600);
 delay(100);
 pinMode(9, OUTPUT);
}

void loop()
{
 digitalWrite(9, HIGH);
 Serial.print("high");
 delay(1000);
 digitalWrite(9, LOW);
 Serial.print("low");
 delay(1000);
}

The blinking works fine, the timing looks good, not overly fast or slow.
I connect PIN3 (PCINT17, PD1, TXD) directly to the RX on the Arduino (lower red wire) and the serial monitor responds by returning nonsense like ����������.
I have checked the baud rate. I have also tested with all other baud rates in combination with and without 8Mhz and 16MHz.
I have tested the entire setup with another ATMEGA328P-PU and using an entirely other PC. Same results.
It is not possible to upload a sketch while leaving the TXD -> RX connected, so I disconnect this cable when I upload a sketch. I have also tested with only power and TXD -> RX connected.
I have also tried a few types of resistor between the TXD and RX, one of many tutorials recommended this.
This is what I am trying:
http://www.instructables.com/id/Attiny-serial-monitor-using-arduino-walkthrough/
And this is my boards.txt:
##############################################################

atmega328bb.name=ATmega328 (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=16000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard

atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdude

The problem is most likely that big white component. Yes, that one. The breadboard. It has huge parasitic capacitance and will be affecting the frequency of your crystal oscillations, thus skewing your baud rate enough to break communication.

I have tried without external oscillator..

So you have arduino pro mini as ISP and you've connected TX pin from mega328p to pro mini RX input (which is also connected to USB->Serial TX pin). And you wonder why it returns junk data from pro mini Tx pin?

Speaking of capacitance, I don't see any decoupling on that ATMega328 chip...

yes I wonder why it returns this, that is why I post a question here.

Well, you have Arduino ISP on that arduino mini pro and if you connect output of bare chip to input of that arduino then Arduino ISP is confused and sends (possibly) some responses to its RXO pin (connected to TX Input on USB-Serial board).

Is ArduinoISP not supposed to forward this information to the Arduino IDE? How else would I read serial messages from the bare chip?

I don't think so. Even if it does, it's possibly running at much higher baud rate. And if there are no resistors on that USB-Serial you have shorted two outputs.

As you can see at image from linked instructables, they've connected TX pin from Tiny to TX pin on UNO through 220R resistor. This is extremely lousy idea as UNO and Tiny are both driving TX pins.
On the other side you've connected TX Output pin from Target CPU into RX Input of the Arduino ISP (pro mini). Arduino ISP returns some error responses from its TXO pin directly into the monitor. And it's at different speed I suppose, as default baud rate is 19200 in Arduino ISP sketch.
Also using internal 8MHz oscillator and: atmega328bb.build.f_cpu=16000000L means you are running at half speed as compiler and everything else expects. All speeds will be at half rate. Delays twice as long and so on.
Anyway, you can disconnect your USB to Serial converter and connect it directly to the target CPU. Or use two of them. Or just upload bootloader and get rid of ISP.

great, just wiring the FTDI to the ATMEGA gives me normal serial monitor response. it does leave me with another challenge, uploading sketches does not work.

The thing is that you have 2 ATmegas for 1 uploader. You can't really remove the ATmega on the Pro Mini so I suggest removing the ATmega of an UNO and using the UNO without the ATmega to program your seperate ATmega. Tx to Rx and vice versa. 16MHz will work.

No change of boards is needed, it is only necessary to hold the on-board ATmega in reset, and bring the raw DTR or RTS line over to a copy of the reset circuit for the target one.  However, if loading anything that uses SPI or toggles those pins it would generally be good to make sure the ISP (SPI) lines are disconnected between the two, to make sure the slave doesn't accidentally deprogram the on-board ATmega (seen that happen!)

So how's my anwser?

Not very good, as you are proposing that an unnecessary purchase of different hardware be made.


text:
Arduino Nano BME280 weird values
My goal is to measure temperature, pressure and humidity using my Arduino Nano and the BME280 (GY-BME/P280).

To do this I use this library from SparkFun and that works almost. What I notice is probably invalid values for temperature and no humidity values at all.
The PINs:

GND -> GND
VCC -> 3.3V
SDO -> D12
CSB -> D10
SDA -> D11
SCL -> D13

I have noticed that I can unplug the VCC pin, it makes to difference to the measurements. I find that odd.
And I have noticed that the results are the same for 5V to VCC.
This is the result, I have tested this with I2C and SPI, it's the same:
Program Started
Starting BME280.Program Started
Starting BME280... result of .begin(): 0x58
Displaying ID, reset and ctrl regs
ID(0xD0): 0x58
Reset register(0xE0): 0x0
ctrl_meas(0xF4): 0x27
ctrl_hum(0xF2): 0x0

Displaying all regs
0x80:9A 70 90 28 92 2D AF 00 76 6F 7D 67 32 00 93 8C
0x90:C1 D6 D0 0B CF 18 AD FF F9 FF 8C 3C F8 C6 70 17
0xA0:00 45 82 00 00 00 00 00 00 00 00 00 33 00 00 C0
0xB0:00 54 00 00 00 00 60 02 00 01 FF 82 13 4E 08 00
0xC0:00 87 27 FF 00 00 00 00 00 00 00 00 00 00 00 00
0xD0:58 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0xE0:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0xF0:00 00 00 0C 27 00 00 58 DD 00 82 72 00 00 00 00

Displaying concatenated calibration words
dig_T1, uint16: 28534
dig_T2, int16: 26493
dig_T3, int16: 50
dig_P1, uint16: 35987
dig_P2, int16: -10559
dig_P3, int16: 3024
dig_P4, int16: 6351
dig_P5, int16: -83
dig_P6, int16: -7
dig_P7, int16: 15500
dig_P8, int16: -14600
dig_P9, int16: 6000
dig_H1, uint8: 69
dig_H2, int16: 0
dig_H3, uint8: 0
dig_H4, int16: 0
dig_H5, int16: 0
dig_H6, uint8: 0

Temperature: 24.59 degrees C
Temperature: 76.26 degrees F
Pressure: 101121.63 Pa
Altitude: 18.25m
Altitude: 59.87ft
%RH: 0.00 %

My script is almost exactly like the example from the library.
/******************************************************************************
I2C_ReadAllData.ino
BME280 Arduino and Teensy example
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/SparkFun_BME280_Arduino_Library

This sketch configures the BME280 to read all measurements.  The sketch also
displays the BME280's physical memory and what the driver perceives the
calibration words to be.

Resources:
Uses Wire.h for I2C operation
Uses SPI.h for SPI operation

Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23

This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/

#include <stdint.h>
#include "SparkFunBME280.h"
//Library allows either I2C or SPI, so include both.
#include "Wire.h"
#include "SPI.h"

//Global sensor object
BME280 mySensor;

void setup()
{
  //***Driver settings********************************//
  //commInterface can be I2C_MODE or SPI_MODE
  //specify chipSelectPin using arduino pin names
  //specify I2C address.  Can be 0x77(default) or 0x76

  //For I2C, enable the following and disable the SPI section
  //mySensor.settings.commInterface = I2C_MODE;
  //mySensor.settings.I2CAddress = 0x76;

  //For SPI enable the following and dissable the I2C section
  mySensor.settings.commInterface = SPI_MODE;
  mySensor.settings.chipSelectPin = 10;

  //***Operation settings*****************************//

  //renMode can be:
  //  0, Sleep mode
  //  1 or 2, Forced mode
  //  3, Normal mode
  mySensor.settings.runMode = 3; //Normal mode

  //tStandby can be:
  //  0, 0.5ms
  //  1, 62.5ms
  //  2, 125ms
  //  3, 250ms
  //  4, 500ms
  //  5, 1000ms
  //  6, 10ms
  //  7, 20ms
  mySensor.settings.tStandby = 0;

  //filter can be off or number of FIR coefficients to use:
  //  0, filter off
  //  1, coefficients = 2
  //  2, coefficients = 4
  //  3, coefficients = 8
  //  4, coefficients = 16
  mySensor.settings.filter = 0;

  //tempOverSample can be:
  //  0, skipped
  //  1 through 5, oversampling *1, *2, *4, *8, *16 respectively
  mySensor.settings.tempOverSample = 1;

  //pressOverSample can be:
  //  0, skipped
  //  1 through 5, oversampling *1, *2, *4, *8, *16 respectively
    mySensor.settings.pressOverSample = 1;

  //humidOverSample can be:
  //  0, skipped
  //  1 through 5, oversampling *1, *2, *4, *8, *16 respectively
  mySensor.settings.humidOverSample = 1;

  Serial.begin(57600);
  Serial.print("Program Started\n");
  Serial.print("Starting BME280... result of .begin(): 0x");

  //Calling .begin() causes the settings to be loaded
  delay(10);  //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
  Serial.println(mySensor.begin(), HEX);

  Serial.print("Displaying ID, reset and ctrl regs\n");

  Serial.print("ID(0xD0): 0x");
  Serial.println(mySensor.readRegister(BME280_CHIP_ID_REG), HEX);
  Serial.print("Reset register(0xE0): 0x");
  Serial.println(mySensor.readRegister(BME280_RST_REG), HEX);
  Serial.print("ctrl_meas(0xF4): 0x");
  Serial.println(mySensor.readRegister(BME280_CTRL_MEAS_REG), HEX);
  Serial.print("ctrl_hum(0xF2): 0x");
  Serial.println(mySensor.readRegister(BME280_CTRL_HUMIDITY_REG), HEX);

  Serial.print("\n\n");

  Serial.print("Displaying all regs\n");
  uint8_t memCounter = 0x80;
  uint8_t tempReadData;
  for(int rowi = 8; rowi < 16; rowi++ )
  {
    Serial.print("0x");
    Serial.print(rowi, HEX);
    Serial.print("0:");
    for(int coli = 0; coli < 16; coli++ )
    {
      tempReadData = mySensor.readRegister(memCounter);
      Serial.print((tempReadData >> 4) & 0x0F, HEX);//Print first hex nibble
      Serial.print(tempReadData & 0x0F, HEX);//Print second hex nibble
      Serial.print(" ");
      memCounter++;
    }
    Serial.print("\n");
  }

  Serial.print("\n\n");

  Serial.print("Displaying concatenated calibration words\n");
  Serial.print("dig_T1, uint16: ");
  Serial.println(mySensor.calibration.dig_T1);
  Serial.print("dig_T2, int16: ");
  Serial.println(mySensor.calibration.dig_T2);
  Serial.print("dig_T3, int16: ");
  Serial.println(mySensor.calibration.dig_T3);

  Serial.print("dig_P1, uint16: ");
  Serial.println(mySensor.calibration.dig_P1);
  Serial.print("dig_P2, int16: ");
  Serial.println(mySensor.calibration.dig_P2);
  Serial.print("dig_P3, int16: ");
  Serial.println(mySensor.calibration.dig_P3);
  Serial.print("dig_P4, int16: ");
  Serial.println(mySensor.calibration.dig_P4);
  Serial.print("dig_P5, int16: ");
  Serial.println(mySensor.calibration.dig_P5);
  Serial.print("dig_P6, int16: ");
  Serial.println(mySensor.calibration.dig_P6);
  Serial.print("dig_P7, int16: ");
  Serial.println(mySensor.calibration.dig_P7);
  Serial.print("dig_P8, int16: ");
  Serial.println(mySensor.calibration.dig_P8);
  Serial.print("dig_P9, int16: ");
  Serial.println(mySensor.calibration.dig_P9);

  Serial.print("dig_H1, uint8: ");
  Serial.println(mySensor.calibration.dig_H1);
  Serial.print("dig_H2, int16: ");
  Serial.println(mySensor.calibration.dig_H2);
  Serial.print("dig_H3, uint8: ");
  Serial.println(mySensor.calibration.dig_H3);
  Serial.print("dig_H4, int16: ");
  Serial.println(mySensor.calibration.dig_H4);
  Serial.print("dig_H5, int16: ");
  Serial.println(mySensor.calibration.dig_H5);
  Serial.print("dig_H6, uint8: ");
  Serial.println(mySensor.calibration.dig_H6);

  Serial.println();
}

void loop()
{
  //Each loop, take a reading.
  //Start with temperature, as that data is needed for accurate compensation.
  //Reading the temperature updates the compensators of the other functions
  //in the background.

  Serial.print("Temperature: ");
  Serial.print(mySensor.readTempC(), 2);
  Serial.println(" degrees C");

  Serial.print("Temperature: ");
  Serial.print(mySensor.readTempF(), 2);
  Serial.println(" degrees F");

  Serial.print("Pressure: ");
  Serial.print(mySensor.readFloatPressure(), 2);
  Serial.println(" Pa");

  Serial.print("Altitude: ");
  Serial.print(mySensor.readFloatAltitudeMeters(), 2);
  Serial.println("m");

  Serial.print("Altitude: ");
  Serial.print(mySensor.readFloatAltitudeFeet(), 2);
  Serial.println("ft");

  Serial.print("%RH: ");
  Serial.print(mySensor.readFloatHumidity(), 2);
  Serial.println(" %");

  Serial.println();

  delay(10000);

}

Are you connecting via I2C?  If so have you got two 4.7K resistors between SCL and VCC and SDA and VCC?

Thank you for your reply, I have placed these but it does not change the sensor behavior. There are still zero's for dig_H2 trough dig_H6 and I think there should be some value, by comparing it using Google...

The Arduino Nano is a 5V Arduino board, and the BME280 is a 3.3V sensor. You may not apply 5V signals to it. It might already be damaged, you have to buy a new sensor. I have tried the Adafruit library and the finitespace library, and chose the finitespace library: https://github.com/finitespace/BME280 I have not yet tried the Sparkfun library.

The photo of the board shows that it is for BM E/P 280. It can take either the BME280 chip which does temperature, pressure and humidity, or the BMP280 chip which only does temperature and pressure.
The Register 0xD0 contains an ID which has a value of 0x60 for the BME280 and 0x58 for the BMP280.
Your output shows the ID as 0x58 which means you have a BMP280 temperature pressure chip.
I have been sold one of these, claiming to be a BME280 chip. I shall be asking for a refund.

Welcome to Asrrduino SE.  Be sure to take the tour at https:/arduino.stackexchange.com/Tour - and earn a badge in the process.

From my experience 0x58 means BMP280, I haven't found anything else than this thread claiming that 0x58 means BMP260

I'm after getting a batch of these myself...
I can't get it working with the Adafruit libraries, but it will work with the SparkFun Ones
To get data... the wiring is, well, nonstandard.
I can't get it to work in SPI mode, but it will work in I2C mode
I'm using an Arduino mega so the pin layout is different from an uno.
Pin no|Label|Arduino pin
Pin 1 |VCC  |3.3V
Pin 2 |GND  |GND/Ground
Pin 3 |SCL  | The SCL pin, on a mega its digital 21
Pin 4 |SCA  | The SCA pin, on a mega its digital 20
Pin 5 |CSB  |Do not connect
Pin 6 |SDO  |3.3V
Weird as it sounds, it needs to be connected to power on 2 separate pins

The breakout board photo shows that it is not the original BOSCH BME280 sensor. The dimensions are off. The original is square. This is how it should look like.

You're correct. It's the BMP280.


text:
TLS Client ESP8266
My ESP8266 collects data and sends it to a webserver over HTTP. I would like to use TLS for this but I cannot figure out how to get ESP8266 running on the Arduino framework to use this.
My curent code is based on ESP8266HTTPClient and when searching the ESP8266 pages on GitHub 50% of the information tells me that it's impossible to use HTTPS and the other half of the info tells me it's possible but not documented with WiFiClientSecure but that looks like a whole different way of communicating HTTP..
Link: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h
void senddata() {
  String testdata = "{\"tickle\": {\"id\": " + String (package.id) + ",\"value1\": " + String (package.value1) + ",\"value2\": " + String (package.value2) + "}}";
  Serial.println("Starting the journey to Salador..");
  http.begin("https://myserver/_db/Salador/upload");
  http.addHeader("Content-Type", "application/json");
  int httpCode = http.POST(testdata);
  if(httpCode > 0) {
      Serial.println("[HTTP] POST... code: ");
      Serial.println(httpCode);

  }
  else {
      Serial.println("[HTTP] POST... failed, error: ");
      Serial.println(http.errorToString(httpCode));
  }
  http.end();
}

I don't think you can easily mix the HTTP wrapper and the WiFiClientSecure. At the moment if you want to do HTTPS you have to do the HTTP portion of the transaction manually by sending the individual headers and then the body, then parsing the response yourself.
It's not that hard, and the example you point to shows you how it can be done - print the headers and body to the client, then read the data back looking for specific things (like a blank line to separate headers from body, etc).

Although: I do see this clue in the BasicHttpClient.ino example:
// configure traged server and url
//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS

So maybe if you know the fingerprint of your HTTPS server you can connect directly with HTTPS. How you get that fingerprint though is not something I know yet.

I can get the fingerprint from my browser and will try just adding it to the http.begin()

you have to hard-code the cert info for each domain. it's a PITA to manage if you get new certs, and it's hard to OTA if the trusted server goes down. not all certs fit; 2k is the known max, though depending on the sketch and ram, some 4k ones work as well.

Sounds like it's better to relay through something like a Pi or use a Yun.


text:
RadioHead and DallasTemperature error
The RadioHead library only runs on a very old core for the ATtiny85.
It sends data but I would like to send something useful. The problem is I cannot read any sensors using this core. And on any other core the RadioHead library fails.
RadioHead library
ATtiny core
An old post in the Arduino forum, probably the same issue.
I would like to know what is in the DallasTemperature that conflicts with RadioHead making the code to hang.
The problem appears when I add DallasTemperature sensors(&oneWire); to the code.
// RadioHead ASK
#include <RH_ASK.h>

// DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS PB0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// Sleep
#include <avr/sleep.h>
#include <avr/wdt.h>

#ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

// Absolute reference PB to overcome inter-IDE issues
#define T_PIN PB1 // transmission
#define L_PIN PB3 // optional LED pin
#define BAUD 2000

// Baud rate, receiver, transmitter
RH_ASK driver(BAUD, 9, T_PIN); // pin 9 is non existent

// the Tickle structure, what a name, ugh
struct tickle {
  uint16_t id;
  uint16_t value1;
  uint16_t value2;
};

// Watchdog
volatile boolean f_wdt = 1;

ISR(WDT_vect) {
  f_wdt=1;
}

// Sleep
void system_sleep() {
  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();

  sleep_mode();                        // System sleeps here

  sleep_disable();                     // System continues execution here when watchdog timed out
  sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
}

// Setup for Watchdog
void setup_watchdog(int ii) {
  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;

  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}

// With set_watchdog at 8 (4 sec.) we cycle from 0 to 14
// This timer is not precise
void minute_sleep(int ms) {
  for (int c = 0; c < ms; c++) {
    for (int i = 0; i < 15; i++) {
      system_sleep();
    }
  }
}

void setup() {
  // Debugging, if this takes less than a second, check fuses (core)
  if (!driver.init()){
    pinMode(L_PIN, OUTPUT);
    digitalWrite(L_PIN, HIGH);
    delay(500);
    digitalWrite(L_PIN, LOW);
    delay(500);
  }
  setup_watchdog(8);
  sensors.begin();
}

void loop()
{
  if (f_wdt==1) {
    f_wdt=0;
    struct tickle package; // make a Tickle package

    package.id = 38; // hard-coded device ID
    package.value1 = analogRead(PB0); // any positive int up to 2^16
    package.value2 = analogRead(PB2); // any positive int up to 2^16

    // sending data
    driver.send((uint8_t *)&package, sizeof(package));
    driver.waitPacketSent(); // wait for it ~Barney
    minute_sleep(10); // tested: 10 was 10:30, I like
  }
}

I have experienced many issues when using RadioHead library on ATTiny85 together with the Arduino IDE. Your issue is not the Dallas temp sensor.
The problem lies in that RadioHead uses timer 0 on the ATTiny and changes the prescaler on the timer to match the baudrate you have requested for your tranciever. The change of prescaler changes the way Arduino IDE functions like delay()works since those also use timer 0. I believe your Dallas library depends on delay() to synchronize the signals on the 1-bus so there you have a conflict between the two libraries.
I solved this by rewriting the RadioHead RHASK files to allow for ATTiny85 timer 1 to be used instead. Here's my code. Although I use TinyHead instead of RadioHead, the change will be the same as TinyHead is a RadioHead clone.
The only change I made to RH_ASK.h is the code to define whether to use TIMER1 or not.
// Flag to indicate whether to use timer1 in attiny85.
#define RH_ASK_ATTINY_USE_TIMER1

The below changes goes into RH_ASK.cpp
First change. Update pre-scaler code and add the pre-scalers used by timer 1:
// Put these prescaler structs in PROGMEM, not on the stack
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) || (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)
#if defined(RH_ASK_ARDUINO_USE_TIMER2)
// Timer 2 has different prescalers
PROGMEM static const uint16_t prescalers[] = {0, 1, 8, 32, 64, 128, 256, 3333};
#else
  #if defined(RH_ASK_ATTINY_USE_TIMER1)
   PROGMEM static const uint16_t prescalers[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16834, 3333};
  #else
   PROGMEM static const uint16_t prescalers[] = {0, 1, 8, 64, 256, 1024, 3333};
  #endif
#endif

Second change. This code sets up the timer 1 and goes before the existing code for ATTINY timer0 in function RH_ASK::timerSetup(). please note the "... existing code" part. The existing code for setting up timer 0 goes between the #else and the #endif
#if defined(RH_ASK_ATTINY_USE_TIMER1)
#warning RH_ASK_ATTINY_USE_TIMER1 set.
   // figure out prescaler value and counter match value
   // REVISIT: does not correctly handle 1MHz clock speeds, only works with 8MHz clocks
   // At 1MHz clock, get 1/8 of the expected baud rate
   prescaler = timerCalc(_speed, (uint8_t)-1, &nticks);
   if (!prescaler)
       return; // fault

   TCCR1 = 0; // Stop the timer
   TCNT1 = 0; // Zero the timer
   GTCCR = _BV(PSR1);  // Reset the prescaler

   // Number of ticks to count before firing interrupt
   OCR1A = uint8_t(nticks);

   TCCR1 = _BV(CTC1); // Turn on CTC mode / Output Compare pins disconnected

   // convert prescaler index to TCCRnB prescaler bits CS00, CS01, CS02
   TCCR1 |= prescaler; // set CS00, CS01, CS02 (other bits not needed)

   // Set mask to fire interrupt when OCIE1A bit is set in TMSK
  #ifdef TIMSK0
   // ATtiny84
   TIMSK1 |= _BV(OCIE1A);
  #else
   // ATtiny85
   TIMSK |= _BV(OCIE1A);
  #endif
#else
#warning RH_ASK_ATTINY_USE_TIMER1 not set.
   // use timer 0 (default)
   // figure out prescaler value and counter match value
   // REVISIT: does not correctly handle 1MHz clock speeds, only works with 8MHz clocks
   // At 1MHz clock, get 1/8 of the expected baud rate
   prescaler = timerCalc(_speed, (uint8_t)-1, &nticks);

... existing code

   // ATtiny85
   TIMSK |= _BV(OCIE0A);
  #endif
#endif

Third change goes where the vectors are set up. Note the added #if defined for TIMER1 and the corresponding vector. Note also that the vector for timer0 is now called TIM0_COMPA_vect in later RadioHead/TinyHead but the names TIMx and TIMERx are interchangeable.
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO)
#if defined(RH_PLATFORM_ATTINY)
 #if defined(RH_ASK_ATTINY_USE_TIMER1)
  #define RH_ASK_TIMER_VECTOR TIMER1_COMPA_vect
 #else
  #define RH_ASK_TIMER_VECTOR TIMER0_COMPA_vect
 #endif
#else // Assume Arduino Uno (328p or similar)

Mind you that I have had other issues using the DallasTempSensor library. I'm not sure whether the issue is a low quality crystal in my ATTiny or not, but I get garbage readings from my sensor. The same code works flawlessly on my Arduino Nano, so I'm currently investigating whether my ATTiny is too far off in its timings to work properly with that library. I'm also going to try the OneWire protocol to see whether that one works better. However, the above code change resolved my issues with Arduino IDE and RadioHead/TinyHead.

This sounds great, I thought that the ATtiny85 only had a single timer.. the TinyHead is my light copy of RadioHead and I will test your code in a new version of this library as soon as possible!

Hi there, it has been a long time but I'm looking into this now. I cannot find any suitable place for you code to go. The #else suggests that more code will follow so it does not belong in timerSetup() in RK_ASK.cpp?

@Thjis, I have updated the code changes above. I hope it helps. The changes goes in RH_ASK.cpp with only the actual #define in RH_ASK.h.
BTW, I see the link to your GitHub was broken so I have updated the link to point to enisocha.

Thank you! I have moved to GitLab: https://gitlab.com/thijsvanulden/TinyHead and applied for a listing on the platformio library index. I will test your code, thank you for your input!! Also, my Dallas sensor works fine for me, I use DallasTemperature from the platformio library index.

I made the changes and TinyHead works fine with the Timer1, thank you for that. But the the Dallas library does break the radio transmission somehow. As soon as I call sensors.requestTemperatures() I can't send any radio transmission anymore.

I've been successfully using the OneWire library https://github.com/PaulStoffregen/OneWire. The upside is that it works for me but the downside is that you need to know what commands to send over the 1-wire and how to interpret the byte responses. I gave up on the DallasTempSensor library because I got unreliable readings on the ATTiny.


text:
Get Hash from Biometric Fingerprint Data for Encryption
I'm trying to get a reliable hash from a fingerprint scanner to use as a encryption key. According to this post here: https://crypto.stackexchange.com/questions/103693/can-you-restore-a-private-key-from-biometrics, this can be done using stored error-correction data.
Is there a way to obtain this hash from the Adafruit Fingerprint Scanner Library for Arduino (ESP32 S2), i.e. grabbing the biometric data after the correction code has been applied to use as a reliable hash, that follows the three conditions outlined in the post above:

With error-correction data stored and made available independently of the biometric, we get the desired reproducible private key (or identifier).
The combination of said error-correction data and private key is non-revealing of the biometric.
Knowledge of both the biometric data and the error-correction data is needed to regenerate the private key, or match either the biometric data or the error-correction data with the private key.

If this is not possible using the Adafruit Scanner Library and/or the Adafruit scanner, what should I use in order to do this?

duplicate of https://arduino.stackexchange.com/questions/97037/finding-data-from-adafruit-fingerprint-library-for-encryption-key

@jsotola my message before was asking if there is a general way to derive a key from a fingerprint, which I was told was not possible. I deleted that post because it wasn't specifically relevant to Arduino. In this post I am presenting a valid algorithm to derive a key from biometric fingerprint data, and asking for a specfic Arduino library/scanner (Arduino software & hardware) that has this capabilities. (Plus, the old message was deleted so it cannot be seen by others as a duplicate).


text:
Build fails on `plugin needed to handle lto object` when trying to combine two libraries with `dot_a_linkage=true`
The project structure is the following:
HID-Project Library -\
                      >---> Custom Library 2 -> project.ino
Custom Library 1 ----/

Both HID-Project Library and Custom Library 1 have dot_a_linkage=true.
When I try to build the project it fails on lto plugin.
Consumer.cpp.o: plugin needed to handle lto object

Command line building the project (I use Arduino IDE 2.3.3 on Windows) is the following:
"C:\\Users\\user\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc"
-Wall
-Wextra
-Os
-g
-flto
-fuse-linker-plugin
-Wl,--gc-sections
-mmcu=atmega32u4
-o
"C:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7/volume_control_and_pc_busy_simulator.ino.elf"
"C:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7\\sketch\\volume_control_and_pc_busy_simulator.ino.cpp.o"
"C:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7\\libraries\\HID-Project\\HID-Project.a"
"C:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7\\libraries\\HID\\HID.cpp.o"
"C:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7\\libraries\\support_library\\support_library.a"
"C:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7\\libraries\\peripherals_library\\peripherals_library.a"
"C:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7/..\\..\\cores\\arduino_avr_micro_bdb0ea67b0fdabd05f48f42cab13e7fd\\core.a"
"-LC:\\Users\\user\\AppData\\Local\\Temp\\arduino\\sketches\\D15174364F07792C498DDA13DC5F9CF7"
-lm

As soon as I comment out dot_a_linkage=true build succeeds.
Because my custom library depends on 3rd party library (HID-Project) I'd want to be able to fix build without changing it's properties.

and if you have dot_a_linkage only in the HID library?

@Juraj the same. Moreover I have an older version of the same project where all the code is in ino file and it stops working if dot_a_linkage is commented out in HID-Project.

yes the HID-project library doesn't work without dot_a_linkage because all global instances for different USB devices collide if they are all linked. with dot_a_linkage the linker only picks used instances from the .a file.

@Juraj Interesting fact. I simplified the hierarchy a bit. Now I have only one library but it still depends on HID-Project. Still having the same issue. As far as I understand -fuse-linker-plugin should be resolving it, but it doesn't seem to have any effect.

maybe something can be changed in Consumer.cpp