Syntax highlighter ...
 
Notifications
Clear all

Syntax highlighter test

2 Posts
1 Users
0 Likes
491 Views
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1083
Topic starter  

Here is the Blink sketch:

/*
  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.

   https://www.arduino.cc/en/Tutorial/BuiltInExamples/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
}

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
Quote
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1083
Topic starter  

Here is some MicroPython Code:

# Digi XBee3 Cellular DRM Example
# uses a TMP36 to measure temperature and post it to Digi Remote Manager
# by default repeating once per minute, 1440 times total, stopping after a day
# ENTER YOUR DRM username and password, REPLACING "your_username_here" etc. BEFORE UPLOADING THIS CODE!
from remotemanager import RemoteManagerConnection
from machine import ADC
from time import sleep
from xbee import atcmd
cycles = 1440 # number of repeats
wait_time = 60 # seconds between measurements
username = 'your_username_here' #enter your username!
password = 'your_password_here' #enter your password!
# Device Cloud connection info
stream_id = 'temperature'
stream_type = 'FLOAT'
stream_units = 'degrees F'
description = "temperature example"
# prepare for connection
credentials = {'username': username, 'password': password}
stream_info = {"description": description,
                   "id": stream_id,
                   "type": stream_type,
                   "units": stream_units}
ai_desc = {
    0x00: 'CONNECTED',
    0x22: 'REGISTERING_TO_NETWORK',
    0x23: 'CONNECTING_TO_INTERNET',
    0x24: 'RECOVERY_NEEDED',
    0x25: 'NETWORK_REG_FAILURE',
    0x2A: 'AIRPLANE_MODE',
    0x2B: 'USB_DIRECT',
    0x2C: 'PSM_DORMANT',
    0x2F: 'BYPASS_MODE_ACTIVE',
    0xFF: 'MODEM_INITIALIZING',
}
def watch_ai():
    old_ai = -1
    while old_ai != 0x00:
        new_ai = atcmd('AI')
        if new_ai != old_ai:
            print("ATAI=0x%02X (%s)" % (new_ai, ai_desc.get(new_ai, 'UNKNOWN')))
            old_ai = new_ai
        else:
            sleep(0.01)
# Main Program
# create a connection
rm = RemoteManagerConnection(credentials=credentials)
# update data feed info
print("updating stream info...", end ="")
try:
    rm.update_datastream(stream_id, stream_info)
    print("done")
except Exception as e:
    status = type(e).__name__ + ': ' + str(e)
    print('\r\nexception:', e)
    
while True:
    print("checking connection...")
    watch_ai()
    print("connected")
    for x in range(cycles):
        # read temperature value & print to debug
        temp_pin = ADC("D0")
        temp_raw = temp_pin.read()
        print("raw pin reading: %d" % temp_raw)
    
        # convert temperature to proper units
        temperatureC = (int((temp_raw * (2500/4096)) - 500) / 10)
        print("temperature: %d Celsius" % temperatureC)
        temperatureF = (int(temperatureC * 9.0 / 5.0) + 32.0);
        print("temperature: %d Fahrenheit" % temperatureF)
    
        # send data points to DRM
        print("posting data...", end ="")
        try:
            status = rm.add_datapoint(stream_id, temperatureF) # post data to Device Cloud
            print("done")
            print('posted to stream:', stream_id, '| data:', round(temperatureF), '| status:', status.status_code)
        except Exception as e:
            print('\r\nexception:', e)
        # wait between cycles
        sleep(wait_time)

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
ReplyQuote