


Arduino serial serial#
Serial.begin(9600) // set up Serial library at 9600 bps Serial.print( "Test value is: ") Here is a short list of types we can use. OK let's fix it! All we need to do is change the variable type so that it can store more than 2 bytes of data. Since the number we're trying to store (102400) is larger than that, we see that "rollover." So, in this case the largest number is 2 16 - 1 = 65535. Then we subtract 1 because like in the car odometer, you can't actually display the final value, 10000. To figure out how big a number we can store in a 2 byte-sized box use a calculator and take 2 to the power of the number of bits (since each bit can store 2 values, 0 or 1). There are 8 bits in 1 byte so 2 bytes is 16 bits It turns out that an int type can store only 2 bytes. Keeping that in mind, remember in lesson 2 we said that when we define a variable we also define the box-type of the variable? The box is where we store the data, in this case the type is int. If you travel 10000 miles, the odometer will "roll over" to 0 again, and from then on it will display an incorrect value. The odometer has only 4 digits, it can display 0 miles to 9999 miles travelled. What's happening is that we have an overflow problem. Here's whats going on in the Arduino with this sketch. You can experiment with changing the print's to println's and looking at the Serial Monitor output to verify this for yourself. The print procedure is just like println except it does not print out a "carriage return" at the end, starting a new line. Note that we're using 2 procedures here, the original println and now also print. Void loop() // we need this to be here even though its empty begin(9600) // set up Serial library at 9600 bps Serial. Void setup() // run once, when the sketch starts Make the Arduino chill out a little by adding a one second delay to the sketch, so that it only prints out Hello World once a second. The data is being transmitted so fast, that we can't see the TX LED 's sending data many times a second! What's going on here? Hint: Remember lesson 2?.Try waving the Arduino around in a dark room, what do you see?.You will see Hello World! scroll by super fast! Perform this modification and then compile and upload the new hyper-hello sketch. Simply move the Serial.println("Hello world!") statement from the setup procedure to the loop procedure. What simple modification should we perform to make the Arduino print Hello World over and over again?.Instead of printing out Hello World just once, we'd like it to print it out over and over and over again. Our next sketch will be a minor modification of this one.

Good, now compile the sketch and upload it to your Arduino. This is twice as fast as before, so it will take half the time, about 1/200th of a second. If the Arduino transfers data at 19200 bits per second (19200 baud) and you're sending 12 bytes of data, how long does it take to send over this information?.If we can transfer 9600 bits per second, then 96 bits takes 1/100th of a second! If the Arduino transfers data at 9600 bits per second and you're sending 12 bytes of data, how long does it take to send over this information?ġ2 bytes of data equals 12 * 8 = 96 bits of data.We use two "'s (double quotes) to indicate the beginning and end of a line of text. This time the input is a quotation, the line of text we would like it to print. Note that the 6th letter in println is the letter L not the number 1. This line also uses the Serial library, this time it's calling a procedure called println which is just a shorthand for "print line". Serial.println( "Hello world!") // prints hello with ending line break How much less storage do you get thanks to the marketing guy who came up with this trick? Given this fact, how many bytes can you really store in your 200GB drive? Hard drive makers are quite sneaky, you'll notice that they define GB as being 1000 MB, and 1 MB = 1000 KB, etc. If your hard disk is 200 Gigabytes, how many bytes is that? Use a calculator with lots of digits!Ģ09715200 KB * 1024 = 214748364800 bytes! That is, a 1.0 Kilobyte file on your computer is 1024 bytes: You can group bits together into 8 bits which is 1 byte.ġ024 bytes (8192 bits) is one Kilobyte (sometimes written KB).ġ024 KB (1048576 bytes) is one Megabyte (MB)Īn interesting thing to note is while 1000 grams is a kilogram, nearly all computer systems consider 1024 bytes to be a kilobyte. Information has its own system of measurements: For example, we measure weight with "ounces" and "pounds" (or grams and kilograms) and distances with "inches," "feet," and "miles" (or centimeters, meters and kilometers). Now is a good time to review how data is measured. It's run by little ones and zeroes, little bits of data. The world isn't run by weapons anymore, or energy, or money.
