25
votes
Accepted
How do I convert a float into char*?
There is a function in the standard Arduino library called dtostrf(). I think of it as "Decimal to String Float". You pass in the float, how wide you want the whole number to be (if it will fit), the ...
25
votes
Using String instead of C string, yet another attempt to touch a loaded issue
It's not that String itself is evil, it's more that it's very easy to abuse it and cause heap fragmentation. Used judiciously it's fine and a useful tool. Used in "bad" ways and you open the ...
22
votes
How do I extract code from an arduino?
The short answer: You don't.
With enough know-how, you could probably extract the executable binary from the Arduino, but the source code is not installed on the device. You would need to run a ...
13
votes
How do I extract code from an arduino?
You never can get the actual code back ... by reading the flash you might be able to get the executable/runtime code, but this doesn't look at all similar as your code, although it's functionally the ...
11
votes
Accepted
how fast does loop() run in Arduino
Loop runs as long as loop needs to run.
Instructions in a CPU run sequentially. The more instructions there are the longer it takes to run.
The more code you put in loop the longer loop will run.
...
11
votes
How do I directly access a memory mapped register of AVR with C
It's worth exploring how PORTD is defined in the actual AVR header file. The relevant file is iom328p.h, and it's defined as:
#define PORTD _SFR_IO8(0x0B)
_SFR_IO8 is defined as
#define _SFR_IO8(...
9
votes
How do I extract code from an arduino?
You read the contents of flash and save it to a file. It can then be re-flashed if your need is not to edit, but duplicate.
This reads all flash, including the bootloader, and also PROGMEM data.
Use ...
8
votes
Accepted
Most memory efficient way to program
That is an incredibly hard question to give a definitive answer to.
In general using OO consumes more memory, but that is the price you pay for greater flexibility and ease of use. The difference is ...
8
votes
Binary message formatter
Passing messages across computers and/or microcontrollers with different architectures can be a real pain (endianness...). So do not fall into NIH / reinventing the wheel traps but keep standing on ...
8
votes
Accepted
Arduino port relocation (PORTD to PORTB)
You cannot set pin states in multiple ports simultaneously, if that's what you're asking.
At the instruction set level, setting pin states is a single that writes to an 8-bit register which ...
8
votes
Accepted
Print with round towards zero instead of round to nearest
A cheap trick to round a number to one decimal place (in "chop-off mode") is to multiply it by 10, convert it to an integer, and divide by 10.0f again:
float myVal = 123.89f;
myVal = (long)(myVal * ...
8
votes
Accepted
How to convert byte *payload to String
Depending on what is setting the message on the topic, payload may, or may not be, a NULL-terminated string. This is why they provide the length parameter.
You could consider comparing the data ...
8
votes
Using String instead of C string, yet another attempt to touch a loaded issue
The short answer is that fragmentation crashes are infrequent because they require very specific conditions to arise—and that's the problem.
Imagine you have a crash that occurs once every few days ...
6
votes
max7219 chained display showing mirrored text
Since version 3.0 MD_MAX72xx.h no longer supports that definition. Now the hardware type is defined as a parameter on creation (in the "Example" file you are using - not in MD_MAX72xx.h)
#define ...
6
votes
How can I concatenate multiple byte Arrays into one Array
You can concatenate with memcpy. You just need to set the pointer at the right place inside the c1 array.
memcpy(c1, a1, sizeof(a1));
memcpy(c1+sizeof(a1), a2, sizeof(a2));
memcpy(c1+sizeof(a1)+...
6
votes
Accepted
Max length of char arrays?
The main issue with your code is:
sizeof(s)
That doesn't return the string length - it returns the size of the char pointer - which is two bytes (on an 8-bit system, 4 on a 32-bit system).
Instead ...
6
votes
Accepted
How to compare a string
version using String (not recommended, but it makes simpler to understand the following C-string version)
#define LED 2
const char* a = "abcd";
void setup() {
Serial.begin(115200);
pinMode(LED, ...
6
votes
Accepted
Arduino wrap or subclass print() to work with multiple Serial
You can create a class derived from Print that forwards its output to
either or both Serial and Serial1. The only method you need to
implement for this to work is write(uint8_t):
class DualPrint : ...
6
votes
arithmetic operation outcome differs from the expected outcome
Once again an example to Why should I learn C/C++ first before learning Arduino.
The main point here is: know your data types.
Your calculation millisec*frequency/1000 would work if it was a compile ...
6
votes
How can I set up outputs without using digitalWrite?
digitalWrite() is just a convenience function to hide away complexity from the user, so that she/he can just use a pin number and a value. This complexity takes some time to execute. If this is too ...
6
votes
Accepted
Which Arduinos support ATOMIC_BLOCK?
This answer covers: Which Arduinos support ATOMIC_BLOCK? And how can I duplicate this concept in C with __attribute__((__cleanup__(func_to_call_when_x_exits_scope))) and in C++ with class constructors ...
6
votes
How to upload code without closing puTTY
There is an open source project that will do what you want.
http://com0com.sourceforge.net/
The com0com will create virtual com ports for the programs to connect to.
The hub4com will allow you to ...
6
votes
Accepted
How to write nonblocking code, for polling sensor at 100 Hz
should I be declaring last_ms as a global variable instead of
static?
Local static is better, as it limits the scope of the variable to just
where it is needed. Consider making it global only if the ...
6
votes
Accepted
How arduino PORTB pins are addressed if I want to access them with pointer?
The address of PORTB can be found in the ATmega328P datasheet,
section “I/O-Ports”, subsection “Register Description”. It is repeated
near the end of the section “Register Summary”, where it is ...
6
votes
Accepted
lcd.createChar() only allows for 8 custom characters
These displays only allow up to 8 custom defined characters. The hardware just only has the character RAM for at most 8 characters. They will be mapped to char codes 0 to 7 and 8 to 15. The character ...
5
votes
Peer to peer communication
Peer to Peer Example
Written by Stewart Meyer (engineer retired from the FAA).
This is first time that I have given an answer, hope you can read this:
Not only can the ESP8266 connect to a WiFi ...
5
votes
Basic makefile for avr-gcc
The accepted answer is great as it has given me a valuable lesson in all kinds of debugging tools (avr-objdump -D has become a close friend). Namely, the line:
${OBJCOPY} -O ihex -R .eeprom $< $@
...
5
votes
Accepted
AVR (Arduino Uno) Serial.print and Serial.println only printing 1 or 2 chars
You have two issues here:
The first is that you are using the Arduino core library and failed to
initialize it. This is done automatically if you rely on the core's
supplied main(), i.e. you stick ...
5
votes
Accepted
AVR timer overflow interrupt not working
You are misunderstanding what an overflow interrupt is. That is called when the timer overflows (ie. it reaches TOP which in the case of an 8-bit timer is 255). Since you are counting to 124 that will ...
5
votes
How to execute three functions at the same time?
You can implement three functions but you can't able to execute them same time.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
c × 430arduino-uno × 154
programming × 102
c++ × 84
arduino-ide × 42
arduino-mega × 30
serial × 26
esp8266 × 23
i2c × 23
avr × 23
arduino-nano × 18
string × 16
array × 16
sketch × 14
interrupt × 13
led × 11
library × 10
sensors × 9
atmega328 × 9
esp32 × 8
lcd × 8
arduino-due × 8
variables × 8
spi × 7
pointer × 7