Created
October 24, 2017 12:22
-
-
Save fredrikhr/f55c1930b0aad402763644d29768dbb0 to your computer and use it in GitHub Desktop.
air:bit Arduino Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LED_WHITE PIN_A1 | |
#define LED_GREEN PIN_A0 | |
void setup() { | |
pinMode(LED_WHITE, OUTPUT); | |
pinMode(LED_GREEN, OUTPUT); | |
} | |
void loop() { | |
digitalWrite(LED_WHITE, HIGH); | |
delay(1000); | |
digitalWrite(LED_WHITE, LOW); | |
digitalWrite(LED_GREEN, HIGH); | |
delay(1000); | |
digitalWrite(LED_GREEN, LOW); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Blink | |
Turns an LED on for one second, then off for one second, repeatedly. | |
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO | |
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to | |
the correct LED pin independent of which board is used. | |
If you want to know what pin the on-board LED is connected to on your Arduino | |
model, check the Technical Specs of your board at: | |
https://www.arduino.cc/en/Main/Products | |
modified 8 May 2014 | |
by Scott Fitzgerald | |
modified 2 Sep 2016 | |
by Arturo Guadalupi | |
modified 8 Sep 2016 | |
by Colby Newman | |
This example code is in the public domain. | |
http://www.arduino.cc/en/Tutorial/Blink | |
*/ | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin LED_BUILTIN as an output. | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(1000); // wait for a second | |
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW | |
delay(1000); // wait for a second | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DHT_sensor_library\DHT.h> | |
#define DHTPIN 9 | |
DHT dhtSensor(DHTPIN, DHT22); | |
void setup() { | |
Serial.begin(9600); | |
dhtSensor.begin(); | |
} | |
void loop() { | |
float temperature, humidity; | |
humidity = dhtSensor.readHumidity(); | |
temperature = dhtSensor.readTemperature(); | |
Serial.print("T(C): "); | |
Serial.print(temperature); | |
Serial.print("\tT(F): "); | |
Serial.print(dhtSensor.convertCtoF(temperature)); | |
Serial.print("\tH: "); | |
Serial.println(humidity); | |
delay(1000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TinyGPS++.h> | |
#include <SoftwareSerial.h> | |
#include <stdlib.h> | |
static const int RX_PIN = 7; | |
static const int TX_PIN = 6; | |
static const uint32_t GPSBaud = 9600; | |
TinyGPSPlus gps; | |
SoftwareSerial ss(RX_PIN, TX_PIN); | |
#define LED_WHITE PIN_A1 | |
#define LED_GREEN PIN_A0 | |
void setup() { | |
pinMode(LED_WHITE, OUTPUT); | |
pinMode(LED_GREEN, OUTPUT); | |
ss.begin(GPSBaud); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (ss.available()) { | |
if (gps.encode(ss.read())) { | |
if (gps.location.isValid()) { | |
digitalWrite(LED_GREEN, HIGH); | |
// Date | |
Serial.print("Date: "); | |
Serial.print(gps.date.day()); | |
Serial.print("/"); | |
Serial.print(gps.date.month()); | |
Serial.print("/"); | |
Serial.print(gps.date.year()); | |
Serial.print(" "); | |
Serial.print(gps.time.hour()); | |
Serial.print(":"); | |
Serial.print(gps.time.minute()); | |
Serial.print(":"); | |
Serial.print(gps.time.second()); | |
Serial.print(","); | |
// Latitude. | |
// Note that we convert the float output to a string. This is | |
// for convenience when we're later going to write it to a file | |
// on a SD memory card. | |
char lat[15]; | |
dtostrf(gps.location.lat(), 3, 6, lat); | |
Serial.print(" Latitude: "); | |
Serial.print(lat); | |
Serial.print(","); | |
// long | |
char lng[15]; | |
dtostrf(gps.location.lng(), 3, 6, lng); | |
Serial.print(" Longitude: "); | |
Serial.print(lng); | |
Serial.print(","); | |
delay(500); | |
digitalWrite(LED_GREEN, LOW); | |
} | |
else { | |
digitalWrite(LED_WHITE, HIGH); | |
Serial.print("Bad GPS signal."); | |
delay(500); | |
digitalWrite(LED_WHITE, LOW); | |
} | |
Serial.print("\n"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
SD card test | |
This example shows how use the utility libraries on which the' | |
SD library is based in order to get info about your SD card. | |
Very useful for testing a card when you're not sure whether its working or not. | |
The circuit: | |
* SD card attached to SPI bus as follows: | |
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila | |
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila | |
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila | |
** CS - depends on your SD card shield or module. | |
Pin 4 used here for consistency with other Arduino examples | |
created 28 Mar 2011 | |
by Limor Fried | |
modified 9 Apr 2012 | |
by Tom Igoe | |
*/ | |
// include the SD library: | |
#include <SPI.h> | |
#include <SD.h> | |
// set up variables using the SD utility library functions: | |
Sd2Card card; | |
SdVolume volume; | |
SdFile root; | |
// change this to match your SD shield or module; | |
const int chipSelect = 10; | |
void setup() { | |
// Open serial communications and wait for port to open: | |
Serial.begin(9600); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for native USB port only | |
} | |
Serial.print("\nInitializing SD card..."); | |
// we'll use the initialization code from the utility libraries | |
// since we're just testing if the card is working! | |
if (!card.init(SPI_HALF_SPEED, chipSelect)) { | |
Serial.println("initialization failed. Things to check:"); | |
Serial.println("* is a card inserted?"); | |
Serial.println("* is your wiring correct?"); | |
Serial.println("* did you change the chipSelect pin to match your shield or module?"); | |
return; | |
} | |
else { | |
Serial.println("Wiring is correct and a card is present."); | |
} | |
// print the type of card | |
Serial.print("\nCard type: "); | |
switch (card.type()) { | |
case SD_CARD_TYPE_SD1: | |
Serial.println("SD1"); | |
break; | |
case SD_CARD_TYPE_SD2: | |
Serial.println("SD2"); | |
break; | |
case SD_CARD_TYPE_SDHC: | |
Serial.println("SDHC"); | |
break; | |
default: | |
Serial.println("Unknown"); | |
} | |
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 | |
if (!volume.init(card)) { | |
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); | |
return; | |
} | |
// print the type and size of the first FAT-type volume | |
uint32_t volumesize; | |
Serial.print("\nVolume type is FAT"); | |
Serial.println(volume.fatType(), DEC); | |
Serial.println(); | |
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks | |
volumesize *= volume.clusterCount(); // we'll have a lot of clusters | |
volumesize *= 512; // SD card blocks are always 512 bytes | |
Serial.print("Volume size (bytes): "); | |
Serial.println(volumesize); | |
Serial.print("Volume size (Kbytes): "); | |
volumesize /= 1024; | |
Serial.println(volumesize); | |
Serial.print("Volume size (Mbytes): "); | |
volumesize /= 1024; | |
Serial.println(volumesize); | |
Serial.println("\nFiles found on the card (name, date and size in bytes): "); | |
root.openRoot(volume); | |
// list all files in the card with date and size | |
root.ls(LS_R | LS_DATE | LS_SIZE); | |
} | |
void loop(void) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SDS011 dust sensor example | |
// ----------------------------- | |
// | |
// By R. Zschiegner ([email protected]). | |
// April 2016 | |
#include <SDS011.h> | |
float p10, p25; | |
int error; | |
SDS011 my_sds; | |
void setup() { | |
my_sds.begin(2, 3); | |
Serial.begin(9600); | |
} | |
void loop() { | |
error = my_sds.read(&p25, &p10); | |
if (!error) { | |
Serial.println("P2.5: " + String(p25)); | |
Serial.println("P10: " + String(p10)); | |
} | |
else { | |
Serial.println("Could not read air data: " + String(error)); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment