Altsoftserial serial library
- #Altsoftserial serial library generator
- #Altsoftserial serial library software
- #Altsoftserial serial library code
The actual use of the pins when the library is running is due to way the timer hardware is physically connected within the chip. The definitions in known_boards.h are merely for documentation, and for the library to configure the correct pins using pinMode (so receive becomes and input and transmit becomes an output).
#Altsoftserial serial library generator
Pin 9 is always transmit, because that is timer1's compare A waveform generator pin. On Uno, pin 8 is always receive, because that is the pin with timer1's input capture signal. If you are echoing the SmartMeter characters to Serial, be sure you have a higher baud rate on Serial.Do NOT change config/known_boards.h! (unless you're adding another board) In your case, using AltSoftSerial for the SmartMeter should work fine, and you can choose different baud rates. I had to use two Arduinos to fully test asynchronously (i.e., not synchronized). In developing the NeoSWSerial library, I have seen this manifest the same way. The character interrupts do not disturb the sending or receiving of the bits. If you just hook 0 to 1, I think it will work, because the UART is able to send and receive at the same time, and it deals with complete characters, not bits. Your loopback test makes it especially susceptible because the sending and receiving are synchronized (the initial receive interrupt occurs while the transmit interrupt is starting the next char). This manifests as receiving the wrong byte. When there are other interrupts in the system (millis() TIMER0 or Serial), the bit "calculations" can be affected.
#Altsoftserial serial library software
All the software serial libraries use interrupts for processing individual bits instead of one interrupt per character. I think what you've tried is probably working ok. It can transmit and receive at the same time (unlike SoftwareSerial), but it only works at bauds 9600, 1920. It's almost as efficient as AltSoftSerial, but it works on any two pins.
My NeoSWSerial library is another alternative. This can interfere with other parts of your sketch or other libraries. SoftwareSerial is very inefficient, because it disables interrupts for long periods of time. The baud rates must be the same on Serial and mySerial.Īnd you don't describe the connections, so I have to ask: Did you connect a wire from pin 1 ( Serial transmit) to pin 10 ( mySerial receive), and another wire from pin 0 ( Serial receive) to pin 11 ( mySerial transmit)? Note how they are crossed.ĪltSoftSerial is really the best choice, but it only works on pin 8 (RX) and pin 9 (TX), which would require connecting 8 to 1 and 9 to 0. Same as AltSoftSerial but keeps printing Ôë‹–+ë¡Ñ�j½½¹…j. NeoSWSerial with wires connecting 1-10 and 0-11. First prints Goodnight moon! and then it keeps printing Ô당¥�¡Ñ�moon!. It prints strange characters: Goodnight moon!ĪltSoftSerial with wires connecting 1-8 and 0-9.
SoftwareSerial with wires connecting pin 1 to pin 10 and pin 0 to pin 11. I tried all three options suggested by but none had the expected behaviour: I had no wiring, because the example specified "There is no circuit for this example". I would be grateful to anyone who could shed some light on this or offer an alternative way for me to read the data from my Smart Meter. Instead of Serial.write(mySerial.read()), store the result in a char first. Tried different RX and TX pins for SoftwareSerial. Tried a different SoftwareSerial library (AltSoftSerial). Change the baud rate for both software and hardware serial (9600 for instance). That which was written appears on the screen.īut whatever I try, nothing happens. The Software Serial reads this data and writes it back to Serial. Serial.read() reads this data and writes it to the Software Serial. set the data rate for the SoftwareSerial portĪs far as I understand this, the following should happen:
Open serial communications and wait for port to open: SoftwareSerial mySerial(10, 11) // RX, TX
#Altsoftserial serial library code
The example code is below, the example can be found here #include Problem is, I can't get the most basic example to work and I have been stuck on this for quite a while now. To become familiar with (software) serial communication on the Arduino, I reviewed the documentation of the SoftwareSerial library. I figured I would need to use the SoftwareSerial library to read the incoming data and print that data on my screen using the hardware serial and the Serial Monitor in the Arduino IDE. The meter uses serial communication and I would like to see the values being outputted on my laptop screen. I recently bought an Arduino UNO to read the data outputted by my Smart Meter.