Can't connect to terminal [SOLVED]

I’m trying to setup a temperature logging program for a DS18B20 using the code found here by @tidwelltimj

My problem is that I cannot connect to the terminal window to make sure I’m getting temp readings. I’ve successfully connected to the terminal with other programs, but the spark core doesn’t even show up when running this code.

@Jackalopes, you selected Serial1 as the serial port but if you are connecting to a PC using the USB connector, you must specify Serial. Also, don’t forget to install the USB driver if you are connecting with WIndows. You can get more information about connecting here. :smile:

I must be missing something here then because I can connect when I use the below code, but not when using the DS18B20 code from above.

// Define the pins we're going to call pinMode on
int led = D0;  // You'll need to wire an LED to this one to see it blink.
int led2 = D7; // This one is the built-in tiny one to the right of the USB jack
int ledTime = 50; // Defines the time the led is on and off

// This routine runs only once upon reset
void setup() {
  // Initialize D0 + D7 pin as output
  // It's important you do this here, inside the setup() function rather than outside it or in the loop function.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  
  // Open serial over USB.
   Serial.begin(9600);
   Serial.println("Ready to go!");
}

// This routine gets called repeatedly, like once every 5-15 milliseconds.
// Spark firmware interleaves background CPU activity associated with WiFi + Cloud activity with your code. 
// Make sure none of your code delays or blocks for too long (like more than 5 seconds), or weird things can happen.

void loop() {
    // Turn ON the LED pins
    digitalWrite(led, HIGH);
    digitalWrite(led2, HIGH);
    Serial.print("On, ");
    
    // Wait for 1000mS = 1 second
    delay(ledTime);       
    
    // Turn OFF the LED pins
    digitalWrite(led, LOW);
    digitalWrite(led2, LOW);
    Serial.println("Off");
    
    // Wait for 1 second in off mode
    delay(50);
    
    // Increase delay time
    if (ledTime < 4000) {
        // do stuff if the condition is true
        ledTime = ledTime + 50;
        
    } else {
        // do stuff if the condition is false
        ledTime = 100;
    }
    
}

@Jackalopes, I hate to say it but you ARE missing something :open_mouth:

In the DS18B20 code you have:

void setup() {
  Serial1.begin(9600);
}

Note the 1 (one) after Serial? That makes use of the secondary serial port on the TX and RX pins of the Core. In the working code above you have:

  // Open serial over USB.
   Serial.begin(9600);

You need to change the “Serial1” references in the DS18B20 code to “Serial” unless your terminal IS connected to Serial1. :smile:

1 Like

Yes, I was missing something! Thanks for pointing it out and the help @peekay123.

3 Likes

What’s the difference between Serial1.begin and Serial.begin ?

Serial --> :spark: core to/from machine
Serial1 --> :spark: core to/from serial devices

See TX and RX pin on the core. It’s for you to hook up to serial devices and Serial1 will enable you to communicate :smiley:

@Jackalopes, just to add to what @kennethlimcp said, “Serial” is the console serial port done via USB to a PC. :smile:

1 Like

Good to know. Thanks again for all the help!