this post was submitted on 28 Jul 2023
4 points (100.0% liked)

Arduino

537 readers
1 users here now

This is an UNOFFICIAL Arduino community.

Everyone who uses Arduino board or their clones or associated boards and/or the Arduino IDE is welcome here. If it involves Arduino hardware or software it's welcome here. If it connects to Arduino hardware it's welcome here. If you're building your own boards that you use with an Arduino it's welcome here. There will be no Arduino elitist bullshit in this community.

You may also be interested in:

AVR

RULES:

  1. It's always a floating input.

  2. All Lemmy.ca rules apply here.

  3. Everyone (see rule 98) is welcome.

  4. If you’ve seen a question 100 times answer it the 101st time or ignore it. Even better, write a complete, detailed answer and suggest that the mod(s) pin it to the community.

[Did you actually think there were 98 rules?]

  1. If you present something as fact and are asked to provide proof or a source provide proof or a source. Proof must be from a reliable source. If you fail to provide proof or a source your post or comment may be removed.

  2. Don’t be a dick. Yes, this is a catch-all rule.

  3. The mod(s) have the final say.

founded 1 year ago
MODERATORS
 

Here is my new serial starting code. It takes some time to start printing the serial after the command is set. Usually you simply add a delay, but that delay can be longer than the time your serial takes to connect, so you're waiting for nothing and when you're trying to troubleshoot that becomes frustrating. The other option is the check if the serial started with while (!Serial) { delay(10); } but then your code doesn't run without a serial connection so it just hangs if you try it off a battery or USB charger block.

Here comes the best of both worlds!

It checks for a serial connection every 10 ms but only for 3 seconds, then it goes on. The commented out line is to print how long it takes for your serial to show up. It was useful to determine 3s was a good number (I landed around 2100 to 2700 ms so 3000 gives me just a bit of padding while still being fairly fast when not plugged to a serial console.

Bonus is the giant ASCII START logo I made so I can easily see where it started when scrolling back up.

You can throw this at the top of your setup() or even better, make it a function and call it, so you only need to comment out a single line when you go testing it without a computer and save those precious 3 seconds at startup.

Enjoy!

  Serial.begin(115200);
  unsigned long time_begin = millis();
  while (!Serial && (millis() - time_begin) < 3000) {
    delay(10);
    // Serial.println(millis() - time_begin);
  }
  delay(10);
  Serial.println(" ");
  Serial.println("       ::::::::   :::::::::::       :::        :::::::::   ::::::::::: ");
  Serial.println("     :+:    :+:      :+:         :+: :+:      :+:    :+:      :+:      ");
  Serial.println("    +:+             +:+        +:+   +:+     +:+    +:+      +:+       ");
  Serial.println("   +#++:++#++      +#+       +#++:++#++:    +#++:++#:       +#+        ");
  Serial.println("         +#+      +#+       +#+     +#+    +#+    +#+      +#+         ");
  Serial.println(" #+#    #+#      #+#       #+#     #+#    #+#    #+#      #+#          ");
  Serial.println(" ########       ###       ###     ###    ###    ###      ###           ");
  Serial.println(" ");
  Serial.println(" ");

PS: it looks like Lemmy can't handle color coded markdown... :(

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here