Raspberry Pi & PHP & Swift

I may have mentioned in previous posts that I’m working on a PHP port of my MonoPi and jsRPi frameworks for the Raspberry.  The project is WELL underway and a great deal of progress has been made. The core and some of the extensions are already done and I’m now beginning work on the “Components” and “Devices” portions of the framework.  Also, I just read a really interesting article about getting Apple’s Swift compiler running on the Raspberry Pi 2 (will also work on the Pi 3).  I’ve been wanting to try out Swift for a while now but none of my Macs are new enough to run new enough versions of XCode to get the Swift toolchain.  However, Apple recently open-sourced Swift, and luckily plenty of people have already gotten to work porting it to other platforms such as Linux and now there is a working port for the ARM7 architecture under Linux.

This pleases me.

One of the things the article mentions is a need for libraries that allow access to Raspberry Pi hardware such as GPIOs….

Well… As you can imagine, this is a bit like the perfect storm for me.  I get to learn and code in Swift *and* port my framework to Swift at the same time. Boom. So now how am I going to go about this?  Well since I can’t really use my Mac for the dev work, I *can* use my PC running Linux and thankfully this fella built an Atom addon for Swift dev and debug that I can use for exactly that. I am so excited I can barely stand it.  Now I gotta hurry up and get this damn PHP port done so I can start on it.

 

UPDATE: Turns out you can do unit testing in Swift under Linux too.  Apparently, Apple also open-sourced XCTest.

Wednesday, April 6th, 2016 Hardware, PHP, Programming, Raspberry Pi, Swift No Comments

CyrusBuiltHTPC v2.0 Released!

I’m happy to announce that the new version CyrusBuiltHTPC has just been released.  Version 2 is an extensive overhaul that fixes the ATX PMU firmware, upgrades from XBMC to Kodi and if you are still running Raspbian “Wheezy”, the setup scripts will upgrade you to Raspbian “Jessie” (Kodi v15.x works best on Jessie).  This build of Kodi fixes the “Black Screen” issue that would occur when exiting Kodi.

Wednesday, December 2nd, 2015 Arduino, C/C++, Hardware, Programming, Raspberry Pi No Comments

Joystick Library for Arduino

In my previous post, I briefly mentioned that I had released a joystick library for Arduino.  I thought I oughtta expand on that a bit, especially since I use it quite a bit these days.  I’m the CTO of the family landscaping business.  One of the services we provide is snow removal.  As such, we have multiple snowplows.  All of the plows have hand-held controllers that control blade movement (raise, lower, pan left, pan right).  One of the controllers blew up, so we ordered a new one.  The new one blew up too.  So we got copies of the schematics and went over it with our mechanic looking for wiring faults that may be causing the failure.  We couldn’t find anything.  We then manually manipulated the plow by shorting wires in the wiring harness and in all our testing did not encounter any problems.  We had the last controller replaced under warranty.  After a couple of weeks, the replacement blew up too.  So I tore it apart and discovered that it was basically just a microcontroller that read button inputs and then triggered one or more solid-state relays to control the plow.  The problem was, I could not find any protection circuitry on the outputs.  So, when the magnetic fields collapse for the pump motor or solenoids, there is some reverse-biased current that flows back into the system.  Without any suppression circuitry (ie. “clamping” diode) and no reset-able fuses or anything, it eventually damages the board.  Each of these controllers was about $486.00 cost to us.  So eventually, we decided we could build our own better controller, and we could do it significantly cheaper using an Arduino-based solution.

So that is exactly what I did.  All the other controllers used a D-pad arrangement; Soft-membrane buttons for each direction.  I opted for a thumbstick because I felt it would be easier to water-proof (not necessarily true as it turns out) and would be easier to manipulate and potentially allow for finer-grained control of the plow.  So I went with Arduino Uno R3, a Sparkfun ProtoShield , and a SparkFun Thumb Joystick which I soldered to the protoshield.  The thumbstick is essentially just a couple of potentiometers (one for each axis) that act as voltage dividers.  I needed a way to read the analog values for both pots (axis) and then normalize the values to range from -100 -> 0 -> +100.  Naturally, I went looking for an Arduino library that could do this work for me.  I found a library that *almost* met my needs.  The problem with it was it did not process events immediately. Instead it would only emit a single event after processing all the possibilities.  So I decided to write my own library instead.  My library emits *all* events as soon as they are detected.

You can use it as described below.  The first thing you’ll need to do, is download and install the library.  Next, wire up a thumbstick to an Arduino like so:

joystick

 

(Note: You can use whatever analog inputs you want, I just used A0 and A1 as an example. However, you MUST use analog inputs.)

Now, you can calibrate it and start getting readings.  It is important to note that you should not touch the joystick while the sketch is starting up. The calibration process takes current readings from the stick and computes new center, stroke, and threshold values based on these readings.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "Arduino.h"
#include "JoystickLib.h"
 
Joystick stick(A0, A1);
 
void setup() {
   Serial.begin(9600);
   while(!Serial) {
      delay(10);
   }
 
   // Calibrate the joystick. For this to be effective, the joystick should
   // be resting at its center position.
   stick.calibrate();
}
 
void loop() {
   // Both axis values should be:
   // Center = 0
   // Farthest left (X) or farthest down (Y) = -100
   // Farthest right (X) or farthest up (Y) = 100
   // Or any value in between. Make sure you call loop() first.
   stick.loop();
 
   // Print the X-axis value.
   Serial.print(F("X = "));
   Serial.printlin(stick.getX());
 
   // Print the Y-axis value.
   Serial.print(F("Y = "));
   Serial.println(stick.getY());
   delay(500); 
}

You can also test what direction the joystick is in like so:

 

1
2
3
4
5
6
7
if (stick.isUp()) {
   Serial.println(F("Stick is up"));
}
 
if (stick.isDown()) {
   Serial.println(F("Stick is down."));
}

Or you can handle events. These events include: when the joystick moves in any direction including diagonals and does so in +1 or -1 increments (in other words, a movement of only +1 on the Y-axis would be considered an “up” movement) and when the joystick goes neutral (returns to zero on both axis). The method signature for the event handler callbacks do not currently pass any event objects, so it only needs to be a void:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void printPosition() {
   Serial.print(F("X: "));
   Serial.println(stick.getX());
   Serial.print(F("Y: "));
   Serial.println(stick.getY());
   Serial.println();
}
 
void onUpHandler() {
   Serial.println(F("Direction: Up"));
   printPosition();
}
 
void onDownHandler() {
   Serial.println(F("Direction: Down"));
   printPosition();
}
 
void setup() {
   Serial.begin(9600);
   stick.calibrate();
   stick.onUp(onUpHandler);
   stick.onDown(onDownHandler);
}
 
void loop() {
   stick.loop();
   delay(300);  // Delay not necessary.  Just added to make it easier to read the output.  
}

Given the sensitive nature of the events, it may be best to determine a threshold value and then compare the axis value against it before reacting to it:

 

1
2
3
4
5
6
7
8
const int AXIS_THRESHOLD = 30;
 
void onUpHandler() {
   if (stick.getY() > AXIS_THRESHOLD) {
      // Do stuff only if the Y-axis is greater than 30.
      // This way we know the movement was more deliberate.
   }
}

For my application, I used event handlers and forced cardinal direction movement only, then fired one or more SSRs based on which direction the user was trying to move the plow. These SSRs, in turn, triggered solenoid(s) and the pump motor (except when lowering the blade) to allow the hydraulic fluid to move the arms.  You can increase or decrease the sample rate by using delay() inside your loop() method.  In the future, this will be option in the library itself.

Have fun and happy hacking!

Wednesday, December 2nd, 2015 Arduino, C/C++, Programming No Comments

Interfacing with a Raspberry Pi using NodeJS

Well…. I’ve been gone waaaaayyyy too long.  I’ve been on an extended hiatus while my personal life self-destructed, then began to rebuild, then had a serious car accident, then ended up battling major health issues (chemo is a bitch), and then the road to recovery.  The good news is, my hands have been anything but idle.  During all that I pushed out another release of my MonoPi framework, a joystick library for the Arduino, another release of my CrystalFontz LCD library for Arduino, and finally: a NodeJS framework for the Raspberry Pi, which is essentially a port of my MonoPi framework to NodeJS.  I call it jsRPi.  Yes, there are a couple other Node modules that exist for interfacing with a GPIO, but with all due respect to their authors, I find them lacking for my purposes.  MonoPi and pi4j offer a wide breadth of functionality that the existing modules for Node simply don’t have.  All of the existing modules I found offered only the most basic read/write capability for the GPIOs.  jsRPi, on the other hand offers that plus various system utilities, hardware abstractions for relays, motors, LEDs, etc and device interfaces for PiFace, PiCamera, PiBrella, sprinkler control, etc.

The reasons I decided to take on such an ambitious project were:

  • I wanted to teach myself NodeJS (and become more proficient with JavaScript in the process).  Porting a large framework like MonoPi seemed like a good way to do this.
  • No other modules/libraries/frameworks as extensive as MonoPi exist for Node.
  • I ultimately intend to write a web app using NodeJS and Express and React.  Being able to write the entire thing in JavaScript would be a huge win.

Getting Started

Head over to my github repo and download the source or clone the repository, then from a command line, navigate to the jsRPi folder (as of this writing, the framework is still an Alpha so I have not published an npm module yet).  Then follow the instructions in the README to install dependencies and build the source.  I should note that the term “build” when in comes to jsRPi really just means check all the syntax, generate API documentation, run unit tests, and produce an optional version of the framework “compiled” into a single file.  Build tasks are executed using Grunt.  If you don’t already have Grunt and grunt-cli, it will be installed when you run the appropriate install_deps script.  You can also run just the unit tests by entering the following command from the command line (from within the jsRPi root directory):

 

1
grunt nodeunit

 

Blink Example

The following example shows how you can blink an LED.  This example assumes you have an LED and appropriate resistor connected to GPIO-00:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';
var jsrpi = require("jsrpi");
var GpioPins = jsrpi.IO.GpioPins;
var PinMode = jsrpi.IO.PinMode;
var PinState = jsrpi.IO.PinState;
var GpioStandard = jsrpi.IO.GpioStandard;
var LEDComponent = jsrpi.Components.Lights.LEDComponent;
 
// Setup the pin.
var ledPin = new GpioStandard(GpioPins.GPIO00, PinMode.OUT, PinState.Low);
 
// Create an LED and attach it to the pin.
var led = new LEDComponent(ledPin);
 
// Blink the LED once per second, for 5 seconds. This is an asynchronous operation.
led.blink(1000, 5000);
 
// Destroy the LED. Note: You do not need to call dispose() on the pin. It gets disposed by LEDComponent.
setTimeout(function() {
   led.dispose();
}, 6000);

Again, this framework is currently an Alpha release, so I expect there are probably bugs, particularly in the parts I have not yet been able to test for lack of required hardware. Future plans include, refactoring to be ES6-compliant, include callbacks as optional parameters for asynchronous methods (WHY ON EARTH I didn’t do this in the first place is beyond me. Hence, disposing the LED using setTimeout() shown above), and hopefully native RS-232 serial support (present in MonoPi, but not yet ported to jsRPi). I should also mention that I’ve already begun porting to PHP as well. So keep your eyes peeled for “PHPi”, coming soon!

All of this is part of an even larger project that I’ve been prototyping with quite a bit of success:

A home automation controller using an Arduino Mega 256 w/Ethernet Shield to control power outlets (which mostly just control lights), and a REX (Request to EXit sensor) , which is just a PIR (Proximity Infra-Red) sensor that triggers an onboard relay.  The Arduino has its own built-in web interface for configuring settings like the network interface (static IP or DHCP, etc), and ultimately communicates with a Command And Control server running on a Raspberry Pi with Mosquitto (an MQTT service), which I use to send commands to and get status from, the Arduino.  Then a small web app also runs on the Pi that communicates with Mosquitto to provide a GUI that can run from a phone, tablet, laptop, whatever and control the lights. It also has an “away” mode which makes use of the REX. When you leave, you put it in “away” mode and then walk out the front door.  When you come back through the door, the REX sees this and switches on the lights for you automatically and switches “away” mode back off.  Pretty slick.  All of the pieces of this project will eventually be detailed here and published to my github page as I complete them.  Stay tuned!

Tuesday, November 24th, 2015 Arduino, JavaScript, NodeJS, Raspberry Pi No Comments

Controlling a CrystalFontz 16×2 serial LCD with Arduino

While digging through a box of parts, I came across an old CrystalFontz 632 (16×2) intelligent serial LCD display.  With all the recent work I’ve been doing with Arduinos and Raspberry Pis, I thought it would come in handy.  Most LCD displays designed to work with Arduino require quite a few I/O pins (more than I’d care to sacrifice for most projects), so I thought a nice serial LCD would be a lot better since I could just use 1 or 2 pins and the SoftwareSerial library to control the display.

Like I said, this thing is pretty old.  I think I bought it sometime back in 2000 maybe.  I used to use it with some software package that had “driver” that talked to the display.  The software would monitor things like fan speeds, CPU speed, temperatures, utilization, etc and spit them on the LCD.  The software was unreliable and had to be constantly re-launched.  Eventually I got frustrated with it and gave up.  But I kept the display.  I found it with some light corrosion on the bracket it was mounted to and a serial cable still attached to it that had the end cut off.

I noticed the pin header on the back that is used to provide power indicated that it just needed 5V DC.  Hmmmm…. should be easy to test then.  So I took an old power supply hooked it up and…. voila!  The screen lit up and displayed its firmware bootscreen then cleared and displayed a blinking cursor.  Awesome.  I’m in business.

So I dug out an Arduino Uno and started writing a test sketch.  I honestly had no idea how to interact with this thing, but I just figured I could probably just start out by sending some text to it and see what happens.  No luck.  I sent “Hello, World!” using the print() method of the SoftwareSerial library and it just produced garbage.  At least it received the data I guess.

I tried using different BAUD rates to no avail.  Eventually, I realized that maybe I needed to send the data byte-encoded or I probably needed to send some kind of command to it before I could use it properly.  I noticed there are solder pads on it for an SPI connection and wondered if I’d have better luck using SPI instead.  I decided not to get ahead of myself, so I went to the CrystalFontz website, which as of this writing was still up.  Joy!  I was happy to see they were still in business.  And to my amazement, they still had specs and datasheets for this display.  So I downloaded the manual for the 632/634 series.  The only difference between the 634 and the 632 is that the 632 is 2 row, 16 column and the 634 is 4 row, 20 column.  Other than that, the command set is the same for both.  As I started reading the manual, I discovered that when using logic level serial (such as with the Arduino), there are some jumpers (well… solder pads) that need to be connected.  Specifically, I needed to close jumpers JPB (RS-232 data inverted) and JPE (DATA_IN is 0v to 5v swing).

So I soldered those 2 connections and tried again. BAM!  No we’re getting somewhere!  Then I realized that every time I restarted the Aduino, it appended the text to the previously printed text and ran off the display.  Yeah…. I gotta keep reading.  So I got to the section describing the command set.  As I assumed, they were all just byte values representing ASCII commands.  For example \0001 (or Control A) sends the cursor to it’s home position (upper left-hand corner or row 0, column 0).  So I tried some commands out and eventually got to where I could print text on both lines of the display, clear the screen, print some more stuff, turn the backlight on and off, etc.  I had a lot of fun experimenting with it, and then decided I could just write a library to do all the heavy lifting for me.

I googled around and searched github first, just to make sure I wasn’t trying to re-invent the wheel and didn’t find much on using the CrystalFontz displays with Arduino and more importantly, did not find any libraries written to do the work (although I did find a couple guys had worked with them and wrote some demo sketches).  So I wrote my library and some test sketches and tried them out.  It all worked beautifully!  So I decided to publish my library to github, but first I should probably test it in a live installation in a production environment.  That’s when I ran into problems.

It all worked fine until I installed the library into the actual Arduino libraries folder and tried to run a test sketch.  I got a bunch of weird compiler and linker errors.  So I googled around and came across this post and this article and came to the conclusion that because of the “Arduino Magic” and the way the linker works, you have to include BOTH my library and the SoftwareSerial library in order to get your sketch to compile EVEN THOUGH the SoftwareSerial library is already included in mine.  Lame.

Aside from that caveat, it is a pretty robust library and provides almost the entire functionality of the 632/634 command set including drawing bar graphs, controlling brightness and contrast, scrolling, wrapping, etc.  And the best part is, you can control MULTIPLE displays from a single Arduino.  You only need a single I/O pin for each display (2 if you also want to control the backlight).  You can get it here.

It has low memory usage (estimated 128 bytes), but is a whopping ~5K in size, so keep that in mind if you are working with a large sketch and are pressed for space.  Of course, you can always just fork the library and strip out the parts you don’t need if you need to reduce its footprint.

 

Enjoy!

Monday, July 21st, 2014 Arduino, C/C++, Programming No Comments

LAMPi

I love my Raspberry Pi.  I built an HTPC around one and I use it almost every day.  It suits this purpose quite well.

But, I don’t really take full advantage of the Pi in this capacity.  Afterall, there is most of a GPIO header on that thing that I’m not using for anything.  Recently, I was working a home automation project using an Arduino.  I kept running into roadblocks concerning capacity.  If (for example) you take an Arduino Uno R3, add an Ethernet Shield w/SD Card slot and then implement the all the libraries and essentially turn your Arduino into a mini-webserver, you’ll quickly find that you don’t have a whole lot of room for your program.  And if you want to implement a library to read/write INI files on your micro SD card, you have even less room.  Even with an Arduino Mega, you aren’t left with much space to do anything really cool or complex.

Most of the code I wrote, simply wouldn’t fit on the Arduino.  Even after countless optimizations, cutting out chunks that weren’t 100% necessary, removing some error checking code, etc., I usually still came up a little bit short.  The only option was to remove functionality, split it up into chunks across multiple Arduinos.  So naturally, when you look at this from a cost perspective, it just doesn’t make sense. Enter, the Raspberry Pi.

I mean, in terms of processing power and program capacity, it’s several orders of magnitudes greater…. for $35.  Granted, these are 2 totally different platforms, but that is my point:  I was trying to use the wrong tool for the job.  *Can* it be done with an Arduino-based platform?  Given the right additional components and some clever and highly-optimized code, yes.  Or, you could just install Apache on a Raspberry Pi, and actually be able to build *real* web pages and take advantage of CSS and JS, etc and not be constrained by space problems.

It’s still small, still low power, and still network and web-enabled.  Now, there is a bit of work necessary to turn a Raspberry Pi into a webserver.  Not much more than you would on any other Linux-based machine, but if you’ve never done it before, it might seem a bit tedious and confusing.  The standard deployment is know as LAMP (Linux, Apache, MySQL, and PHP).  To automate the deployment process to make things easier on myself (and I also figured it might make things easier on the newbies to get started), decided to build a tool to do all the hard work for me.

I call it LAMPi.  You can find it on my github page.  You just download it, unpack it, then run the ‘ilovelamp’ script (the play on words was intentional) and let it do the rest.  Optionally, it can also install VSFTP server and phpMyAdmin for you as well.

Go check it out.

Thursday, March 27th, 2014 Arduino, Raspberry Pi No Comments

Arduino IDEs part 2

So I was reading this post the other day when I was trying to determine why one of my Arduino sketches was puking out garbage on the serial port.  It was a good read, and I definitely recommend you go read it too (particularly if you are an advanced Arduino programmer).  I had no idea how flawed the Arduino core libraries were.  So I went digging through the source code (why the hell hadn’t I done this yet?).  Sure enough…. yeah…. needs work.  Things have indeed improved since Alan’s post was originally written.  But, as he pointed out, the hardware serial library still needs fixing (among other things).  Nonetheless, it got me thinking…. maybe I need to “graduate” bit in Arduino-land.  So while I was googling around and reading all kinds of forum posts and talking to people on IRC, etc, one of the common things people kept talking about is just using ATmel Studio and doing direct pin access.

I had stayed away from Atmel Studio because event though it is designed to program Atmel AVR chips (which is what the Arduino platform is built on), it is not specifically geared toward the Arduino platform, and more importantly, it is essentially customized version of Microsoft Visual Studio…. thus, it is not cross-platform compatible.  In my previous post, I discussed my preferences when it comes to Arduino IDEs and the importance I place on cross-platform IDEs.  While looking into the Atmel Studio 6.1, I was reading up on the Atmel Gallery and decided to go check it out and see what kind of add-ons were in there.  Wouldn’t you know…. right on the front page was the Arudino IDE for Atmel Studio.  You know what?  This thing is BAD ASS.

I know, I know, I know…. “But it only works on Windows!”.  Yes… unfortunately, this is still true.  But I gotta tell ya… I think I like it better than Visual Micro.  If you’re a Windows user, or at least aren’t as anal about platform compatibility as I am, then you’re gonna love it.  I’ve only gotten to use to write one sketch (a BIG one) and edit a couple others, but so far…. it’s fairly superior to almost everything else I’ve used (so far).

Tuesday, December 31st, 2013 Arduino, C/C++, Programming No Comments

A Better Arduino IDE

Been a long time.  My professional duties and chaotic life have precluded me from things like blogging for a while now.  But since I’m on vacation, time to catch up!

So I’ve been questing for a better Arduino IDE.  I really enjoy the Arduino in its various forms, but I find the IDE rather lacking….. and I’m not the only one.  It seems to be a rather popular search.  Everyone is looking for something better.  I’ve seen some different forks of the standard Arduino IDE, but they all just seem to add additional hardware support or a couple small features.  None of them make the IDE (specifically the editor) any *better*.  Being a guy who spends much of his time in either Microsoft Visual Studio or Eclipse, using the standard Arduino IDE leaves me wanting more.  Sure, it is perfectly fine for beginners, but for professionals or more advanced users, it seems lackluster.

So I began my quest.  The first thing I ran across was MariaMole.  It is a much better IDE, but as of this writing, it only runs on Windows (Linux and MacOS support planned).  Also, I don’t care of the default color scheme (although still better than Arduino IDE) and I could not find an easy way to change it.  But the killer is not being (currently) cross-platform.  I develop on Windows, Linux (Mint) and MacOS X.  So I need, if possible, an IDE that can run on all 3.

Then I came across Visual Micro.  Let me get this out of the way: I LOVE Visual Micro.  It is hands-down the best IDE I’ve used for Arduino development so far.  Except for one problem: It only works on Windows.  This is because it is a Visual Studio add-on.  That in and of itself isn’t bad (because I love Visual Studio), but not being cross-platform is.  For a while, I was doing all my ‘serious’ Arduino development in Windows using Visual Micro, then just using the standard Arduino IDE on Linux and MacOS X.

Then I thought, “Hey… I bet there’s an Eclipse plugin out there for this”.  Sure enough, there is.  At first, I read these instructions and thought, “This seems like a lot of work”.  Then I saw the link for the actual plugin.  I ignored the fact that the documentation kept referencing old versions of Eclipse (as of this writing I’m using ‘Keppler’ everywhere) and proceeded to install and configure the plugin.  Still not terribly simple, but I get to use a cross-platform IDE of choice.  Also, it does not support *.ino files.  Instead, it produces ‘main.h’ and ‘main.cpp’ files.  This sucks if you need to be backward compatible with the Arduino IDE.  Also, it was fairly buggy and more often than not, I either could not get my source to build or could not get it to upload.  I read tons of stuff in forums, etc and plenty of people suggested various fixes to my various problems, but ultimately I gave up.  If I have to invest that much effort into my tools (especially on 3 platforms), then I just go find a better tool.

So I kept searching.  I eventually came across this article describing using QtCreator for Arduino development.  Fireworks went off in my head.  “OF COURSE!!”, I thought.  QtCreator is *built* for C/C++ dev and supports templates, etc.  And it’s cross-platform! I love QtCreator as an IDE in general, so I got really excited.  I went off and downloaded the latest build of QtCreator and Qt5.  I also found a QtCreator project template for Arduino here.  Even though, the documentation seems a little dated, it worked just fine.  There are some caveats: First, like the Eclipse plugin, the project template creates *.h and *.cpp files instead of a *.ino.  I chose to rename the *.cpp file to *.ino, which QtCreator is still happy to open, and then I just include it in the *.h file.  This method is also supported by the Arduino IDE, because if it finds a *.h file with the same name as your *.ino file, it opens them both in separate tabs in the editor.  I then adjust my paths depending on what platform I’m compiling on using #defines (see an example on my github page here).  I also had to create separate *.includes files for each platform.  But hey, minor tweaks to get to use a beautiful IDE.  One problem, compile/upload functionality is a bit sketchy.  Most of the time, I can get it to compile, but I usually can’t get it to upload.  So I started using QtCreator to do all the work, and then just used the Arduino IDE to compile and upload, and also for the serial monitor.  Still not quite an ideal solution.

A co-worker asked me what IDE I used for Arduino development and I pretty much gave him all the options I just laid out for you.  He decided to go the QtCreator route also.  But his inquiry renewed my quest.  So I went looking again.  That night, I stumbled across a single mention of something called ‘Stino’ in a forum post.  I decided to go look.

It was wonderful.

As it turns out, Stino is a plugin for Sublime Text.  I had never heard of either.  This was a new experience, and I was not disappointed.  I followed the instructions and went and downloaded Sublime Text 3.  Next, I enabled package control.  Then, using the package manager, I downloaded and installed ‘Stino‘.  And guess what?  Its cross-platform!! I opened existing projects on all 3 platforms and was able to compile and upload without any alterations.  In fact, the Stino plugin basically provides all the existing functionality of the Arduino IDE (including serial monitor) and is every bit as simple to use, but with a MUCH better code editor.  It supports color themes, syntax completion, etc.  It even has console output for the compile/upload process just like the Arduino IDE.  And…. it natively supports the *.ino format and uses that by default when creating projects.

I’m a fan-boy, to say the least.  Not gonna lie.  As much as I love QtCreator, I find Stino + Sublime Text 3 to be the best (cross-platform) IDE so far and I now do ALL my Arduino development using it.  Plus, since the projects it creates are basically regular Arduino projects, they are directly compatible in both IDEs.

For the life of me, I can’t figure out how there hasn’t been more buzz about this.  So…. I recommend you at least give it a try.

That being said, I’m going to get back to slinging code myself.  I’m currently working on a Christmas light controller using an Arduino Uno R3.  More on that soon!

Monday, December 23rd, 2013 Arduino, C/C++, Programming No Comments

CyrusBuiltHTPC Update

I’ve finally released a new build of CyrusBuiltHTPC for Raspian Linux.  This new build will install the latest XBMC (12.2 “Frodo”) and configure your Raspberry Pi as a full-fledged HTPC with the following features:

1) AirPlay support
2) TVHeadEnd support
3) libCEC support, so you can control it using your TV’s remote.
4) Support for relocating rootfs to an EXT4-formatted USB HDD.
5) A ~60% reduction in overall CPU usage.
6) Support for the DS1307 Real-Time Clock.
7) XBMC can now be updated just like any other package in the system via “apt-get update” or using the “systemupdate” tool installed with CyrusBuiltHTPC.
8) Reduced memory usage footprint to ~40MB on average.

NOTE:  This has only been tested with the Raspberry Pi Revision 2 Model B.  IT HAS NOT BEEN TESTED ON PREVIOUS RASPBERRY PIs AND LIKELY WILL NOT FUNCTION CORRECTLY.

This build makes use of the pre-compiled DEB packages built and maintained by Michael Gorven (cocooncrash).

Usage instructions:

Once you’ve pulled down the source package, navigate to the CyrusBuiltHTPC/CyrusBuiltHTPC folder in the terminal and then type “chmod +rx remote_install.sh”.  If you have not already done so, enable the SSH daemon on your Pi.  Then run “./remote_install.sh” in the terminal and follow the prompts.  This will push the CyrusBuiltHTPC package to the home folder of the Pi user (or whichever user you specified).

On the Pi, navigate to ~/CyrusBuiltHTPC in the terminal and type “chmod +rx setup.sh” and then run it “./setup.sh”.  This will make all the necessary scripts executable and install some system tools.  You can now run commands like “systemreboot” to reboot the Pi immediately or “systemshutdown” to gracefully power off, or “systemupdate” to upgrade and update the system.  You can also backup and restore the system configuration files modified by CyrusBuiltHTPC setup.  To proceed with installing XBMC do “cd ~/CyrusBuiltHTPC/xbmc_install” and then “./get_and_install_xbmc.sh” from the terminal.  This will add Michael Gorven’s APT repo for XBMC and then pull down XBMC and any necessary dependencies and install it all.

Once finished, you will be prompted to run the platform configuration utility.  This will install RTC support, some additional tools, configure XBMC to auto-start on boot, grant the authority to XBMC to shutdown and reboot the system, and give you the option to relocate rootfs.  This will also overclock the system to 800MHz and set the memory slice to 128MB/384MB.  As prompted, you will need to reboot the system for the configuration changes to take effect.  If you chose not to run the platform configuration utility, make sure you are not booted into desktop mode (pure console, not running X11/Xorg), and run “xbmc-rpi” to launch XBMC.  The xbmc-rpi script will store the current terminal settings before launching XBMC and then restore the terminal when XBMC quits so you are left with a black screen afterward.

I plan to make this available as a custom distribution of Raspbian in the form a disk image that you can just plop onto an SD card and go with.  But this will be a little ways down the road.  Hop on over to my GitHub page to get the latest CyrusBuiltHTPC stuff.

Enjoy!

Tuesday, June 18th, 2013 Arduino, Hardware, Programming, Raspberry Pi No Comments

HTPC Pt 3

USB-to-SATA adapter and 250GB Hitachi HDD.  Relocated rootfs to the HDD to eliminate writes and reduce reads from the SD card. The SD card is only used for bootstrap, and then hands off to the HDD.

USB-to-SATA adapter and 250GB Hitachi HDD. Relocated rootfs to the HDD to eliminate writes and reduce reads from the SD card. The SD card is only used for bootstrap, and then hands off to the HDD.

 

Raspbian up and running on the HTPC.  Once I work out on the compilation issues with XBMC 12.1, I'll post pics of that too.

Raspbian up and running on the HTPC. Once I work out on the compilation issues with XBMC 12.1, I’ll post pics of that too.

 

And there you have it.  A fully-functional HTPC (connected via HDMI to a 1080P HDTV) that also works as a full-blown Linux desktop.  CEC is also working, so if the TV is off with the HTPC turns on, the TV will turn on and switch to that input.  Likewise, XBMC can be controlled using the TV remote because the TV essentially becomes a peripheral of the HTPC via libCEC.  Thanks to my PMU, it behaves much like a PC would in the sense of power on/off, reset, auto-off on shutdown, etc.  The only thing it does not do yet is power on via remote control (…. yet).

Sunday, May 5th, 2013 Arduino, Hardware, Raspberry Pi No Comments