A question about arduino mega?

hello
i'm not at all new to arduino
but i have a question , before i made a like 3 project by arduino uno but when the arduino read the temperature and reading serial port it became to slow, it wasn't function well
my question here is mega can run multiple sketch or task at the same time like
reading color sensor+reading ultrasonic distance sensor and more??
please replay
with my best regards :slight_smile:

zhirantaha:
hello
i'm not at all new to arduino
but i have a question , before i made a like 3 project by arduino uno but when the arduino read the temperature and reading serial port it became to slow, it wasn't function well
my question here is mega can run multiple sketch or task at the same time like
reading color sensor+reading ultrasonic distance sensor and more??
please replay
with my best regards :slight_smile:

The mega and the Uno boards run at the same speed. The mega just has more program memory for larger programs and more I/O pins.
Your problem is most likely the structure of your program. Perhaps if you post your program someone can show you how to improve it. Using the delay() statement incorrectly is the most common problem beginners have, but of course we would have to see your code to say if that is your problem or not.

Lefty

Thanks.for replay
I mean that can arduino mega run 2 diffrenet sketch at the same time

zhirantaha:
Thanks.for replay
I mean that can arduino mega run 2 diffrenet sketch at the same time

There is no microcontroller chip in the world that can run two different sketches at the same time, they all have a single processor that performs a single instruction one at a time. However most all run fast enough that one can run many separate independent user requirements fast enough so that they all appear to be functioning at the same time. You need a better understanding of how microcontroller chips operate and then adjust your thinking about what a sketch can accomplish and how to write a sketch that does all that you require to be done.

Lefty

Serial communication is slow... Depending on our application, one solution would be to read/write serial data less frequently (not every time through main loop).

Computers deal with this problem by using a [u]buffer[/u]) (a small amount of separate-dedicated memory). The CPU reads & writes to the buffer at high speed. On the other side of the buffer, the data flows in & out at the communication speed. [u]Here's[/u] a buffered UART chip.

With the right hardware, the same thing can be done with a microcontroller (but I've never built anything like that.).

For example, without buffers audio/video would never work on a multitasking computer because the audio/video needs to flow at a nice smooth-constant rate, even when the CPU (and data bus) is interrupted or multitasking. (The operating system is always multitasking, even if you are only running one application.)

DVDdoug:
Serial communication is slow... Depending on our application, one solution would be to read/write serial data less frequently (not every time through main loop).

Computers deal with this problem by using a [u]buffer[/u]) (a small amount of separate-dedicated memory). The CPU reads & writes to the buffer at high speed. On the other side of the buffer, the data flows in & out at the communication speed. [u]Here's[/u] a buffered UART chip.

With the right hardware, the same thing can be done with a microcontroller (but I've never built anything like that.).

For example, without buffers audio/video would never work on a multitasking computer because the audio/video needs to flow at a nice smooth-constant rate, even when the CPU (and data bus) is interrupted or multitasking. (The operating system is always multitasking, even if you are only running one application.)

Well today the core arduino serial library software uses fully buffered interrupt driven serial data for both send and receive data, so as long as the serial message size is smaller then the buffer size allowed, the baud rate used does not have to be a limiting factor. Again proper sketch structure can allow many user tasks to coexist and run fast enough to met the goals. However it's all about the details of what one is trying to accomplish. Bottom line is that there is only one sketch running on a arduino board at any given time.

Lefty

Yes, the serial data is buffered - haivng an external SPI based UART would let the uC blast out a bunch of data at 4 MBit/sec in a drop & forget kind of operation, the external device then deals with the actual transfer.
SC16IS752 Dual UART with I2C-bus/SPI interface, 64 bytes of transmit
and receive FIFOs

SC16IS752_SC16IS762.pdf (477 KB)