Bentuino – Bloghttps://bentuino.com
Microcontrollers and IoTTue, 06 Nov 2018 05:00:44 +0000en-UShourly1https://wordpress.org/?v=4.9.8Using a MeshBee with Smartthingshttps://bentuino.com/2016/12/10/using-a-meshbee-with-smartthings-part1/
https://bentuino.com/2016/12/10/using-a-meshbee-with-smartthings-part1/#respondSun, 11 Dec 2016 07:17:39 +0000http://bentuino.com/?p=805Since about six month I owned a Smartthings (ST) smart home hub from Samsung and have been pretty pleased with the functionality and openness of the platform. My home is equipped with wireless light switches that can be control from ST. So I started to add motion sensors to turn on and off lights in the basement and restrooms. My choice fell on the 2nd generation Iris Motion sensor from Loewe’s. They are battery powered and so far have been reliable with the battery still at 76% after almost 6 months of service.
I quickly realized that the ST system was really flexible and open. Therefore it should not be too difficult to add custom-built sensors and actors to the ST hub. This post describes the first phase of trying to build my own wireless sensors and actors.
The ST hub hardware supports the following protocols to interact with sensors and actors. Among them TCP/IP (Ethernet, WiFi), Z-Wave, Zigbee, Bluetooth (not activated yet in ST hub). As I wanted my sensors to be battery powered, WiFi solutions like the Particle Photon or ESP8266 fell by the wayside. Therefore my focus turned to Z-Wave and Zigbee.
Z-Wave is a proprietary standard owned by Sigma Designs, Inc and uses different frequency bands in different geographic regions which leads to the available z-wave modules to be rather expensive. That said there is an interesting DIY board the Z-Uno but it is not yet available in the US Freq. Band and again fairly pricey.
Zigbee is the other candidate. This is an open standard that is supported by many semiconductor device manufacturers and there is a large selection of modules out there.
What I was looking for are solutions that allowed to write small programs to control or sense a few IO pins. Many available modules use TI’s CC2x30 chips. These chips come with a built-in 8051 8 bit CPU. However, TI suggests using the IAR compiler and SDK. Unfortunately, it carries a price tag of ~$3000 which is hard to justify for a DIY project. However, there is a Zigbee device that fits my needs pretty nicely and comes with a free SDK. It is the JN5168 from Jennic that is now owned by NXP and soon by Qualcomm. I settled on a MeshBee (~$20) module from Seeedstudio together with a UartSBee V4 but I expect you can also use the SparkFun XBee Explorer Dongle or similar FTDI adapters.

Installing The JN5168 SDK and compiling the first Application

Head over to the NXP IEEE802.15.4 Page. You must register and login first before you can download the BeyondStudio for NXP toolchain (JN-SW-4141). Then add the JN516x IEEE 802.15.4 SDK (JN-SW-4163) to your installation by following the NXP installation instructions. I also installed the Flash Programmer (JN-SW-4107) .
Now that your SDK and toolchain are installed download the ZigBee Home Automation Demo (JN-AN-1189) from the NXP web site. Unpack and import it into your Eclipse workspace as an “Existing Project into Workspace” under the tab “General”. Yshould now have something like this on your screen:
Go to “Project” -> “Build Configuration” -> “Set Active” and select item #9 “DimmableLight 1 (DR1175)”. Then select “Project” -> “Build All” or just use the command line:

make LIGHT=DimmableLight DR=DR1175 REV=r1v1 all

The compile takes quite long but once finished you should have a binary “DimmableLight_JN5168_DR1175_LED_EXP_MONO.bin”. Plug your Meshbee on top of the UartSbee. Make sure SW3 of the UartSBee is in the “Prog” position and connect UartSBee with a USB cable to your computer. In Eclipse select from the “Device” -> “Program Device”. Program you MeshBee with the freshly compiled firmware.
You can now use your ST app on your phone to add a new device. After a while, the MeshBee should show up as a “Thing” device. Rename it to something of your choosing and save it.
Head over to your ST development environment, login and check under “My Devices”. You should see you freshly added device listed under the name you assigned. Click on the name and you will get a page like this:
Now click on the Edit button and change the “Type” to “Zigbee Dimmer” and save it by clicking the “Update” button
You should now get a proper Tile in your ST App on your phone. Click on the On/Off button and in the log you should see events being logged. Connect a LED or Voltmeter to D13 and you can see the LED turn on and off.
This blinky example is the “Hello World” demonstration of a Zigbee actor connected to a Smartthings hub.

]]>https://bentuino.com/2016/12/10/using-a-meshbee-with-smartthings-part1/feed/0Quadcopter BeeRotor Victory210https://bentuino.com/2016/11/22/quadcopter-beerotor-victory210/
https://bentuino.com/2016/11/22/quadcopter-beerotor-victory210/#respondWed, 23 Nov 2016 06:47:57 +0000http://bentuino.com/?p=766This is a bit of a leisurely post. After attending Maker Fair 2016 my son wanted to build a racing quad-copter. He did not want to buy a Ready To Fly (RTF) copter but rather a kit based on some recommendations from a pilot of the said show. Anyway, eventually we settled on the BeeRotor Victory210 from RCTimer.There are a few guides that show step-by-step how to assemble the copter. The most helpful is certainly the one from the Blog of Nathan Vertile.
However as a total newbie to the field of quad-copters and RC models We went through a bit of troubles to get everything working. So here are some notes that eventually got us to a flying model.
Note, that I will not cover the assembly of the copter in details as we did not have much trouble to follow the guides available on-line. I will mostly focus on the software and configuration part.
Besides the copter kit we used the following components:

The only thing note worthy is that the four motor controllers (ESCs) are not all connected the same. Pay attention to the direction the motors turn.Connect the Receiver: Once the kit is assembled the receiver needs to be connected to the BRF3 flight controller. We use FlySky IBUS port of the iA6B receiver and connect it to UART3 pin 1-3 (S.BUS) of the connector SB on the BRF3 board. IBUS is a FlySky proprietary interface using a UART channel to forward the control to the flight controller. It replaces the traditional PWM ports.Flash Flight Controller with Firmware:

Connect your computer to the micro USB port of the BRF3 while holding the boot button next to the micro USB connector down. Do not connect the battery to the Victory230 the controller will get powered over the USB cable..

The flash process should now start. Wait until completed successfully.

Note 1: you can also simply select “SPRACINGF3” in the firmware pull-down menu and click the “Load Firmware [Online]” button.
So now that we have flashed the correct firmware we do the same thing for the motor controllers (ESCs). The nice thing is we can use the BRF3 in pass-through to program the ESCs.Update ESC Firmware: this is an optional step and I believe not really required. However because I did it I list the steps to perform it.

Now you can check the setup of all four ESCs under the “ESC Overview” tab. Note the bold values are the only non-default settings.

Configure Flight Controller:

Click the “Connect” button. Betaflight should now connect to your copter and the following screen will appear. If you have problems, check your COM port setting

Put the Victory210 on a leveled surface and under the “Setup” tab click the “Calibrate Accelerometer” button. Then rotate it along all three axis at least 360 degrees within 30 seconds. Now the accelerometer should be properly calibrated.

Move to the “Ports” tab and select the “RX” of “UART3” to enable the connection between the BRF3 to the RC receiver.

Move to the “Configuration” tab and scroll down to “Battery Voltage” and set “Voltage Scale” to 210. Next turn under the “Current Sensor” the “CURRENT_METER” on. Set the “Scale the output voltage….” to 380. Now the under voltage and over current protection will go off at the right levels.

Under “Receiver Mode” select “RX_SERIAL” to configure the BRF3 to understand the FlySky receiver connected to UART3

Under “Serial Receiver Provider” select IBUS to the correct protocol for the FlySky receiver.

Under “System Configuration” enable the “Barometer (if suppoted)” and click “Save and Reset”

Configure the FlySky Transmitter:

There is not too much to configure. The transmitter should work out of the box and shipped already paired with the receiver.

Although we use it for a copter make sure that it is configured to “Plane/Glider”

Note: once you have turned the “Expert Mode” on you can also save and restore configurations under the “Setup” tab.Maiden Flight
Before we install the propellers we want to check a few things:

Check that when you move the sticks only the related chnannels are chaning. If that is not the case your Radio Controller may do some mixing so you want to check this.

Check the Motor control. The motors are secured until you push the throttle stick (in a normal setup the left stick on your RC) to the lower right corner. Once you do this a Beep will signal that the copter is armed and you should see all four motor bars to jump to 1070.

Now it is time to install the propellers and do a first flight test. Note the propellers are not all the same: pay attention to their shape before you mount them. Consider the motors turning directions and select the propeller that works for the related directions.

Firmware: Even though Natan uses Clearflight I could not get it to work with their firmware

Resources and Credit:
A big Thank You goes to all the contributors of tools and software described in this post. I also want to acknowledge the blog posts from Nathan Vertile and the countless YouTube videos I used as guides for this post.

]]>https://bentuino.com/2016/11/22/quadcopter-beerotor-victory210/feed/0A DIY security video camera recorder (part 2) – beaglebone black hosthttps://bentuino.com/2015/05/04/dvr-sec-part-2/
https://bentuino.com/2015/05/04/dvr-sec-part-2/#respondTue, 05 May 2015 05:11:09 +0000http://bentuino.com/?p=642In part 1 of this series I demonstrated how ffmpeg can be used to dump live video streams from IP cameras to a hard drive. In this post I will show how a Beaglebone Black board can be used to build a cheap and energy efficient video recorder.
Given that the recorder is not re-coding any of the camera streams the CPU requirements are quite moderate. The processor only collects the streaming data and copies them to a hard drive. Hence using a Mac or PC as a host platform is quite an over-kill. Also from an energy and cost point of view a smaller size computer is a much better fit. Embedded systems like the Rasberry Pi or Beaglebon Black should be perfectly capable of handling this task at a fraction of the cost. So in the next few section I am going to walk you through the process of setting up such a IP-DVR system.

The Beaglebone Black (BBB) comes with a single USB 2.0 host and Ethernet port. For our setup we need at least 2 x Ethernet ports. One to connect the camera (LAN Port) and one for the connection to the internet (WAN port). The easiest way to add the second Ethernet port is the buy a USB-RJ45 Ethernet adapter. However this would occupy the USB 2.0 port so we also need a USB hub to add an additional port for the hard drive.
Fortunately there are combined 3-Port USB 2.0 Hub with RJ45 Port offered at your local computer store or on-line. They give you flexibility as you will have spare USB ports to add WIFI or other USB devices in the future.

Software

The following description assumes the latest BBB Debian Linux installation. If you are still using Angstrom please install the Debian Linux. No worries, it is very easy to do and there are many description out there that walk you through the steps. I just give an outline here assuming you use a Windows machine to write the Micro SD card.
Pull the lates image from the official site: http://beagleboard.org/latest-images. Then unpack the image with 7-Zip. You can now write the img-file with a utility like Win32DiskImager or WinFlashTool to your microSD card. Once the memory card is written you insert it into the BBB. Connect a USB hub with a keyboard and mouse and hook a Monitor to it. You are now ready to power the BBB up.
After a while the Linux environment should be visible on the screen.
If you use a SD card that offers more than 4GB of space like me you also want to increase the BBB Image Disk Space. First make sure you boot from the mircoSD card, then adjust the Linux partition with fdisk.

fdisk /dev/mmcblk0p

execute the following single letter commands inside the fdisk utility:
1) Delete the second partition: d, 2
2) Create New Primary Linux Partition: n, p, 2
3) Write new partition table to disk: w
4) Exit fdisk: q
reboot and then adjust file system to use the extended partition:

resize2fs /dev/mmcblk0p2

reboot a second time so the change can take effect. You should now see the difference using the disk free utility:

df

Connect the BBB to the internet and update the package list:

sudo apt-get update

Before we start to install additional drivers we need to make sure the build tools and header files are installed:

USB-Ethernet Driver

Now that we have an up-to-date Linux system we can start to install the drivers of the additional hardware. I will start with the USB-Ethernet interface first. My 3-Port USB 2.0 Hub with Ethernet Port uses the ASIX controller. To install the drivers follow the steps outlined below. Download the driver source from the ASIX’s web site, unpack the source code and compile it. Then install the driver:

Plug in an Ethernet cable connected to your network and activate the interface:

ifup eth1

The device should now fetch an IP address and once successful you are connected to the Internet.

The USB-WiFi Driver (optional, only required if you need support for WIFI)

The next driver we are going to install is for the USB TP-LINK TL-WN725N Wifi Dongle.
Important to know: there are TWO versions of the “TL-WN725N”, one needs the RTL8188CUS driver, the other needs this RTL8188EU. See wikidevi.com/wiki/TP-LINK_TL-WN725N_v1 and wikidevi.com/wiki/TP-LINK_TL-WN725N_v2 for differences.
These instructions are for the RTL8188EU version. Before you start confirm that your TP-LINK adapter is based on a RTL8188EU Realtek controller. Plug in the adapter and checkwith the following command:

The system is now configured such that we can bring up the wireless connection:

ifup wlan2

You can take down eth1 (ifdown eth1) before bring up (ifup) wlan2.

Webmin

I was looking for a tool similar to OpenWRT’s LUCI that allows me to administrate the BBB Debian Linux from a web browser. I settled on Webmin. Please leave a comment if you have a better recommendation.
Webmin allows you to manage all to most common Linux services like retworks, firewalls, routing, sql, HTTP……. from simple web forms.
We are going to install Webmin via APT. The first step is to edit the /etc/apt/sources.list file on your system and add the lines :

Now that all the tools are in place you can just follow the instruction of part 1 to capture and dump the video to the hard drive.

Conclusion

In this blog we learned to build a simple BBB based IP video recorder. With Debian Linux as the baseline I demonstrated how to install all the additional hardware drivers, tools and software such that the resulting server is able to record IP based video streams to a hard drive for a cost of less than $100 dollars.

Credits

To all the web sites, blog and forum posts I missed to record so that I could credit them here. To debian.org, elinux.org, webmin.com, ffmpeg.org, firehol.org and all the other contributing opensource communities that jointly created all the software used in this post.

]]>https://bentuino.com/2015/05/04/dvr-sec-part-2/feed/0A DIY security video camera recorder (part 1) – the missing newspaperhttps://bentuino.com/2015/05/02/dvr-sec-part-1/
https://bentuino.com/2015/05/02/dvr-sec-part-1/#commentsSat, 02 May 2015 17:25:48 +0000http://bentuino.com/?p=591Over the last few month 1-2 a week our newspaper was missing. This, most of the mornings, really ticket me off as it disrupted my breakfast routine. A while later I got a letter from the courier announcing that in our neighborhood newspapers get stolen.
I need my morning newspaper even though there is hardly any news in there. I considered cancelling the subscription but realized that I was not ready to let go of this habit. I also grew curious who would steal newspapers when most of the news was freely available on-line. Maybe one of my lovely neighbors had a dark side. So I took the challenge and set out to solve this mystery.
I ordered a Samsung SNH-P6410BN in-door and Samsung SNH-E6440BN outdoor wireless IP security camera. These are really great Hi-Def cameras with a wide field of view and good picture quality during daylight as well as at night.
The camera comes with pretty decent cloud support and an Android and iPhone app. It can store the video feeds to microSD cards that can be inserted into the cameras. However I did not want to fiddle with SD-cards as the camera is connected to my network and I hoped that additional software could help me out.
I was intrigued by 3rd party Video Software like BlueIris that could in fact connect to my cameras video streams.
While setting up my camera with BlueIris I realized that the camera is able to stream video in any of the following resolutions:

This is no where documented in the product manual that shipped with the camera. Anyway, I managed to open the camera streams in VLC and watch the live feed using a URL like this:

rtsp://admin:YOUR_PASSWORD@192.168.1.100/profile5/media.smp

However I was mostly interested in dumping these streams to a hard drive so that I could zap through them with VLC. That is when I started to look into ffmpeg.
What a tool this is! The Swiss-Army knife of Video. Is there something that cannot be done with this utility? However, the flexibility comes at a price. There are so many options and parameters that exploring them feels like an entry riddle to a secret society. That said, the ffmpeg user community is large and there are many example and posts that are available on the internet to get you started.
So here is a simple command that dumps my stream:

This line dumps the input video stream into the file VideoDump.mp4. The option “-vcodec copy” makes sure that the stream is not re-coded so the process hardly takes any CPU resources. This worked really well. However the files started to become big as a 1920×1080 stream uses about 1 GByte of hard disk space per hour. Is there a way to split the files into 1hour segments? You bet!
The following command line will dump segments of 1 hour:

The segment time is specified with the option “-segment_time 3600” that takes seconds as the argument. The option “-segment_time_delta 0.03″ allows the utility some 0.03 second flexibiliy where to cut a segment so it can do it at a key frame. The option ” -reset_timestamps 1″ will reset the time inside a segment to start at 00:00. Also the segments get numbered. The segment files are named like this:

VideoDump_000.mp4
VideoDump_001.mp4
VideoDump_002.mp4
:
:

The amount of video data I collected was rapidly growing and I was interested to start and turn off the capturing at define moments. Sure ffmpeg can do this:

Adding the option “-ss 00:00:00 -t 02:30:00” will capture 2.5 hours of footage and then stop. I then used a cron job on my Mac to start the stream capturing.

In summary ffmpeg works great with the Samsung IP cameras and allows to capture videos exactly during the hours of interest.

So coming back to the missing newspaper, you wonder who the culprit was? Well to my surprise there was no thief. The footage clearly revealed that the newspaper never got delivered the days it was “stolen”.

]]>https://bentuino.com/2015/05/02/dvr-sec-part-1/feed/2Logging Weather Data to the Cloudhttps://bentuino.com/2015/03/18/logging-weather-data-to-the-cloud/
https://bentuino.com/2015/03/18/logging-weather-data-to-the-cloud/#respondWed, 18 Mar 2015 17:56:24 +0000http://bentuino.com/?p=581In this post I want to report some of the finding from a 4 month experiment with a Spark Core. The core is uploading pressure measurement values into the cloud every five minutes. It then loggs them into a Google Spreadsheet. I use the Spark Temboo library and service after I failed to reliably poll the core from Google.
Anyway the Spreadsheet has now more than 30,000 entries. The chart generation is a bit slow but everything is still running stable to this day. A plot of the 4 month is shown below:
After a measurement is taken the core goes to deep sleep to conserve energy. An STM103 internal HW timer interrupt is used to wake-up in time for the next measurement.
Over the four month I have seen only a few corrupted values. These are most likely transmission errors due to network connectivity issues.
]]>https://bentuino.com/2015/03/18/logging-weather-data-to-the-cloud/feed/0PCB Design Workshophttps://bentuino.com/2015/03/04/pcb-workshop/
https://bentuino.com/2015/03/04/pcb-workshop/#respondWed, 04 Mar 2015 23:46:32 +0000http://bentuino.com/?p=601Last weekend I attended a cool 1 day workshop “Designing a Circuit Board” given by Matt Berggren. Matt is a member of supplyframe San Francisco with many years of experience as a PCB designer and instructor.
The class is positioned as “Learn to Build a PCB from the ground up…” targeting hackers and professionals that want to tip their toes into the water of hardware design. This was the 4th installment of this class that always fills up withing a very short time.
Matt is an engaging presenter. He spent the morning explaining the fundamentals of PCB boards and technology. The class does’t assuming an EE degree so Matt is careful to explain the fundamentals and terms relevant for PCB design. In fact he is quite a master in catering to the beginners and more advanced members of his audience.
Here is an overview of the topics Matt covered in the morning:

The afternoon was mostly spent hands-on working with Eagle. Here is what we covered:

Build our first schematic + PCB + CAM (simple USB power supply that generates some very basic voltages we can use on the bench to do stuff – very simple USB->LDO->Connector)

Looked at Eagle and learn some important Eagle terminology, basics of the menus, command line interface, shortcuts, etc + basic workflow (should prepare you for doing this on your own)

Cudo and thanks to Matt. He runs these classes for free at weekends. His audience’s backgrounds are very divers. Some are complete electronic novices and some are pros. Matt masters this challenge by providing a lot of well selected practical technical information with entertaining anecdotes. Great teaching job.

]]>https://bentuino.com/2015/03/04/pcb-workshop/feed/0Updated Temboo library availablehttps://bentuino.com/2015/01/19/updated-temboo-library-available/
https://bentuino.com/2015/01/19/updated-temboo-library-available/#respondTue, 20 Jan 2015 05:09:18 +0000http://bentuino.com/?p=579I finally found some time to fix the problems with the Spark Temboo library. The following issues were fixed:

]]>https://bentuino.com/2015/01/19/updated-temboo-library-available/feed/0Temboo ignited with a Sparkhttps://bentuino.com/2014/06/04/temboo-ignited-with-a-spark/
https://bentuino.com/2014/06/04/temboo-ignited-with-a-spark/#commentsWed, 04 Jun 2014 18:28:54 +0000http://bentuino.com/?p=540This is a re-post of an article I wrote as a guest blogger for Temboo’s blog.
I am working with connected devices and was looking for a cloud service. While surveying the field Temboo caught my eye because of the large number of supported premium web sites and the promise to connect IoT devices to the Internet in a breeze. The connected device I am using is a Spark Core. The Spark Core is a sleek small board that offers a powerful 32 bit ARM CPU paired with WiFi. The product grew out of a Kickstarter campaign and is rapidly gaining in popularity. The Spark is nicely priced and everything is open source. The team supporting the Spark Core is smart and supportive and made a great choice to port most of the main Arduino APIs to their platform.
As outline in a blog post here migrating Arduino Libraries to the Spark Core often turns out to be pretty easy. With Temboo providing an open source library for Arduino I was tempted to give it a try. However, I had no Temboo-Arduino setup so I was not sure how hard it would be to get it all up and running.
Well, I am happy to report that is was easier than expected. Temboo’s code is well written. I only had to work around some AVR specific optimizationsthat Temboo did to save program memory. As the Spark Core is built around a STM32F103 chip resources are not as tight as with the AVR so I simply bypassed these optimizations.
Here are some brief instructions how to install the Temboo Arduino Library. The instructions use the Spark command line SDK setup:

to change the example that is built, edit the first line in the core-firmware/src/build.mk file:

CPPSRC += $(TARGET_SRC_PATH)/application_gxls.cpp

or

CPPSRC += $(TARGET_SRC_PATH)/application_gmail.cpp

Building this code was tested under Windows 8.1 using cygwin and the MINGW version of the ARM GCC compiler tool chain. It should be easy to use this Temboo Library with the Spark Cloud based SDK. To configure the Library to support Spark all the is required is to define the following label:

CFLAGS += -DSPARK_PRODUCT_ID=$(SPARK_PRODUCT_ID)

or add a

#define SPARK_PRODUCT_ID SPARK_PRODUCT_ID

to the source code. Temboo support for the Spark Core is a lot of fun. It is easy to setup your own Temboo account and compile the Temboo Arduino Library that now supports the Spark Core platform. To learn more about similar projects please visit my blog at http://bentuino.com.

]]>https://bentuino.com/2014/06/04/temboo-ignited-with-a-spark/feed/13Google polls Spark Corehttps://bentuino.com/2014/05/31/google-polls-spark-core/
https://bentuino.com/2014/05/31/google-polls-spark-core/#commentsSun, 01 Jun 2014 00:22:16 +0000http://bentuino.com/?p=483In a previous blog post I was describing an example of how a Spark Core can be used to read weather sensors. The setup was really no different from any simple Arduino Uno setup. It only demonstrated how easy it is to port Arduino Sketches to a Spark Core.
With the integrated WLAN I was interested to connect the Spark Core to the internet cloud. One of the simplest ways I found, was using Google’s Spreadsheet service. I stumbled over this idea in this Spark forum post.
Here is how it works: a Google Script is periodically reading data from the Spark Core via the RESTful Spark API and then appends the data to a Spreadsheet. The code below is a minimalistic Spark code to test the such a setup:

However when I setup a time trigger to run the script in regular intervals I found the setup to be very unreliable. This is discussed and documented by several Spark Users and as of this writing I have not seen a fix for this problem.
One thing to note is, that this approach is pulling data from the Spark Core rather than the core pushing them to the cloud. This has a significant flaw as we cannot put the core into standby between the measurement intervals. Therefore this solution is anyway not a good choice for low power applications.
So stay tuned, I am experimenting with a better solution that I will blog about in my next post.

]]>https://bentuino.com/2014/05/31/google-polls-spark-core/feed/2Using Arduino code on Spark Corehttps://bentuino.com/2014/04/24/using-arduino-code-on-spark-core/
https://bentuino.com/2014/04/24/using-arduino-code-on-spark-core/#commentsThu, 24 Apr 2014 20:03:28 +0000http://bentuino.com/?p=425In an earlier post Spark Core Weather Station I presented code that was reading weather sensors and sent the data over USB to a PC terminal. However the approach I took there to combine all code into a single file is not very practical. So now that the Spark IDE supports multiple project files we can just include Arduino library files.
So here are some hints how to get Arduino library code and sketches to compile in the Spark framework. I use a TMP102 I2C temperature sensor to demonstrate the porting. Below is an example Sketch that reads the temperature values and sends them to the serial interface:

The main reason this code fails to compile is the Arduino Wire.h library include statement fails on the cloud based Spark Core IDE. The TMP102 sketch code use I2C. So it includes the Arduino Wire Library with the following line:

#include <Wire.h>

This triggers an error in the Spark IDE. To solve this problem I created a new library named Wire.h with the following content: