SolderCore & CO2 Shield send data to COSM & SD Card

SolderCore is a powerful new platform that is ideal for web connected data logging applications. Programed in (core)Basic directly to the on board BASIC interpreter via Ethernet means you can access the IDE from anywhere to update the software.

We have been testing quite a few Ethernet enabled micro-controllers out over the last few months and have struggled to find a product that has enough resources and is robust enough for the purpose of periodically logging sensor data to an on-line server via Ethernet.  We have even designed and produced a custom board based on the ATmega 1284p & Wiznet 5200 chip (more on that another day).


By chance we came across the SolderCore project and have been testing it for a few weeks, have to say we are pretty impressed.  Now, this is a departure from where we thought we were heading with this but I think it's a welcome one.  Although we have had to cast our minds back to the 1980's days of BASIC the benefits are significant: the code is very compact and human readable & as the interpreter is on-board and accessed via Ethernet, we can get at each SolderCore for re-programming, without leaving the office, anywhere in the world (although the test unit is on the desk in font of me).

Apart from being well resourced, capable and Arduino form factored it has two extremely able people developing both the hardware and software for this unique product.   Take a closer look at the SolderCore website for more info:

Our first project, and there will be more to come, was to set up a sensor data logger to pump data up to COSM as well as writing it to SD card - using just the SolderCore and the CO2 Shield.

When you look at the COSM feed you will notice some external data on there too.  This is being sent wirelessly from outside (30m away) via an XRF radio on a battery operated Seeeduino Stalker board - this data is being received and handled by our same SolderCore but we will look at that another day - for the moment we will just look at the wired stuff.

To start with take a good look at the SolderCore documentation and watch the instruction videos which will get you familiar with this slightly different workflow.  You will need to configure windows Telnet or a program like PuTTY to access your SolderCore over Ethernet - this SolderCore video takes you through this process nicely or take a look at this blog post.  Now you are connected to the hardware, familiarise yourself with the CoreBasic manual and watch the Series of programming tutorial videos starting with this one.

Of course you don't have to use the CO2 Shield to get up and running, just select your sensors to be sure they are supported by CoreBasic drivers or you can code raw I2C, for example, directly in CoreBasic.  You can type the code below directly into the CoreBasic intrpretter, copy paste or download the COSM.bas file to the SD card via your computer and load from there.... it would look something like this:


Coding the SolderCore is a real joy and pretty easy to learn as a beginner.  The AS2COSM.BAS CoreBasic file is listed below with ' Comments - you can see that the code sets up the uSD card and sensors, requests date and time from an Internet server, reads 5 sensor values, does some maths, compiles a data packets and sends it to COSM and finally writes the same data to the uSD card.... oh yes, and it blinks an LED.

 10 ' Program to log sensor data to COSM & uSD
 20 ' 2012
 30 '
 40 DEBUGGING = TRUE ' Set to TRUE to trace progress on console.
 50 '
 60 CLS ' Clear Screen
 70 LOGGERNAME = "AirSensor 2 COSM" 'Set Variable LOGGERNAME as string
 80 PRINT "Starting: "; LOGGERNAME 'Print to screen
 90 INSTALL "CORE-PRESSURE" AS BMP085 ' Install Driver for BMP085 sensor
 100 INSTALL "SHT1X" USING CORE.D17, CORE.D16 AS SHT11 ' Install SHT11 on A2 & A3
 110 '
 120 NTP = "" 'UK Time Server address
 150 '
 160 F = OPEN("/c/data/datalog.csv", READ WRITE) 'Open/Create the file on the uSD card
 170 IF F < 0 THEN 'SD error check
 180  PRINT "Failed to open file." 'Report error on screen
 190  STOP 'End program if there is a uSD card error
 200 ENDIF
 210 PTR F = EXT F 'Move to the end of the file - ensures writing to the right place
 220 PRINT #F, "Starting: " + LOGGERNAME 'Write first part of header to uSD
 230 PRINT #F, "Date,Time,Temp,RH,CO2,Air Pressure,Dew Point," 'Write second part of header in CSV format to uSD
 240 CLOSE F 'Close file
 250 PRINT "File headers written to SD" 'Print to screen
 260 '
 270 MYID = "xxxxxx" 'Variable MYID holds COSM ID number, swap out xxxxxx for yours
 280 MYKEY = "xxxxxxxxxx" 'Variable MYKEY holds COSM key code, swap out for yours
 290 BMP085.RESOLUTION = 3 'Set BMP085 resolution to maximum
 300 SHT11.RESOLUTION = 0 'Set SHT11 resolution to maximum
 310 SHT11.SOURCE = 3 'Set SHT11 voltage factor to 3V3
 320 '
 330 PAUSE 2 'Wait for 2 seconds
 340 '
 350 ' Main loop
 370  '
 380  CLS ' Clear Screen
 390  CORE.D8 = 1 'Turn LED on D8 on
 400  ' Read the ambient pressure sensor
 410  AP = (BMP085.PRESSURE / 100) + 9.15 'Read BMP085 Air Pressure value into variable AP (divide by 100 to get hPa - add 9.15 to compensate for altitude)
 420  IF DEBUGGING THEN PRINT "Air Presure is: "; AP 'Print to screen only if DEBUGGING = TRUE
 430  PAUSE 0.1 'Wait for 0.1 seconds
 440  '
 450  TP = SHT11.TEMP 'Read SHT11 Temperature value into variable TP
 460  IF DEBUGGING THEN PRINT "Temp is: "; TP 'Print to screen only if DEBUGGING = TRUE
 470  '
 480  RH = SHT11.HUMIDITY 'Read SHT11 Humidity value into variable RH
 490  IF DEBUGGING THEN PRINT "Humidity is: "; RH 'Print to screen only if DEBUGGING = TRUE
 500  '
 510  DP = SHT11.DEWPOINT 'Read SHT11 Dew Point value into variable DP
 520  IF DEBUGGING THEN PRINT "Dew Point is: "; DP 'Print to screen only if DEBUGGING = TRUE
 530  '
 540  PAUSE 0.1 'Wait for 0.1 seconds
 550  '
 560  ' Read the CO2 Sensor
 570  CALL READCO2 'run function to read CO2 sensor using 'raw' I2C code.
 580  IF DEBUGGING THEN PRINT "CO2 is: "; CO 'Print to screen only if DEBUGGING = TRUE
 590  PAUSE 0.1 'Wait for 0.1 seconds
 600  '
 610  '
 620  X = [TP, RH, CO, AP, DP] 'Write the sensor data to an array named X
 630  X = STR(INT(X * 100 + 0.5) / 100) 'Perform rounding to each value in the array
 640  '
 650  PRINT "The time according to SolderCore is "; TIME$; "."
 660  PRINT "The date according to SolderCore is "; DATE$; "."
 670  '
 690  COSMPACKET = []
 700  COSMPACKET = COSMPACKET & ["1," + X(0)] 'Join COSM 'ID' with first value in array
 710  COSMPACKET = COSMPACKET & ["2," + X(1)] 'Join COSM 'ID' with next value in array
 720  COSMPACKET = COSMPACKET & ["3," + X(2)] 'Join COSM 'ID' with next value in array
 730  COSMPACKET = COSMPACKET & ["4," + X(3)] 'Join COSM 'ID' with next value in array
 740  COSMPACKET = COSMPACKET & ["5," + X(4)] 'Join COSM 'ID' with next value in array
 750  '
 760  'Compile and send to COSM
 770  IF DEBUGGING THEN PRINT "Start write to COSM"
 780  CALL COSM(MYID, COSMPACKET) 'Send variable MYID and concatated string to COSM function.
 790  IF DEBUGGING THEN PRINT "Finished write to COSM"
 800  '
 810  'Log data to SD card
 820  IF DEBUGGING THEN PRINT "Start write to SD"
 830  F = OPEN("/c/data/datalog.csv", READ WRITE)
 840  IF F < 0 THEN
 850  PRINT "Failed to open file."
 860  RETURN
 870  ENDIF
 880  PTR F = EXT F
 890  PRINT #F, DATE$; ","; TIME$; ","; 'Write Date & Time to uSD in CSV format
 900  PRINT #F, JOIN(STR X, ",") 'Write array of sensor values, one value at a time, to uSD in CSV format
 910  CLOSE F
 920  IF DEBUGGING THEN PRINT "Finish write SD"
 930  '
 940  CORE.D8 = 0 ' set LED on D8 to OFF
 950  PAUSE 60 ' Wait 60 seconds.
 960  '
 970 UNTIL Z 'Repeat forever
 980 '
 990 'Log data to COSM
 1010  S = SOCKET("", 80) 'Open a Socket
 1020  IF S < 0 THEN 'Is socket ok?
 1030  PRINT "Failed to connect"
 1040  RETURN
 1050  ENDIF
 1060  '
 1070  'Function to send data to COSM API
 1080  PRINT #S, "PUT /v2/feeds/" + ID + ".csv HTTP/1.1" 'Send PUT request
 1090  PRINT #S, "Host:" 'Send Host
 1100  PRINT #S, "X-PachubeApiKey: " + MYKEY 'Send Key
 1120  PRINT #S, "Content-Length: "; LEN CONTENT 'Send Length
 1130  PRINT #S, "Content-Type: text/csv" 'Send Content type - CSV
 1140  PRINT #S
 1150  PRINT #S, CONTENT 'Write the data
 1160  CLOSE S 'Close the socket
 1180 ENDPROC 'End of function
 1190 '
 1200 DEFPROC READCO2() 'Function to read CO2 sensor
 1210  I2C 0x62 WRITE [0x52] 'Send I2C data request
 1220  PAUSE 0.2 'Wait 0.2 seconds for data to become ready
 1230  I2C 0x62 READ 7 TO M ' Read 7 bytes of data to variable M
 1240  M = EXPAND M 'Split variable M into 7 seperate bytes
 1250  CO = M(1) * 0x0100 + M(2) 'CO2 value is byte 1 & byte 2
 1260 ENDPROC 'End of function
0.0/5 rating (0 votes)

Comments (0)

Leave a comment

Please login to leave a comment.