Accessing SD Card from Linux VirtualBox Guest on Windows Host

This post shows steps to enable SD card access from Linux VirtualBox guest on Windows host. In this post, I use Windows 10 as the host and Ubuntu 18.04 as the guest.

 

Contents
– Steps
1. Create Virtual Machine Disk file (VMDK) for the SD Card device
2. Attach SD card VMDK to VM
3. Verify
– Troubleshoot

 

Steps
1. Create Virtual Machine Disk file (VMDK) for the SD Card device
1-1. Open Command Prompt as administrator (“Windows” key + “x” and select “Command prompt (admin)”).

1-2. Check the device ID for the SD card device

The result should be like this. In this example, the deviceID for the SD card is “\\.\PHYSICALDRIVE1”.

1-3. Create VMDK file for the SD card device by using “VBoxManage” command.

Note:
Replace “C:\Program Files\Oracle\VirtualBox” and “\\.\PHYSICALDRIVE1” with the installation folder of your VirtualBox and the device ID from the previous step respectively. The result should be like this.

and “sdcard.vmdk” file will be appared on the Desktop.

 

2. Attach SD card VMDK to VM
2-1. Launch VirtualBox as administrator.

2-2. Navigate to “Settint” > “Strage”.

2-3. Click on “Controller: SATA”.

2-4. Check “Use Host I/O Cache” check box.

2-5. Then, click on “Adds hard disk” icon.

2-6. Select “Choose Existing Disk”.

2-7. Navigate to Desktop and select the “sdcard.vmdk” file.

 

3. Verify
3-1. Launch the VM and verify. In my case it appeared as “/dev/sdb” as below (Raspbian OS image in 32GB SD card).

 

Troubleshoot
If you got the error below (during/after you made changes on the SD card), please go back to Step 2 and make sure “Use Host I/O Cache” check box is checked.

“I/O cache encountered an error while updating data in medium “ahci-0-1″ (rc=VERR_ACCESS_DENIED)”

 

 

Using Your Phone as Touch Screen Display for Raspberry Pi

Got a Raspberry Pi but don’t have a display, keyboard, or mouse? You can go with headless setup, or use your phone as a touch screen display (with onscreen keyboard).

This post shows steps to connect Raspberry Pi with your phone wirelessly and use it as a touch screen display by using Remote Desktop Protocol [1].

Here is the list of contents of this post.

Contents
– Assumptions
– Steps
1. Remote Desktop Server Setup on Raspberry Pi
2. Remote Desktop Client Setup on Your Phone
– Reference

 

 

Assumptions
Here are some assumptions before start. In parentheses, it shows my environment for reference.

  • Raspbian Desktop runs on Raspberry Pi (Raspbian 2018 March on Raspberry Pi 3+)
  • iOS or Android device (Android 7.0)
  • Raspberry Pi and phone is connected to same network (private Wi-Fi network: 192.168.0.0/24)
  • SSH enabled on Raspberry Pi

 

 

Steps
1. Remote Desktop Server Setup on Raspberry Pi
xrdp [2] is a remote desktop server which is capable of accepting connections from Microsoft Remote Desktop.

1-1. Update the package list.

1-2. Install xrdp.

 

2. Remote Desktop Client Setup on Your Phone
For client side, we’ll use Microsoft Remote Desktop app which is available for both iPhone and Android. I used Android for below example but the steps are very similar for iPhone.

2-1. Install Microsoft Remote Desktop from the app store.

2-2. Launch the app, then read and accept the terms of the agreements.

2-3. Touch “+” button, then select “Desktop”.

(* I changed the display orientation to portrait mode.)

2-4. Enter Raspberry Pi’s IP address, user name and password.

IP address can be found by using ip command on Raspberry Pi.

The result should look like this:

 

2-5. Tap on newly created Desktop.

 

2-6. If everything is fine, Raspberry Pi’s desktop will be displayed on your phone!

 

Microsoft Remote Desktop app provides an onscreen keyboard.

 

Also, you can select “Touch” or “Mouse Pointer” in setting menu.

 

 

References
[1] Remote Desktop Protocol – Wikipedia
[2] xrdp: Open Source Remote Desktop Protocol Server
[3] How to Use an Android Tablet as a Screen for Raspberry Pi

 

 

Mapping Caps-Lock Key to Control Key

I used to use Happy Hacking Keyboard. Its control key is located where usual keyboard has caps-lock key. (see below picture). So, for me it’s natural that control key is there, below the tab key and above the shift key.

This post shows steps to reassign the caps-lock key to control key on ordinary keyboard, on Windows, Mac OS X, and Linux.

 

Contents
1. Windows
2. Mac OS X
3. Linux
4. Reference

 

1. Windows
I tested with Windows 10 laptop. According to [1], this also works for Windows 7, 8 and Vista.

1-1. Download and install SharpKeys from here.

1-2. Launch SharpKeys and click on “Add” button.

1-3. In “Edit Key Mapping” window, select “Caps Lock” as “From key”, and “Left Ctrl” as “To key”, then click on “OK”.

1-4. Click on “Write to Registry”.

1-5. Restart PC for the changes to take effect.

 

 

2. Mac OS X
2-1. Open “System Preferences”.

2-2. Select “Keyboard”.

2-3. Click on “Modifier Keys…” button.

2-4. Select “Control” from pull-down menu for Caps Lock Key, then click on “OK”.

 

 

3. Linux
I tested this with Ubuntu 16.04.

3-1. Open keyboard config file.

3-2. Search a line starts with “XKBOPTIONS” and edit as below:

3-3. Restart PC for the changes to take effect.

 

 

4. References
[1] Map Any Key to Any Key on Windows 10, 8, 7, or Vista – How-To Geek
[2] macOS Sierra: Change modifier keys – Apple Support
[3] Change caps-lock to control in virtual console on Ubuntu 17 – ask ubuntu

 

 

Creating AltBeacon with Raspberry Pi using BlueZ Example Code

A previous post showed the steps to make an iBeacon transmitter with Raspberry Pi using BlueZ example code (i.e. “example-advertisement). This post shows the steps for AltBeacon [1] in the same manner.

 

Here are the contents of this post.

Contents
– Prerequisites
– Steps
1. Enable experimental flag
2. Download BlueZ
3. Modify BLE Advertisement Example Code
4. Test
– Summary
– Reference

 

Prerequisites
Here are some prerequisites before start.

  • Raspberry Pi 3 or Raspberry Pi Zero W
    Or any other model with Bluetooth adapter (e.g. Plugable BLE Adapter, Panda Bluetooth 4.0 Adapter)
  • Raspbian Stretch (March 2018)
    I would suggest to use Desktop version of Stretch because I got “DBus.Error.AccessDenied” for some reason when I ran “example-advertisement” on Raspbian Lite. It seems it’s similar to this but couldn’t figure out the cause/workaround.
  • Internet access
    It’s required to download BlueZ example code. Here is a Wi-Fi Setup steps. If you already have the code, you can work offline.

 

Steps
1. Enable experimental flag
Skip to Step 2 if you are using BlueZ 5.48 or higher. (update BlueZ to 5.48)

If not, follow the steps below.

Bluetooth service needs to be executed with experimental flag since ‘LEAdvertisingManager1’ interface is an experimental feature until BlueZ 5.48 release.

1-1. Open the configuration file for Bluetooth service.

1-2. Find a line starting with “ExecStart” and add “–experimental” at the end of the line. After modification, the line should look like this:

1-3. Reload the configuration file and restart Bluetooth service.

1-4. Check the status of Bluetooth service. [Optional]

You should see the experimental flag. (Line 9 in the example below)

 

2. Download BlueZ
2-1. Download BlueZ source code.

2-2. Extract the archive file.

2-3. Run the sample code and make sure that it works. [Optional]

Output should be like this:

* Press Ctrl + C to stop the script.

 

3. Modify BLE Advertisement Example Code
3-1. Copy the example code.

3-2. Open the file and look for TestAdvertisement class.

3-3. Replace ‘__init__’ method:

with:

 

4. Test
4-1. Run the code. The console output should be same as Step 2-3.

4-2. Find your Raspberry Pi using a beacon scanner app. If everything goes well, the Raspberry Pi should be broadcasting AltBeacon message and it can be detected by app. Below are examples of apps.

‘nRF Connect’ for Android

 

‘Locate Beacon’ for iPhone

 

Summary
AltBeacon is an open source version of Apple’s iBeacon. It has the same functionality as iBeacon, and the two have similar data structure as below.

*2 : Bluetooth 4.0 Core Specification, Volume 3, Part C, Appendix C, 18.1 Flags
*4 Manufacture dependent value
*5 Application dependent value
*6 Device dependent value

 

References
[1] AltBeacon

 

 

Creating iBeacon with Raspberry Pi using BlueZ Example Code

This post shows the steps to make an iBeacon with Raspberry Pi, by modifying BlueZ BLE Advertisement example code (i.e. “example-advertisement).

Note:
Even though it uses Bluetooth Low Energy standard, iBeacon is Apple’s proprietary protocol and making/deploying iBeacon devices requires the license from Apple [1]. The scope of this post is limited to getting familiar with BlueZ advertising example code and iBeacon format for experimental purpose.

 

Here are the contents of this post.

Contents
– Prerequisites
– Steps
1. Enable experimental flag
2. Download BlueZ
3. Modify BLE Advertisement Example Code
4. Test
– Summary
– Reference

 

Prerequisites
Here are some prerequisites before start.

  • Raspberry Pi 3 or Raspberry Pi Zero W
    Or any other model with Bluetooth adapter (e.g. Plugable BLE Adapter, Panda Bluetooth 4.0 Adapter)
  • Raspbian Stretch (Nov 2017)
    I would suggest to use Desktop because I got “DBus.Error.AccessDenied” for some reason when I ran “example-advertisement” on Raspbian Lite. It seems it’s similar to this but couldn’t figure out the cause/workaround.
  • Internet access
    It’s required to download BlueZ example code. Here is a Wi-Fi Setup steps. If you already have the code, you can work offline.

 

Steps
1. Enable experimental flag
Bluetooth service needs to be executed with experimental flag since ‘LEAdvertisingManager1’ interface, which is used in the example code, is experimental feature in BlueZ 5.43 (pre-installed in Stretch Nov 2017). In case you’ve updated BlueZ to 5.48 or higher, skip Step 1 since the interface have been marked as stable since 5.48. [2]

1-1. Open the configuration file for Bluetooth service.

1-2. Find a line starting with “ExecStart” and add “–experimental” at the end of the line. After modification, the line should look like this:

1-3. Reboot the board to restart Bluetooth service.

1-4. Check the status of Bluetooth service. [Optional]

You should see the experimental flag. (Line 9 in the example below)

 

2. Download BlueZ
2-1. Download BlueZ source code.

2-2. Extract the archive file.

2-3. Make sure that the sample code works. [Optional]

Output should be like this:

 

3. Modify BLE Advertisement Example Code
3-1. Copy the example code.

3-2. Open the file and look for TestAdvertisement class.

3-3. Replace ‘__init__’ method:

with:

 

4. Test
4-1. Run the code. The console output should be same as Step 2-3.

4-2. Find your Raspberry Pi using a beacon scanner app (e.g. nRF Connect).

 

Summary
If everything goes well, the Raspberry Pi should be broadcasting iBeacon message and you can find it with a scanner app. Some of the iBeacon data can be configured on Step 3-3 for your application. Here is a brief explanation of those data.

  • ‘company_id’
    Company Identifiers are defined by Bluetooth SIG [3]. For iBeacon, it must be Apple’s ID (i.e. 0x004C).
  • ‘beacon_type’
    It must be ‘0x0215’ which means Proximity Beacon.
  • ‘uuid’
    Proximity UUID is an application unique ID.
  • major‘ and ‘minor
    Major Number and Minor Number are application dependent values which can be used to identify more precise location, etc.
  • ‘tx_power’
    Tx Power is a device dependent value. It must be calibrated for each device when it’s deployed.

 

References
[1] iBeacon – Apple Developer
[2] BlueZ Release Notes
[3] Company Identifiers – Bluetooth SIG