Hot answers tagged

18

This answer lists the 4 basic choices: HardwareSerial, always the best. Simply use the pre-defined Serial variable. On some Arduinos, there are extra HardwareSerial ports, called Serial1, Serial2, etc. The Nano only has Serial. AltSoftSerial, the best of the software serial libraries. Only one instance is allowed, and it is must be used on one of the ...


13

The Arduino Nano cannot do 800 kb/s. As you can see in the source code, the bit duration is rounded to the nearest multiple of 8 CPU cycles. In your case, it is rounded to 3 × 8 CPU cycles, which yields a baud rate of 666.666 kb/s. That is 16% too slow, an error too large for any communication to be possible. At 400 kb/s ...


9

for length such as this, you should be using protocols that are designed for length, such as: UART, CAN, Ethernet for UART, you can't of course use a direct connection between the two boards, you need to upgrade the connection and wiring to either rs232 or rs485, using a driver between the arduino pins and the cable. Though, the simplest solution would be ...


6

Each spi peripheral has its own protocol in the sense of commands and addresses if any and data. Spi simply makes a common ground for chip select vs clocks and clocks vs data and separate miso and mosi data lines. So a general purpose library doesnt make sense. Also spi certainly is not limited to a byte, many peripherals and many spi controllers allow ...


6

I think the problem is not so much in the update speed, but in the fact that you loose accuracy in your calculation. The following lines are the culprit: int kphValue = 0; // [-32768:32767] int mphValue = 0; mphValue = kphValue * 0.621371; Make sure the calculation will be entirely in integers to prevent calculation errors: uint16_t kphValue = 0; // [0:...


6

Personally I wouldn't go down this route. Instead I would pass a Stream object (as a pointer or a reference) to the constructor and use that. Then it is up to your sketch to define what that Stream object is and initialize it. That way if you want to use the same class on a hardware UART instead of a SoftwareSerial you just change the sketch, not the ...


6

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 route data between the physical port and multiple virtual com ports. http://com0com.sourceforge.net/hub4com/ReadMe.txt


5

If you want to set the UART to 9-bit mode, you will have to set the UCSZ02 bit of the _ucsrb register to 1 in HardwareSerial::begin(). For example: void HardwareSerial::begin(unsigned long baud, byte config) { // Mostly unchanged... but by the end: sbi(*_ucsrb, RXCIE0); cbi(*_ucsrb, UDRIE0); sbi(*_ucsrb, UCSZ02); // set 9-bit data mode } Notice ...


5

AVRDUDE which is used by the IDE to send the content of HEX file from your computer, as a feature letting it to get back the data of the flash, in order to compare and see if data are correct. For a UNO try: avrdude -patmega328p -carduino -P/dev/cu.usbmodemFD121 -b115200 -U flash:r:"flash.bin":r I think it would not be very hard to change that for a Mega....


5

I think your problem is that you need 4 serial ports. With software serial that's just not going to happen: SoftwareSerial can only receive on one serial port at any given time. AltSoftSerial is limited to specific pins, and only one instance because there is only one set of pins NeoSWSerial is kind of between the two. More efficient than SoftwareSerial, ...


5

I tried the code from the link you posted and it worked: struct Gyro_data_structure { char command_name[6]; int gyro_X; int gyro_Y; int gyro_Z; }; struct Gyro_data_structure Gyro_data = {"Hello", 48, 49 , 50}; int size_gyro = sizeof(struct Gyro_data_structure); void setup() { Serial.begin(9600); // opens serial port, sets data rate to ...


5

High likely you are exceeding your character array, see: char a[5]; Which can hold 5 characters. However, you write: if(strcmp(a,"RGB_1") == 0) Which assumes you receive "RGB_1" which is 6 characters, because a string ends with a 0. What also might happen is that you indeed receive only 5 characters without the ending newline, which ...


5

You can have bidirectional communication over a single wire by using open-collector outputs. For this, you could add a circuit like this on each side of the link: simulate this circuit – Schematic created using CircuitLab Here, TX is the transmit pin of the Arduino, and DATA is the data wire. The RX pin is connected directly to the data wire and, ...


4

A very simple sketch to pass serial through looks like this: void setup(){ Serial1.begin(/*BAUD*/); Serial2.begin(/*BAUD*/); } void loop(){ if(Serial1.available()){ Serial2.print((char)Serial1.read()); } if(Serial2.available()){ Serial1.print((char)Serial2.read()); } } I would advise both run at the same baud rate, otherwise you may ...


4

The problem is in your loop() function. On each iteration, you will receive at most one character from the SoftwareSerial, while writing the same AT command again and again. As a result, your slave device (ie. ESP8266) will overflow its UART buffers, resulting in garbage being sent and received. You should keep receiving data from the slave for as long as ...


4

32u4 is multi-serial uC. USB connection works on default serial communication which can be used via Serial.print("somevalue"). On the other hand if you want to use RX/TX on pins 0, 1 which are actually RXD1 and TXD1. So, if you use Serial1.print("somevalue"). So the answer is a yes. You can use USB and RX/TX (hardware serial) at the same time.


4

If you give your board a name with WiFi.hostname("MyESP8266"); (for example) you can then look on your router in the section that lists DHCP assignments (on my Netgear it's Attached Devices). That should then show you the IP address of all the attached devices, including the ESP8266 which you will easily identify by its name. Another option is to use mDNS....


4

When in double-speed mode, as noted in the manual, fewer samples are used. In Asynchronous serial communication, there is no clock signal, so the clock that keeps the two devices in sync is extrapolated from the data signal. Each end of the communication has it's own clock source (crystal oscillator, ceramic resonator, R-C oscillator, etc.), and you'll ...


4

I ran a slightly modified version of your test code on a Mega 2560 and got no echo at all; Unless I totally misunderstood your problem description, there must be something else going on. Here's the code I ran: char test[15]; void setup() { Serial.begin(9600); Serial1.begin(115200); for (int i = 0; i < 15; i++) { //Serial.print(...


4

The first slaves will be plugged in and will send to the master his default address If this happens while the master is talking to one of the other slaves, you risk a collision. I suggest a very small variation on your scheme. Each slave has a default address (0xff). When you turn it on, it doesn't say anything. The slaves only talk when they are ...


4

There are two things wrong with the circuit in that demo. There is no decoupling capacitor on the power pins. This is required to keep the power stable during opertaion. More critically: this is being powered from 3.3V, but is being run at 16MHz. That is outside specifications. You should use an 8MHz crystal to operate at 3.3V.


3

uart::uart(void); That's a prototype, not a function. It needs a body. Also, using "void" to say "no parameters" is really confusing. Better to leave it out all together. uart::uart() { } uart.start(9600); uart.print("Hello world\n"); uart is a class, not an instance. You should be using uart::start(9600) if you first set your functions to be static, ...


3

The Due (more specifically the SAM3X) uses its own proprietary protocol. It's all embedded in the bootloader, which is hard wired in the ROM and can never be changed (idiotic if you ask me). I know of two systems for communicating with it. Atmel's SAM-BA program, and the open source BOSSA. The command line version of BOSSA (bossac) is used by the Arduino ...


3

try this: #import <Arduino.h> #include <OBD.h> int kphValue = 0; int rpmValue = 0; COBD obd; //array of character arrays, see http://arduino.cc/en/Reference/string const char* rpmStrings[] = { ",N,N,255,000,255,000", ",N,N,255,255,030,000", ",N,N,255,255,000,000" }; void ...


3

There is one connection missing - the one that powers the servo and board. At the moment your servo board is getting a small amount of power through the RX pin - disconnect it immediately, you are damaging it. You need to provide +5V to the +5V terminal block, and also a suitable voltage (+5V should do) to the VCC on the terminal block.


3

As we don't know what you are using as a terminal program we can't comment specifically on your choice of EOL characters. It is likely you are receiving everything in ASCII code. That is, when you type the number 1 you are actually getting the ASCII equivalent (0x31) from your terminal. This is fine when you are working with character strings. But when ...


3

Finally I made a breadboard connection joining ESP8266's GPIO 0 and GND to Programmer's GND for flashing the chip For more info Additional Reference: Programming ESP8266


3

If I understand your question correctly, you need to integrate this data into a .ino script. Probably as a byte array. Then the script can read the array and Serial.write its content. You could write a small tool in Python or else on your computer, that takes the text file and converts it into a .h header. Include that into your .ino script. Or use your ...


3

Serial.flush() only empties the output buffer, so that won't achieve anything. Reading exactly 9 bytes and hoping they match the input stream is not very effective, as you found. If you are out of sync with the incoming bytes, you will stay out of sync. It would be better to keep reading (single bytes) until you get 0xFF or 0x86 and then read the rest.


3

Bidirectional Asynchronous Serial schemes are not uncommon. The famous ones, like RS485, utilize special line drivers and differential signalling, but for short distances you can accomplish something similar using the ability of most MCU's, including the Arduino's ATmega, to tristate the serial transmit pin. Essentially, you would wire the shared line to ...


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