Categories

Program your micro:bit with the Arduino IDE

You can now use the Arduino IDE to develop and program your Micro:Bit, in my view thats a good thing to add this support as its a popular development tool that is used for many other boards

Arduino assumes there’s a ‘softdevice’ radio already installed.

Flashing a SoftDevice

This is the instructions from https://github.com/sandeepmistry/arduino-nRF5

cd <SKETCHBOOK>, where <SKETCHBOOK> is your Arduino Sketch folder:
OS X: ~/Documents/Arduino
Linux: ~/Arduino
Windows: ~/Documents/Arduino
Create the following directories: tools/nRF5FlashSoftDevice/tool/
Download nRF5FlashSoftDevice.jar to <SKETCHBOOK>/tools/nRF5FlashSoftDevice/tool/
Restart the Arduino IDE
Select your nRF board from the Tools -> Board menu
Select a SoftDevice from the Tools -> “SoftDevice: ” menu
Select a Programmer (J-Link, ST-Link V2, or CMSIS-DAP) from the Tools -> “Programmer: ” menu
Select Tools -> nRF5 Flash SoftDevice
Read license agreement
Click “Accept” to accept license and continue, or “Decline” to decline and abort
If accepted, SoftDevice binary will be flashed to the board

or

Download this zip file, extract it and drag it into your MICROBIT drive –¬†microbit-adv

Add Arduino Support

In the Arduino IDE, go to Preferences and add https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json into the Additional Board Manager URL text box.

Open Tools>Board>Boards Manager from the menu bar, search for nRF5 and install “Nordic Semiconductor nRF5 Boards” by Sandeep Mistry

Select BBC micro:bit from the Boards menu
Set SoftDevice to S110
And set the Port to the microbit com port

Code

Lets play with the push buttons

You may have to increasethe delay(150), I used this to try and get rid of simple multiple presses and switch bounce

const int buttonA = 5; 
const int buttonB = 11;
 
void setup() 
{  
  Serial.begin(9600);
  pinMode(buttonA, INPUT);  
  pinMode(buttonB, INPUT);   
}
 
void loop()
{
  if (! digitalRead(buttonA)) 
  {
    Serial.println("Button A pressed");
  }
  if (! digitalRead(buttonB)) 
  {
    Serial.println("Button B pressed");
  }
  delay(150);
}

Testing

Open the serial monitor and press the buttons

Button A pressed
Button B pressed
Button A pressed
Button A pressed
Button B pressed
Button B pressed
Button B pressed
Button A pressed
Button A pressed
Button B pressed
Button B pressed
Button A pressed
Button A pressed

A look at four Arduino related Android apps

Arduino apps on Android devices are very hit and miss they generally seem to consist of the free and open source content on the Arduino website which can be in the form of the  reference library or they can be some of the examples.

Another problem appears to be that because its free content that makes it an excuse to show way to many ads – banner ads I can handle but the pop up (interstitial ads) are frankly some of the most annoying that I have seen. Now everyone needs to make a living and a free app obviously won’t have paid purchases but this brings on to the next issue which is the lack of content – I’ve seen some with no more than 20 basic examples, full of typo’s, no schematics, poor quality schematics with mistakes, bugs in the code, code that is not formatted and so on.

My perception is that the people putting these apps together have not a lot of idea about the arduino otherwise some of these issues would be obvious and sorted.

I’ll let you decide on the next 4 apps – there is a video of each and the link if you want to install any of them

 

Arduino Codes Free

A couple of examples for arduino – very basic, could have done with schematics and layouts. You do get a picture of what you are building.

Really needs a lot more examples, its free but does show banners

Video

Link
https://play.google.com/store/apps/details?id=com.arduino.codes&hl=en

 

Arduino Handbook 2

A basic reference for the Arduino that explains many of the basic concepts with code examples. Menu and navigation are clear but think of this as a reference guide and not a tutorial that will guide you from start to finish.

 

Video

 

Link
https://play.google.com/store/apps/details?id=com.oleksandrdovhaliuk.ard_hb&hl=en

 

Arduino LED Projects

This app contains various LED related projects for your Arduino, schematics look clear , parts list is supplied and the code is clear enough.

A bit heavy on the interstitial ads

 

Video

Link
https://play.google.com/store/apps/details?id=org.vivek.cherala.arduinoledprojects

Arduino sensors app on Android

This app has 20 sensor type examples for the Arduino, I would have liked the code to have been spaced out a bit better and also on the same page as the layout but as this is a free app you cant really complain

 

Video

Link
https://play.google.com/store/apps/details?id=com.projects.arduino.vivek.cherala.arduinosensors

Arduino 4 channel line tracker sensor example

The next module to take a look at is quite often entitled 4-CHANNEL LINE TRACKER SENSOR, thats exactly what it does the module consists of a main module and 4 little sensor/reciever modules that connect via a 3 pin cable

here is a typical module and cables

The 4-Channel Line Tracker sensor provides an easy way for line tracking. A line sensor is composed of a number cells and each cell is composed of a sender and a receiver. The particularity of this sender/receiver pair is that it sends light that shall be reflected by the line to be detected but not by the eventually opaque background surrounding this line. Any sender/receiver pair that is able to make a difference between a line and the rest of ground (of a different color) can be used in a line sensor.

VCC pin is connected to 5V , GND pin is connected to the GND, S1, S2, S3, and S4 pins are connected to the digital I/O pins 2 – 5 but you can use others

Features

Operating voltage: DC 3.3V-5V
Operating Current:>1A
Operating temperature: -10 C – +50 C
Mounting Hole: M3 screws
Detection distance: 1mm to 60 CM adjustable, the closer the distance,the more stable performance, and white reflection farthest.
Output Interface: 6-wire (1234: signal output, +: positive supply -: ground)
Output signal: TTL level

 

Schematic

Code

Basic stuff here

void setup()
{
 Serial.begin(9600);
}
 
void loop()
{
 Serial.print(digitalRead(2));
 Serial.print(" ");
 Serial.print(digitalRead(3));
 Serial.print(" ");
 Serial.print(digitalRead(4));
 Serial.print(" ");
 Serial.println(digitalRead(5));
 delay(1000);
}

 

Testing

The sensor module has a HIGH output when its placed over a black line, otherwise its LOW.

 

Links

You can pick one of these modules up for as little as $2.10
Newest 4-Channel Infrared IR Line Detector Patrol Tracking Sensor Module DC 3.3V-5V Durable Quality Sensors Modules lines

Open a command prompt and run ipconfig

This example is for an Arduino with HID capabilities. I used a Leonardo

In this example we simply launch a command prompt and run ipconfig /all. The example is fairly simple and just demonstrates sending keystrokes

 

Code

#include <Keyboard.h> 
 
// Init function
void setup()
{
  // Begining the stream
  Keyboard.begin();
  // Waiting 500ms for init
  delay(500);
  delay(3000);
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press(114);
  Keyboard.releaseAll();
  delay(500);
  Keyboard.print("cmd");
  typeKey(KEY_RETURN);
  delay(750);
  Keyboard.print("ipconfig /all");
  typeKey(KEY_RETURN);
}
 
void typeKey(int key)
{
  Keyboard.press(key);
  delay(50);
  Keyboard.release(key);
}
 
// Unused
void loop() {}

Arduino shields for beginners

If you are just starting out with the Arduino then you can do worse than these 5 shields

You can pick up all 5 shields using the links below for about $15

Links
UNO Shield Ethernet Shield – $5

Sensor Shield Expansion Board – $3.20

L293D motor control shield – $1.75

LCD Keypad Shield – $2.08

Arduino Multifunctional Multi-functional Shield – $2.75