Hot answers tagged

16

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 ...


14

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

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

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, ...


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

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....


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

Suppose one connected two of the Arduino Uno boards through Rx and Tx pins. I assume you will connect the TX of one Arduino to the RX of the other one and vice versa, which is the right way to connect them. As theSealion explained in his answer, you shouldn't connect two TX Pins together. if one or both of the Arduino boards were connected to computer, ...


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 ...


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

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

I am not aware of any such library. You could try to implement one yourself, and maybe share it with the community. :-) If you take this route, you will have to copy the file HardwareSerial.cpp from the Arduino core, make your changes there, and have your version replace the one from the core. Here are some ideas that may help to get you started: Wire the '...


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 ...


3

Every active chip should have adequate decoupling. That is the point of C3, to provide decoupling for the MCU. It is required. While you don't need capacitors on the output of a non-existent regulator you do need a reservoir capacitor on the power input to your board. 10uF should be adequate. No, you don't need the DTR capacitor if DTR is not connected to ...


3

Thanks all for your answers. I did some more research with the new info you provided and found my perfect solution: TCA9548A. That's a 1-to-8 port i2c multiplexer that will allow the master MEGA2560 to control up to 8 independent i2c buses, where I can connect my displays. The chip is dirt cheap here - 2 euro only, and it is available in the store. Thanks ...


3

The “UART” being referred to is the Nordic UART GATT Service. This is not a serial port or USB connection. It is a high level BLE protocol that simulates a serial port via the Bluetooth connection. In order to connect to the device from your Mac you’ll need to write some C or Obj-C. I’ve done this for Windows, but not a Mac, so I’m afraid I can’t give you ...


3

There are many, many problems with this code. The most fundamental flaw is that it uses linear buffers, where you should be using circular buffers instead. I'll come to this later. Now, if we look at the details, in the header file: #define Buf_OF 0x0200 This, and a few other macros, serve no purpose. Do not put "TODO" items in the code: put ...


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