1

So, I am sending data to RP1 B+ model through UART from a microcontroller. I am using minicom to collect data and log it in a .txt file. I am sending around ~800 kB of data and using a baud rate of 1.15 mbps. The problem I am facing is that it takes a bit more than 4 minutes to collect and log all the data.

I tried to do the same using RP3 B+ model and apparently it seems like both RP 3B+ and RP 1B+ have mini UART and the normal (higher throughput UART). But when I am sending data to RP 3B+ through microcontroller, it just takes ~13 seconds at 1.15 mbps baud rate (To clarify, on my RP 3B+, for UART communication, I am using ttyAMA0 on serial 0 and I disabled Bluetooth). And I have configured RP 1B+ in the same way, ttyAMA0 on serial 0, but I don't get the same results (I have attached image of my /dev folder on RP1 B+ model).

I performed the steps as mentioned in (and this is the only tutorial I found for RP 1B+) https://www.abelectronics.co.uk/kb/article/1035/serial-port-setup-in-raspberry-pi-os for RP1 B+. Further, I also disabled the Bluetooth. It still takes too much time . I am not sure what is the problem with my RP 1B+ model.

I tried logging the data in different file formats, but looks like that doesn't matter, it always takes around same time to collect and log all the data.

Can anybody suggest me how to tackle the issue? Thanks!

UPDATE: I wrote the below script. When running this in RP B+, it takes ~9 minutes to log the data and when running in RP 3B+, it takes 1.5 minutes for the same. Any suggestion on how can I reduce the "9 minute" time?

import time
import serial

ser = serial.Serial(
        port='/dev/serial0',
        baudrate = 1152000,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
)

text_file = open("1.txt", 'w')
while True:
    if ser.inWaiting():
        x=ser.readline()
        text_file.write(x)
text_file.flush()

## close the serial connection and text file
text_file.close()
2
  • It is unclear what you have done. Don't expect anyone to read a 5 year old (probably obsolete) post and guess.
    – Milliways
    Commented Oct 30, 2021 at 6:48
  • I see no "image of my /dev folder" - and wouldn't have looked at it anyway. If you think it is significant include (as text) in your Question.
    – Milliways
    Commented Oct 30, 2021 at 7:06

3 Answers 3

1

See How do I make serial work on the Raspberry Pi3 or later

Do NOT use ttyAMA0 use /dev/serial0 for the default serial port on both.

There is no need to swap UART; I don't know upper speed limit of UART, but there should be no difference between the 2.

I regularly use ("/dev/serial0",115200) and even at this speed it shouldn't take 4 minutes.

The Pi Model B+ DOES NOT use the mini UART and does not have Bluetooth so this would not be the cause of any differences. Any delays are more likely caused by other factors e.g. slower clock speed of B+ or data transfer bottlenecks.

2
  • Thanks for the suggestion, yes instead of using minicom, I installed "Putty" application and there the data logged in around 1 min and 20 sec. So I have decided to write my own script to log the data and then I can test it because ultimately, I need a script for my application. Commented Nov 2, 2021 at 3:00
  • I have updated my question and added the script that I wrote. Can you help me regarding what would be causing too much time to log data on RP B+? Clock = 7MHz, RAM=512 MB, and RP B+ still lags no matter what I do, would that somehow be affecting the RP ? Commented Nov 2, 2021 at 5:59
1

This is completely normal to have different data transfer rates on different hardware for the same baudrate. The baudrate only defines the time it takes to transmit a bit within a byte. How much time it takes before the next byte can be transmitted is not known a priori.

It appears that the built-in UART on a B+ is quite slow. The obvious solution is not to use it in a project which needs fast data rates. Use a Pi 3 (which appears to work fine) or get a USB->UART converter with a fast data rate. I think FTDI would be a safe choice, though such converters are often expensive.

As a wild guess (I can't verify it if helps because I don't own a B+), try setting /sys/modules/8250/parameters/share_irqs to 0 and see if it improves the data rate.

0

Your edited Question is actually a different Question and not Pi specific it is a general programming question.

If I was doing this:-

  1. I would not use python
  2. If I was I would NOT check inWaiting, but specify timeout in Serial.
  3. Would NOT write line by line to file. I would buffer and only write at the end.
  4. If I knew rough size of file (e.g. 1MB max) I would read(1000000) and write the received buffer after timeout, or read/write in large chunks.
  5. I would use a more moderate standard baudrate NOT 1152000, but a factor of the 48Mb Pi serial clock.

NOTE I am only a casual python user, you should ask on StackOverflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.