Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: begginer question - serial monitor not responding

  1. #1

    begginer question - serial monitor not responding

    hello everyone , this is my first message on this forum i hope it will turn out to be usefull!
    i have a new arduino 3.6 , installed the ide 1.8.4 and teensyduino and experimented a bit. so far it was working and i coded a nice program that makes three leds light at different rates (i mean the soft and hardware are communicating) . when i wanted to use the printing feature i experienced a problem . it does not show anything . i started reading in forums and troubleshooting but all i got is more stuff i don't understand .
    would someone be kind to explain to me (very simply) what is a serial ? what is a port ? what is COM and the difference between 1 , 2 ,3 ? USART???

    picture of a circuit i made for the code below (maybe you'll find a problem with the circuit?)

    https://photos.app.goo.gl/kQ02Uct65sCROotU2

    push button code:

    void setup() {
    Serial.begin(9600);
    pinMode(28,INPUT);
    }

    void loop() {
    if(digitalRead(28) == HIGH) {
    Serial.println("button not pressed");
    } else {
    Serial.println("button pressed");
    }
    delay(250);
    }

    thank you very much for your help!!!!!

  2. #2
    Senior Member defragster's Avatar
    Join Date
    Feb 2015
    Posts
    4,655
    Was USB Type Serial selected before UPLOAD? Using SerMon in the IDE for PORT is the com port of the 'Teensy' shown - is it selected? Is the default speed of 180 MHz selected?

  3. #3
    USB type serial - selected as default.
    180 Mhz - selected as default.

    Using SerMon in the IDE for PORT is the com port of the 'Teensy' shown - is it selected?
    i'm not sure what you mean , in the tools option , i have COM1 selected for port . maybe that helps.

  4. #4
    Senior Member defragster's Avatar
    Join Date
    Feb 2015
    Posts
    4,655
    There will be a COM# listed in PORT section with 'Teensy' beside it if that COM# is where the Teensy was found and that must be selected.

  5. #5
    well , before that was exactly the situation ( port : COM1(teensy) ) but now i tried many things and somehow COM4 disappeared and also the small teensy on the right of COM1 disappeared as well

  6. #6
    update
    i tried reboot and suddenly the COM4 with the little teensy showed up in the port section , after selecting it the monitor started typing.
    thats great and i thank you for that tip!

    do you mind explaining further what is port in general and more importantly what is serial ? why is it different between teensy and arduino ? maybe you can point out a limk for some good general begginer info ?
    thanks again!!!

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,115
    Wow, now that's a question! Here's an attempt to explain, starting from the beginning. This is going to take a bit of writing.....

    The word serial means a communication method where bits are sent one at a time. Technically, many different communication protocols are serial. The letter "S" in USB and SPI means "serial". Often the word "serial" is used to talk about a specific type which is properly called Asynchronous Serial Communication, but that's a very long thing to say or type. Like most human language, abbreviated phrases are used and their meaning is understood from context. Imprecise human language can be confusing, especially when you lack the knowledge to understand the context for ambiguous phrases. Hopefully this explanation helps...

    So, here's a couple pages with good info about Asynchronous Serial Communication. You can find many more with google.

    http://www.robotroom.com/Asynchronou...ication-1.html
    https://itp.nyu.edu/physcomp/lessons...on-the-basics/

    The basic idea is every byte is sent with 2 extra bits. The "start bit" allows the receiver to know when new data begins and align its timing to capture the incoming bits. The "stop bit" allows for mismatch in speed between transmitter and receiver. This way somewhat inefficient, but it's very simple. The technique dates all the way back to mechanical teletype machines of the 1920s (and the original patent in 1874 by Emile Baudot), where the start bit released a mechanical clutch and the incoming bits were received by a solenoid pressing pins on a rotating wheel, and the stop bit(s) allowed the wheel to return and be recaptured still by the clutch. The start bit literally started a wheel turning and the stop bit allowed time for it to stop. Obviously digital logic circuits are used today, but the fundamental way of Asynchronous Serial Communication was designed for very simple systems and to automatically compensate for imprecise timing between them.

    Asynchronous Serial Communication is also sometimes called names which technically refer to voltage levels. RS232, RS422, RS485 are the common ones. Also "TTL level" is sometimes mentioned, but usually the word "serial" is used because this term can apply to virtually all digital logic. These all mean the same type of serial communication, but with different voltages & currents. MIDI (not USB, the original large 5 pin round connectors) are also Asynchronous Serial Communication at 31250 bits/sec, even though "serial" is rarely said. Because the transmitter and receiver have to use the same settings, and there's no way to auto-detect, lots of lingo about baud rates, data formats and number of start/stop bits also exists. Yes, it's confusing, but that's the way human language is for something that's been so widely used in many ways, for almost 100 years.

    The word "port" means a physical place where you can connect the wires, and whatever name/icon the system uses to refer to that physical location. Asynchronous Serial Communication is usually used to directly connect 2 devices, so in the common usage each port lets you connect only 1 thing. One of the many great features of Teensy 3.6 is you get 6 serial ports, plus a 7th fully separate "virtual" USB port I'll explain in a moment. Many Arduino boards give you only 1 serial port, and it's shared with the USB, which makes connecting serial devices like GPS modules a challenge. With Teensy 3.6 you have 6 of these ports, so you can connect up to 6 serial devices to your Teensy 3.6 pretty easily. After you use up all 6, there are some techniques to emulate another port, but those consume a lot of CPU resources and can interfere with other code, so having enough real serial ports is a pretty desirable feature.

    In the 1990s, most PCs had 2 physical serial ports and 1 parallel port, which were commonly used to connect modems and printers. As USB became common, it replaced these ports. Today no modern PCs have parallel ports. Many PCs still do have 1 physical serial port (Asynchronous Serial Communication), though it's usually a header on the motherboard without any cable plugged in. It's common to see COM1 on Windows and /dev/ttyS0 on Linux, which represents this physical port. If you open COM1 with the Arduino Serial Monitor and send some text, it will make the TX pin on that connector actually change voltages, like the waveforms shown on those pages. Of course, it can seem like nothing is working, because no wires are connected. Nothing is changing the signal on the RX pin, so you never see anything in the Arduino Serial Monitor window.

    With USB, we now have virtual serial ports. On Windows, these usually appear starting with COM3, because of the old history where almost all PCs used to have 2 physical serial ports. On Linux, they appear starting as /dev/ttyACM0 or /dev/ttyUSB0. Like Windows, the numbers increase as you add more. But Windows tries to remember each actual USB device and give it its own number. Linux doesn't keep a history of the USB devices you've plugged in like Windows does with its registry, so they start numbering at 0 and increase in the order you plug them in.

    The idea of a virtual serial port is software compatibility. You can access it the exact same way as the ports for physical Asynchronous Serial Communication, but instead of communicating on the wires as those pages above describe, your data is sent over the USB.

    Now, with this info in mind, you asked:

    Code:
    why is it different between teensy and arduino ?
    There are actually many different Arduino products, but the most common ones are Arduino Uno & Mega. Both of these have a USB-to-Serial converter chip. When you use the virtual serial port on your PC, it communicates with this chip. The chip turns your communication into real Asynchronous Serial Communication, which then connects to the microcontroller you're programming on Uno or Mega. On those Arduino boards, when you use "Serial", it really is real physical Asynchronous Serial Communication, at least on short wires between the chips.

    The big difference with Teensy is "Serial" is a virtual serial port. So when you use Serial.print() on Teensy, you're talking to a virtual serial port which communicates with the other virtual serial port in your PC. It never actually gets turned into actual Asynchronous Serial Communication. Keeping the communication only between virtual ports is much faster, because it's never converted to the slow baud rate of Asynchronous Serial Communication. You also get the data properly received regardless of the baud rate setting.

    Many of Arduino's newer products also have virtual serial ports. Sadly, they haven't been very consistent with port names. On some boards like Arduino Micro & Leonardo, "Serial" is a USB virtual serial port, the same as Teensy. On others like Arduino Due, they named the virtual port "SerialUSB", and "Serial" is regular Asynchronous Serial Communication, sometimes to a USB-serial converter chip. It varies quite a lot across the Arduino products, but there's a strong convention that Serial.print() is supposed to end up printing to the Arduino Serial Monitor if you have everything running in the default way.

    On Teensy and most Arduino boards with more ports, the names are Serial1, Serial2, Serial3 and so on. The main different between boards is how the first one is named, and whether it's a USB virtual serial port or a physical serial port which communicates with a USB-serial chip. On all Teensy boards, "Serial" is always USB virtual serial and the first physical serial is Serial1.

    A big difference between physical ports and virtual ones is hot plugging. The physical port always exists, from the moment your PC boots. It never disappears. But virtual ports are created when you plug in the USB cable, and they vanish when you unplug the cable. This matters, because when boards like Teensy or Arduino Leonardo/Micro reboot, their virtual port goes away. Even though you haven't touched the cable, even though it's still physically plugged in, your PC sees this as if the cable was actually unplugged for a brief moment and then reconnected.

    With boards like Arduino Uno, the USB-serial chip doesn't reboot when you reboot the microcontroller. So even though it's a virtual serial port on your PC, it remains connected the whole time. But on boards like Teensy where the virtual serial port is in the chip which reboots, your PC sees the virtual serial port vanish and then reappear. Teensy also differs from Arduino in its use of USB for programming. Arduino uses serial. Teensy actually uses USB HID for all uploading, so it only becomes a USB virtual serial port on your PC after it reboots and runs your code. Teensy also offers many different USB options, in the Tools > USB Type menu. The ones without "Serial" don't act as USB serial, so there's no COM port (Windows) or /dev/ttyACM (Linux) in those modes. However, it uses a HID interface to emulate serial in those modes, so you can still use Serial.print() to get messages to the Arduino Serial Monitor. But the default USB Type is Serial, so normally Teensy is implements a USB virtual serial port which appears as a COM or /dev/ttyACM port on your PC's operating system.

    Older versions of Macintosh and pre-10 versions of Windows had bugs with their handling of virtual serial ports disconnecting while they were in use. Arduino's Serial Monitor window automatically closes when you upload, avoiding those problems. But if you have other non-Arduino software accessing the COM port, it's possible to trigger this nasty driver bug in all pre-10 versions of Windows. These problems are very confusing, but hopefully someday Windows XP, 7 & 8 will be only a distant bad memory.

    Likewise, if you write programs to talk with serial ports, it's easy to forget that USB virtual ports can disconnect. On Arduino, you can use Serial as a boolean to check if the virtual port is actually connected. It doesn't vanish like the COM or /dev/ttyACM ports on a PC, but it does go into a mode where it can't communicate because the cable isn't connected (or your PC hasn't initialized the USB yet). It's common to add "while (!Serial) ; // wait" near the beginning of setup(), which waits for you to open the serial monitor. This code can also later be a problem if you want to run without a PC, since it waits forever, so don't forget to delete it from your code or modify it to give up waiting after a certain amount of time. Of course, physical serial ports can't tell if the other side is present, since they just transmit and receive the bits as timed patterns of bits.

    Hopefully that clears up what serial is.
    Last edited by PaulStoffregen; 09-07-2017 at 01:17 PM.

  8. #8
    allright! much appreciated!
    i'll continue to the links! (:

  9. #9
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    575
    gony, I notice in your photograph that it doesn't appear you've soldered pins to your Teensy. If I'm seeing it correctly, this should be the first thing to fix. Without reliable wiring, things might not work at all or if you're unlucky, might work just enough to keep you chasing complex theories of what's wrong.

    You'll either need to solder header pins to the Teensy or use spring clips of some sort, like a j-hook clip for example. The pressure between the wire and the pin hole needs to be strong enough that bumping the wire (or the table) doesn't disturb the connection.

  10. #10
    got that!
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •