Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

Tuesday, 18 July 2017

Udoo X86 Power On / Off via BLE on Arduino 101

I finally received my UDOO X86, I backed on Kickstarter on April 2016!

To give a little of context, it is a board designed by UDOO sporting an Intel x86 CPU (64bit, different depending if you have a BASIC, ADVANCED or ULTRA), 2/4/8GB or RAM (soldered) and a LOT of peripherals and I/O.
To mention some of them:
  • M.2 Key E port
  • Gigabit Ethernet
  • 3x USB 3 Ports
  • 1 HDMI and 2x DisplayPort
  • GPIO
  • 2x COM ports
  • RTC
  • I2C

In addition, they managed to put on the same board a Genuino/Arduino 101 board (Intel Curie), with BLE and 6 axis accelerometer & gyroscope.
Everything on a board more or less twice the size of the RaspberryPi.

More details can be checked on the official documentation page on the UDOO site.

I am writing this tutorial from the board itself and I can tell it can be used as desktop/HTPC without any major issues.

One cool feature of the Arduino 101 is it is able to Power On/Off the main CPU via Interrupt!

I am going to tell you how to be able to remotely power on and off the main CPU via BLE.

I am using LUbuntu 16.04 as OS, but those instructions should work pretty well on any operating system, even MS Windows.

Grant Power management to Intel Curie


Verify the BIOS/EFI settings are as shown in this page.

Prepare the Arduino environment


Install the Arduino IDE from the official site and install the Intel Curie Arduino 101 Libraries & Tools. You could do the same with PlatformIO, but I am not quite sure about the Intel Curie support.

Check you select the correct board type, programmer and serial port in the Tools menu.


Remember to give your user the rights to write to the serial port executing:

sudo usermod -a -G dialout

You have to logout to make those changes taken into account.

In addition to that, it could be necessary to execute the following script:

wget -O - https://raw.githubusercontent.com/01org/corelibs-arduino101/master/scripts/create_dfu_udev_rule | sudo bash

This is required to make the Arduino capable of resetting the board to put it in programming mode.

Check everything works fine uploading a simple example sketch (pick the Basic/Blink one).

The blinking led is the one close to the HDMI port

Upload the sketch to receive commands from BLE

Let's start with a skeleton sketch Intel prepared for us.

Choose the example from CurieBLE/Peripheral/CallbackLED.

Upload it to the board.

Follow the instructions shown on this page to configure the Android application.

All you need to do is to pair to the Arduino101 BLE device, which will be shown as LEDCB.
Once you're connected, you'll be able to write 0 or 1 to a variable exposed by the service implemented in the sketch.
The variable will power on and off the LED depending on the value of the variable.

Adapt the sketch to send a Power signal to the main board


We need to add a simple function to send a LOW digital signal for 20ms on the PIN number 9, followed by a HIGH digital level.
This generated wave will be caught by an intermediary SMT32, which will send the power interrupt to the Intel Atom/Celeron/Pentium.



The whole board will react on the interrupt, including the Arduino 101, which will be restarted, losing any unsaved state.
It means everything which follows the execution of the function sendPowerSignal is actually useless, as the Arduino 101 will reboot.

Issues (2 May 2017)


I am unable to fully verify it is working since on shutdown the board actually gets powered on.
Possible root cause:

  • BLE is interacting with the PIN number 9
  • When the Arduino 101 is reset, the PIN 9 goes again low triggering a power on

Those facts seem not impacting just my board, as I found a forum post you can check here where another user faced the same problem.

I can also confirm that if I suspend the system, the Arduino 101 is no more visible on Bluetooth, so it means it gets powered off.

UPDATE (3 May 2017)!

I've been in touch with UDOO team and they provided a revision of the BIOS for testing purposes only.

The problem is partially fixed and I'll keep you posted to let you know when we will have this example fully working.

UPDATE (18 July 2017)!

I've received a BIOS 1.03 RC version to test if the mentioned issues are fixed.

And we have good news! Everything works as expected!

I let UDOO send the changelog of the latest BIOS as soon as it is officially out, but I can confirm you'll be able to use the Arduino 101 to properly power up and shutdown the main board.

The power management via Intel Curie can be now left enabled and flashing the Arduino 101 or rebooting will no more generate issues (reboots).

The problem has been solved making the power signal trigger sequence more complex (5 HIGH to LOW transitions within 100 ms, instead of a single transition).

If you're using a desktop linux distribution (e.g. Ubuntu), please check the power management rules and set "When power button is pressed" to "Shutdown" or "Suspend", depending on what you prefer).

Otherwise, you will get a dialog, as in the following video... 





Sunday, 14 April 2013

Adding Serial/Bluetooth support to Desktop Defender [Part I]

If you have got a spare Arduino board and/or a Bluetooth shield...
Why do not buy a Missile Launcher and mod it a little?



You can find "Desktop Defender" toy on ebay.

First of all, you will need to open the control pad. You'll find a 7 pin connector. My idea is to do not break the control pad. I want to add an extra input method to it. So... Let's solder them.


The control pad:
  • Closes the circuit between -3V and DO (Down), L (Left)
  • Closes the circuit between +3V and UP (Up), R (Right), PLA (Play)
We will need to replicate this on Arduino side.




The issue is... We cannot control a DC Motor directly via Arduino. In this particular case the +3V would be compatible with Arduino (Nano or Pro, for example). The current is the issue. The motors are protected by 2 limit switches for each direction, so they will not stall (the motors reach peak current draw when stalling), but as my "dumb" tester says... There are still 90mA when closing the circuit. Which is more than the maximum allowed for I/O Pins (e.g.: 40 mA).


There are different options for driving DC Motors safely:

  • PWM (Pulse-Width Modulation)
    • But we do not need to drive speed of the motor... Overkill.
  • DC Motor controller (H-Bridge)
    • Same as above
    • Details here
    • Products: L293D IC or Pololu shields
  • MOSFET, Transistor + Diode (To protect for spikes at on/off time)
    • Good solution, cheap... But we must size the Transistor, Resistance correctly
    • Good explaination here and here
  • Optoisolators
    • Details here
    • I just discovered them... Amazing! In few words... It allows to drive the current on another circuit using a LED and... A phototransistor on the other side. We can call them also photocouplers.
    • Each product has its own maximum voltage and current.
    • It is a good choice, cheap, reusable. Available products: optoisolators, opto-isolator shield, etc...
  • Relay (and solid state Relay)
    • A low current driven mechanical switch. It is a good choice, cheap, reusable.
    • In the case of solid state... It is not mechanical... Extended lifetime and faster than common relays.
    • Each product has its own max voltage and current.
    • Good choice as above. Available products: Solid State Relay, Relay Shield for Grove, etc...
My choices are optoisolators, relays (I found a L293DNE on my magic box, hurray... But I am unable to use it, except if I completely remove original control pad).
Since I will wait for parts to be shipped, see you in few days/weeks!

Ok people... SainSmart come in my help!

I just tested using a single Relay and my Bluetooth Silver Mate.
It works! Here you are the code... I'll deploy everything on github (both Arduino and Android code).


A video and photos in next days...

Tuesday, 28 August 2012

Softmodem communication on Android

One of the projects I would like to proceed but I am a little stuck due to limited amount of time...
Being able to communicate between Arduino devices and Android via audio cable.
The idea is simple (and not mine): modulate a carrier wave using frequency changes in correspondence of binary data changes. It is called Frequency Shift Keying.
Obviously, transmission data rates are not suitable for media streaming, but enough for trasmitting small amount of information like commands, data from sensors connected to Arduino board, etc....



There is a similar project, called Androino. Another working example, this time on Apple hardware, is IR-Remote.
I think it was a university project but I think it has been abandoned. Source code is available but I wasn't able to make it work.

Hardware

On the hardware side, all I bought is:

Software

Talking about the software, the Arduino code is ready and available as serial interface. It has been developed by ARMS22 (authors of the board too). It is available on this website. They focused their attention on iPhone, but I want to make it work on Android.

An Android client existed too, but it has been removed from the website. For receiving data on Android, the main idea is to use the Audio API to record chunks of audio, perform a zero crossing algorithm on it to store the "distance" between crossings. Then perform an RLE to translate it into valid byte values.
This will be packed into a threaded library offering an input and an output queue as interface for reading incoming data.
For sending data, some code in Javascript is available and it should not be too difficult to implement it in Java.

The issue can be the battery consumption, since we are continuously recording&processing Audio, having no interrupt on Android side.
I am sure an ADK board is the best way to communicate with Android, but it wouldn't be cross-platform and cross-device.