How to use serial.print

Im new to spark, and dont know how to see the console. Can someone please inform me how? Sample code below.

// 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 cnter=0;
// 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);
}

// 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() {
    cnter++;
       Serial.println(cnter);
  digitalWrite(led, HIGH);   // Turn ON the LED pins
  digitalWrite(led2, HIGH);
  delay(310);               // Wait for 1000mS = 1 second
  digitalWrite(led, LOW);    // Turn OFF the LED pins
  digitalWrite(led2, LOW);
  delay(300);               // Wait for 1 second in off mode
  digitalWrite(led, HIGH);   // Turn ON the LED pins
digitalWrite(led2, HIGH);
delay(1000);               // Wait for 1000mS = 1 second
digitalWrite(led, LOW);    // Turn OFF the LED pins
digitalWrite(led2, LOW);
delay(1000);               // Wait for 1 second in off mode
//}
 
 
 
 
}

You need something like this:

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

void loop(){
      serial.println("");
}

thanks for prompt reply.
your code doesnt complie and serial begin doesnt work in mine either.
Im familiar with arduino. I just go to serial console as see the serial output.
I dont have a clue how to do this on spark

/blink_an_led.cpp:2:7: error: ‘serial’ was not declared in this scope

  /blink_an_led.cpp: In function 'void loop()':


  /blink_an_led.cpp:6:7: error: 'serial' was not declared in this scope

Sorry you need a capital S :smiley:

Serial.begin(9600)

1 Like

Hi Kennith
that now compiles:)
How to get to to see terminal output?

This topic kinda shows it all :wink:

You can use a terminal like Putty on Windows to open up a COM port :wink:

The arduino IDE would work as well, in case you’re used to that one.

2 Likes

or GNU screen: screen /dev/ttyACM0 9600 or minicom

1 Like

Thanks for replies.
IM aware how to do com port serial.print, but was hoping for wifi.
If this is ide, or gnu, can someone show the steps that need to be done?

You want to see serial output via wifi?

Correct, else some other way for wifo to communicate to me. web page, phone app etc

Hi @kiwibird1

Have your seen the Tutorials section here in the fourm? There are a lot great ways to get data to and from your core.

The Spark.publish() method is probably the easiest way to get data out but Spark.variables also work great.

https://community.spark.io/category/project-share/tutorials

spark publish looks good.
I tried the instructions at https://community.spark.io/t/sprint-7-spark-publish-released-lets-build-a-cloud-connected-motion-detector/3391
When I do npn install -g spark-cli i get “…” and it hangs.

Try this tutorial to get the CLI up and running:


Shouldn’t be too difficult, and the CLI is extremely useful!
Good luck.

https://github.com/spark/spark-cli has the unix commands for installing spark-cli

i had to do the following as root on Debian7, as one of the dependencies expects to find the binary “node” not “nodejs”:

apt-get install node
cd /usr/bin
ln -s nodejs node
npm install -g spark-cli