8

You cannot use Serial inside an interrupt. Transmitting Serial relies on interrupts being available, and from inside an interrupt they aren't. All Serial communication must be done from loop(). So you need to just count the switch toggles and check to see if that value has changed in your loop. volatile uint32_t toggles = 0; uint32_t old_toggles = 0; ...


7

The short answer to your question is “yes, there is a way”. Multiple ways actually. You could write a blocking function, which follows more or less the logic of the example you show, blocking while waiting for each new byte. Or you could write a non blocking function, which always return immediately and, either gives you the complete packet, or tells you ...


5

I learned that I needed to include Arduino.h header file apart from that I learned .ino files and .cpp files is that the .ino files transparently include particle.h for you. The other difference is that .ino files generate forward declarations for you. This is necessary when you’ve implemented a function later in the file than when you’ve first used it. ...


4

Yes, with a small converter board it can be connected to an Arduino. The "9 pin serial cable" is very likely an RS-232 interface. RS-232 is like UART with a few extra connections. Here is what the cable looks like: Basically UART with flow control and other modem lines. Most likely it hasn't any of them conencted but that standard RXD, TXD and GND. These ...


3

The Arduino IDE's serial monitor is just one of many tools that can open a serial port and collect information from it. The first step is to make sure the data you are writing to the Serial object in the Arduino is in a format suitable for importing into Excel. Separate multiple values on one line with a comma "," or tab "\t" character. If you are running ...


3

Is it possible to print the debug statements in the Serial window while the GPS module is connected to the hardware serial ports? Yes, that works. If you connect the Arduino TX pin 1 to the GPS RX, then everything you print to Serial goes to both the Serial Monitor window and the GPS device. This works, because: It's ok if you see the GPS configuration ...


3

Your chief problem is that FastLED turns off interrupts when sending the data. It does that because timing is critical, and with interrupts turned on that timing will get completely messed up. So with FastLED running repeatedly in a loop there is very little time when interrupts are enabled for reception to occur over SoftwareSerial. Unlike a real UART, ...


3

SoftwareSerial only works on a few select GPIO pins on the Mega. Specifically those pins that have PCINT on them. But that is irrelevant. There is no reason to use SoftwareSerial on a Mega except in exceptional circumstances. You have four hardware UARTs on the Mega, so there is no call to use SoftwareSerial. Use the real UART pins and objects: Serial -&...


3

The line while (Serial.availableForWrite() <= 0) {} waits until the serial output buffer is not full. Whereas Serial.flush(); waits until the serial output buffer is empty.


3

The reference article, that you linked to, is about sending data over Serial, not about reading. You can use the strtok() function, which can split a character buffer into tokens based on a delimiting character (the comma in your case). First you have a buffer, where your Serial message in saved (I'm not covering the actual receiving/reading of the Serial ...


3

You are using Serial.println() to send the message. That function will add the combination \r\n as line ending to your message, which are the ASCII codes for return carriage and newline. In your receiving code, you read until \n, so your message now reads "0\r", which is of course not equal to "0". Thus the if condition will never trigger....


3

The AVR implementation of sscanf() does not support parsing floating point numbers, thus you only get zeros out of it. You can't use the %f specifier with it. You need to convert these numbers by yourself with functions like atof() or similar. Splitting a string into parts can be done many ways. You could use sscanf() to split up the string parts and then ...


2

You need to clean up the whole sketch. I will try to mention the most important things first. For an Arduino Uno, this sketch uses 520 bytes RAM and 1528 bytes are free to use for stack and heap. That seems enough but with heap fragmentation it might be a problem, see: Adafruit about an increasing heap The data_... Strings are only to display something. ...


2

This answer isn't going to give you the code to solve your problem, it is just ideas that you can look at and see what suits you best. You should be able to find an example on how to read from a serial connection, I'm sure there is at least one example in the IDE. You need to work out how to encode your data, having it in nice human friendly format (like ...


2

First, you could use a string for the commands. You just need to ensure there is some special char to mark the end of a command - like the newline char. Read the input from the port one char at a time, building the string as you go: char buffer[256]; uint16_t buffer_index = 0; void loop() { while (Serial.available()) { int c = Serial.read(); if ('\...


2

You could consider writing/reading the value to/from the EEPROM. http://arduino.cc/en/Reference/EEPROM This allows the board to be reset, or even turned off, and retain the value previously set. What you would be doing is saving the value to the internal memory of the Arduino. This is resettable and persistent over a "reboot". Granted, there is a ...


2

As Look Alterno wrote in a comment, you need to parse the incoming data on the receiving side. In this instance, you have to look for the line terminators. The Node.js serialport module provides a parser for this called Readline. Read that doc and use it.


2

First, you have to understand what “hex” means. Basically, you are representing binary data as text, where each byte is represented as two characters. For example, the number 42 is represented as either “2A” or “2a”. In C and C++, you can write this number as 0x2a, but I assume your serial stream sends the raw hex data, without the “0x” prefix. Thus, on the ...


2

It is an internal buffer and only the pointer gets increased. It it visible in the source code off the project, located on github: // Read data from buffer int SoftwareSerial::read() { if (!isListening()) return -1; // Empty buffer? if (_receive_buffer_head == _receive_buffer_tail) return -1; // Read from "head" uint8_t d = ...


2

Serial.print() feeds the data into the TX buffer one character at a time (through the Print class's inherited .write() function which HardwareSerial implements). If there isn't enough room in the TX buffer for the next character it waits for there to be room available. Characters are removed one at a time from the TX buffer and sent through the physical ...


2

You're thinking backwards. You don't want to read slower (which is what delay does), you want to only send every 10th entry. That is, count the lines as they come in. When you hit 10 you print one and reset your count. In other words: static int count = 0; if(newParoData == true){ count ++; if (count == 10) { count = 0; // (Why copy the ...


2

This is not a good tutorial. The receiver works by assuming 14 dotLen time periods for each character. There is a loop that runs 14 times, with a 200ms delay between each iteration. If the laser is detected, then a is incremented, otherwise f is incremented. This means that the sum of a and f is always 14, and the case where a==0 means nothing was ...


2

In all the examples below, value is the value of the byte LSB -> MSB - so 00001111 would turn ON the first 4 devices and turn OFF the last 4 for(int i = 0, mask = 1; i < 8; i++, mask = mask << 1) { if (value & mask) { // bit is on } else { // bit is off } } Alternatively, you can do the following, but ...


2

Read the values into an array big enough to store them Write the array with the write(const uint8_t *buffer, size_t size) method. Each write then gives you a block of binary data (512 values, 1024 bytes if they're 16-bit integers) written to the SD card. What you do with it then is up to you. Note: an Arduino UNO only has 2kB of memory. If you have 512 ...


2

Is it possible to program chips like the Arduino uno's Atmega328P directly with USB serial from your computer? The bare chip? Generally, no. Some chips that include USB hardware also may include a DFU bootloader in ROM. If your chosen chip has this, then yes you can - you just need to wire it up and use a suitable DFU firmware upload program to install ...


2

https://www.arduino.cc/reference/en/language/functions/communication/serial/availableforwrite/ availableForWrite Get the number of bytes (characters) available for writing in the serial buffer without blocking the write operation Write operations on Arduino streams wait if they can't write the data to output. You can use the count returned by ...


2

First, you got some logic wrong in the receiver: you have a test for Serial1.available()>=size_gyro and, when this is true, you read size_gyro + 9 bytes. You should change the test in order to only start reading when you actually have size_gyro+9 bytes available. Then, note that command_name is transmitted twice: first as part of the 9-byte preamble (...


2

You are not reading the GPS often enough. The method Adafruit_GPS::read() is documented in the comments embedded in the source code: Read one character from the GPS device. Call very frequently and multiple times per opportunity or the buffer may overflow if there are frequent NMEA sentences. An 82 character NMEA sentence 10 times per second will ...


Only top voted, non community-wiki answers of a minimum length are eligible