Bluetooth Low Energy (4.0) on Ubuntu 13.10: Advertisements, Sending and Receiving

Here is a quick tutorial on how to send and receive data without pairing with ubuntu 13.10 and two CSR 4.0 BTLE dongles ($12 including shipping from ebay for both dongles). Surprisingly straightforward.

  • install things

$ sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev bluez wireshark

  • plug in the first dongle (it should show up in hciconfig as “hci0”)
  • start LE scan capture

$ sudo hcitool lescan (you’ll see it spit out things such as “00:1A:7D:DA:71:0D (unknown)”)

  • start wireshark as root

$ sudo wireshark

  • In wireshark, start capture on bluetooth0
  • plug in the second dongle, should show up as hci1
  • program hci1 with hciconfig

$ sudo hciconfig hci1 noleadv (sometimes you can skip this step, sometimes the next step, leadv, will throw up “LE set advertise enable on hci1 returned status 12” if you don’t do noleadv first)

$ sudo hciconfig hci1 leadv

$ sudo hciconfig hci1 noscan

$ sudo hcitool -i hci1 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00 00 00 00 C8 00

  • you’ll see the terminal spit out:

< HCI Command: ogf 0x08, ocf 0x0008, plen 32 1E 02 01 1A 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00 00 00 00 C8 00

> HCI Event: 0x0e plen 4 01 08 20 00

  • On Wireshark, you should now get a packet and see the above data in it.

 

Screenshot from 2014-06-29 02:16:20

Python

Right now, I have only figured out how to read the advertisement data, not set it.

This is using code on stackoverflow: http://stackoverflow.com/questions/23788176/finding-bluetooth-low-energy-with-python which I saved as ble-python.py. If you add this line, it will print out the payload:

print(':'.join("{0:02x}".format(x) for x in data[44:13:-1]))

$ sudo python3 ble-python.py

00:1a:7d:da:71:09 c8:00:00:00:00:61:a9:07:ad:d1:17:2f:a1:c4:4b:f5:73:f4:39:0a:e2:15:02:00:4c:ff:1a:1a:01:02

You can see that both the manufacturer ID and the advertising payload is now printed out.

UPDATE 30 June 2014

Here is how to write data using the second CSR4.0 dongle and python:

import subprocess
dev = 'hci1'
adr = '0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 05 06 07 08 C8 00'
cmd_cc = "hcitool -i %s cmd %s" % ( dev, adr )
subprocess.Popen(cmd_cc.split(),stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()

and if you want to convert strings to hex,

s = 'some data'
" ".join("{:02x}".format(ord(c)) for c in s)

References

http://www.warski.org/blog/2014/01/how-ibeacons-work/ http://en.wikipedia.org/wiki/IBeacon http://hackaday.com/2013/12/05/turning-a-pi-into-an-ibeacon/ https://learn.adafruit.com/pibeacon-ibeacon-with-a-raspberry-pi/adding-ibeacon-data http://stackoverflow.com/questions/22568232/how-to-retrieve-advertising-payload-from-ibeacon-ble
http://stackoverflow.com/questions/23788176/finding-bluetooth-low-energy-with-python
https://www.bluetooth.org/en-us/specification/adopted-specifications, Core_v4.1.pdf, pg 2023 (Bluetooth 4.0 Core Spec. Volume 3, Part C, Section 11.1.4 or 11.1.10)

How do I become a sink for STEM education research, like I am a sink for engineering information?

How do I find the right circles to be as “in” in STEM education as I am in engineering?

Today I want to discuss something that’s been frustrating me for a while: the disparity in my information sources for engineering questions and for STEM education questions.

Here’s what a contrived day looks like (these things have all happened, but not all in one day):

  • Wake up, check my email. Oh, there’s a cool robotics conference coming up soon. And someone sent me a link to the latest hexapod (six-legged robot).
  • Check facebook. Charles posted pictures. “Catalyzed Destruction of a Poly(lactic acid) 3D Printed Bunny (15 photos)”. Huh, I didn’t realize PLA melted like that.
  • Go to work. Work on engineering most of the day with three other engineers. Why aren’t the stepper motors working?? So glad we bought an oscilloscope. After checking stackoverflow, still have no idea how to implement bluetooth low-energy (BLE). Ask friends on google talk and the MITERS mailing list for help. Earlier asked on the Artisan’s discuss and putz-course-6 (the hall I lived on during undergrad’s CS majors list) for BLE help. Crap, no FTDI cable. Facebook chat Charles and get permission borrow one.
  • Chill, read a few friends’ blog posts about their latest technical accomplishment. Oh look, one of my friends is on Hackaday.
  • Grab a snack with a friend after work so that he can help me with our PCB layout software, Diptrace
  • Go to a meeting for contract engineering work. Talk about the latest quadcopters and their costs and how this impacts STEM workshops for high schoolers.
  • Go to MITERS. Rant with my friends about the need for a usable open-source CAD program, and also debate ways we could make a local printed circuit board same-day turnaround manufacturing service.
  • Oh, it’s dinner time, walk with friends over to H-mart and discuss the latest crazy idea we have and bemoan the startups invading our space
  • Meet my friends who stay up until 3 am helping me figure out how to implement bluetooth low energy on our robot.
  • Go home and sleep.

As you can see, if I need engineering help, even just to borrow tools, I have several options:

  • Chat friends a few years older than me or who are more specialized in the field. I have at least ten people I gchat periodically with engineering questions and feel comfortable doing so
  • Email out to engineering lists I’m on, such as MITERS and Artisan’s Asylum discuss and putz-course-2/6, for help
  • Meet people in person for help

I’m also a sink for engineering information. If I do nothing, I still receive tons of information about the latest engineering doodads.

I wish this were the same way regarding information and available resources in STEM education, specifically diversity in STEM education. I want to be a sink for this information. Right now, if I have questions about what’s an effective way to teach pulse-width-modulation, I have no one to gchat. If I have questions about whether my theory that having people creatively build their own things is a good idea and whether it’s worked in the past, I have no one to email. If I need a lengthy strategic session to figure out how I can best help diversify STEM education, there is no one to have lunch with. When I check facebook, I’m not inundated with information or links to videos of the latest STEM education research.

Instead, I have to expend effort and time trying to find all these resources.

My question to you, dear reader, is how can I change this? How do I find the right circles to be as “in” in STEM education as I am in engineering?

Sea Kayaking! Hingham Hull to Peddocks Island (Boston Harbor)

20140615_121420

This Friday, I learned that the PCBs I’d ordered from 4pcb and expected to arrive Saturday weren’t arriving until Monday (silly shipping services that don’t work on weekends). Thus, I decided to join an impromptu camping trip!

I know, I know, after my first time backpacking  a few weeks ago I promised to never do outdoors things again and instead vegetate in bed and watch movies. Oops.

Okay, wait, actually there was kayaking involved. Well, it seems like there were other inexperienced kayakers, a lot of people, and some experienced kayakers, so I went full-speed ahead. 😀

The plan was to go with the tide out on a calm-ish sea to some tiny island 3 km out from hingham hull, to Lovell’s Island I believe. Alright. After some shenanigans, I am approved to go along the trip with some MITOC gear rented by Molly, who is actually boathouse-approved.

20140614_171108

Since MITERS is in the same building as the MITOC boathouse, I had often seen people unloading and loading kayaks from cars, but I never thought I’d be one of those people. Hurray for infiltrating new friend circles! This time, it was through the coworking space NarwhalEdu works out of, the pirateship. In total there were nine of us, over half of who were from Iceland and who happened to be in Boston for a month.

The first ordeal was figuring out how to strap the kayaks to the car. I was pretty dubious about the light foam pads (blocks) and straps we used, and the whole tieing it through the car deal.

20140614_173809

Off we went, a little nervously. We shoved the boats toward the center, but they tended to move outwards as we travelled. I read up on kayaking on the internet on the way while eyeing the kayaks frequently to see if they were looking shaky.

Probably I should have just asked Molly about how a sea kayak works.  I, not being vocal enough about the fact that I had never been kayaking before, let alone sea kayaking, rather drastically changed the course of our trip. See you some other time Lovell’s Island 🙂 I still had an absolutely awesome time though.

20140614_200447

Here are the results of our food pit stop at Whole Foods. I would like to thank Cappie and Sheep for introducing me to pickled pepperocini peppers. Sooo delicious. We also grabbed toilet paper, gallon ziplock bags, and instant coffee

Our packing list was recommended by Erik as:

– Food
— Water (1 gallon aka 4 liters a person)
— Clothes that can get wet (running shorts or swim trunks are a
good idea)
— Clothes that keep you from getting wet (if it rains)
— Shoes or sandals that can get wet, and shoes that can stay dry
— Tent/shelter
— Sleeping bag
— Headlamp/flashlight
— Knife, utensils
— Lighter
— Bandaids, tape, basic first aid kit (I can bring)
— Medium-sized dry bag to hold some clothes and valuables that can’t get wet

The amount of water was a bit surprising to me, since while backpacking in Virginia I consumed at most 2L of water a day. Then I realized there weren’t any water sources on the island, so this included water for oral hygiene and cooking and coffee, as well as an emergency amount of water.

All in all I ended up with a 55F sleeping bag, sleeping pad, my giant winter coat (super happy I brought it), long synthetic pants, long rain pants, synthetic full-sleeve jacket, three shirts, short pants, two pairs of underwear, socks, flip flops,  and velcro sandals. Headlamp was critical, of course. A lot of this was borrowed from Molly — thanks Molly! Instead of a dry bag, I used a large trash bag, and that was okay. Sunscreen was critical.

If I did this over again, I would have packed some comfortable closed-toed shoes (there are actually shoes called boat shoes!), since with the flip flops and sandals I just kept getting dirt and rocks in them. Luckily it didn’t rain at all.

Anyway, we eventually set out around when the sun is setting. It’s dark by the time we get going, but the moon is nearly full (albeit behind clouds) so there’s plenty of light. The headlamps help us identify each other and hopefully keep night-time boats from crashing into us.

This is where I get a crash course in kayaking.

  1. These kayaks have steerable rudders which can be pulled up or down from the water by ropes near you when you are sitting in the kayak. These rudders are turned left or right by pedals. Me: “I wonder why I am drifting right, it sure is hard to paddle straight like everyone else.”
    There was this really classic moment where someone asked me to test my pedals, and I really had no idea what they were talking about.
  2. Be sure to pull the pedals up to where you can comfortably reach them without leaning back. This will help a lot with fatigue.
  3. You can use both hands when pulling a stroke. One push, one pull.
  4. The skirts are used to prevent water from the paddles from soaking you all the time.
  5. You will get wet.
  6. Pedal on the same side you want to turn, paddle on the opposite side.
  7. Fighting the current will make you fairly sad. Having the wind and current in opposite directions will make you fairly sad too.
  8. Point your kayak into waves, e.g. from a passing powerboat.
  9. Give a good distance from shore to avoid crashing into it. If you do crash into it, the only solution may be to get out of the kayak and relaunch.
  10. Life jacket is required, bailer, water, and snacks go behind your seat.
  11. Small things go in first into the tip of the canoe and then larger things.
  12. Be sure to beach your boat above high tide if it will be there for a while.

Eventually after the experienced kayakers, who are staying behind to help me, realize I am making no progress at all against the current, we abort the plan and decide to go to the nearby Peddocks Island and make the best of it.

20140615_003510

20140614_232110

We reach the island, which in the daytime turns out to be super close by. We set up a fire and cook awesome jumbo marshmellows and other food and set up a campsite.

Screenshot from 2014-06-16 01:05:36

(click to enlarge)

Anyway, pro-tip, if you’re going kayaking for the first time probably best not to do it out on the sea in the dark against the current with a group of people who you don’t really know that well and are more experienced / stronger than you are.

As the tide comes up, our campsite gets flooded! Luckily the tents were rescued, but turns out the large flat area that seemed perfect for a campground was large and flat because at high tide it becomes a pool. Here it is at low tide:

20140615_065524

Sarah found some antlers, there was a large horseshoe  crab shell lying around, and I learned about razorback clams, which look like rectangles!

I really liked the beaches on this island because of the rich purple rocks and seashells, which I didn’t take a picture of. At low tide there were also lots of hermit crabs wandering around, and Molly said she saw crabs.

Also, there were flat rocks that were great from skipping, and almost everyone demonstrated some amazing skills at stone skipping shortly before we left on the return trip. I’m talking 10 skips here, where the stone doesn’t just plop and sink but skips along so fast that eventually it disappears into the water.

Molly collected water samples to play around with at BOSSLAB.

20140615_125823

That was pretty much it. Some walking around, some kayaking, a lot of food eating and talking, some running fully clothed into the ocean to cool down on my part (it was so hot during the day! almost everyone got sunburned despite liberal application of sunscreen). We went back at high tide at 1:55 and crossed carefully, since during the day there were a TON of boats, some of them speedboats going incredibly fast.

No pictures of us kayaking because my phone was tucked inside two or three layers of plastic bags.

nectarine

picture thanks to sarah. nectarines are so great

groupphoto

group photo thanks to erik, not pictured because he is taking the picture

Thanks to all the people who put up with me joining their trip, i think everyone had fun despite change of islands. I wonder if I will ever go sea kayaking again. That feeling of going to an island and camping whenever you want to, of reaching places you didn’t think you could reach, was pretty cool. And I do owe Lovell’s Island a visit… ^^

how to download hours of radiolab

i like having things to listen to while cleaning or assembling circuitboards or traveling or other tedious tasks. Here is how I downloaded a few hours of radiolab (each episode appears to be about 25 minutes), using Firefox and DownThemAll:

Go to

http://feeds.wnyc.org/radiolab

Hit Ctrl-A to select everything, then right-click and select  “DownThemAll! Selection…”

Select “Audio files”

Create a folder to store all the files in

Done!

I recommend actually selecting only a small subset of the available files, as the full files list available amounts to several gigabytes of material. This will save their bandwidth. Additionally, you can donate here:

https://pledge3.wnyc.org/epledge/desktop/radiolab/?

 

4pcb Shipping Options, Cost & Time to MIT

Edit: Earlier I kept using myroPCB to refer to 4pcb! Talk about confusing. Myro is a service in China. Not the same.

Recently I got bitten trying to save $30 in shipping, which actually just cost me two days of work time (the weekend). I thought barebones was same-day shipping out, but it is actually 1-day lead time. Thus, the fastest turnaround time possible is 3 days, for instance order on Wednesday, ships on Thursday, next-day delivers on Friday. The 1-day and 2-day services do not deliver on Saturdays.

Thus, for the future, here are some examples of 4pcb costs and shipping times for their barebones option (2 layer no silk no mask yes plating), the best option for quick and dirty prototypes:


 

Order 1

1 402             Bare Bone 2-Layers               5EA       14.29        71.45
2 95              Shipping & Handling              1EA       69.29        69.29

Unit Dimensions: 01.938 x 02.150

ORDER-DATE: 01/13/2012

SHIP-DATE: 01/16/2012

SHIP-VIA: UPS Next Day Air Saver (5:00pm)

Shipped: Mon, Jan 16, 2012 at 12:10 PM

Arrived: Tuesday, 01/17/2012 at 10:58 A.M

For this board:
https://github.com/nouyang/Metrify-Hardware
https://github.com/nouyang/Metrify-Hardware/blob/master/eagle/metroid/boardimage.png

The only options that ship on Saturdays are Fedex and UPS Saturday.


 

Order 2

7 barebones PCBs $91.84

1 day lead time

Shipping UPS 2nd DAY $41.49

Ordered: 6/11/2014

Shipped: 06/12/2014

Arrived: 6/16/2014 (well, almost guaranteed it will arrive on Monday)

First Dimension:     2.400      Second Dimension:     2.200

On this board,  the available shipping options and costs:

     UPS Red Early (8:30 am) $117.41
UPS Red (10:30am) $84.26
UPS Red Saturday $96.76
UPS 2nd DAY $41.49
UPS 3-day orange $31.22
UPS Next Day Air Saver (5:00pm next business day) $77.29
UPS Ground $19.91
FedX Early (8:30am) $117.41
FedX Priority 1 (10:30am) $84.26
FedX Standard $77.29
    FedX Saturday $0.00  
FedX 2nd DAY  $41.49
FedX Express Saver $31.22
FedX Ground $19.91
WILL CALL $10.00
    UPS Worldwide Express Red Will not quote because we are in US
    UPS Worldwide Expedited Blue
    UPS Worldwide Standard
    FedX Intl. Priority
    FedX Intl. Economy


 

Appendix

Order 1
ITAR: no
Certs: IPC Class 2                     AS9100: no
Electrical Test: NO                    5% OVERAGE: no
Material Type: FR4
Material Thickness: 0.062″             Board Finish: BB
Unit Dimensions: 01.938 x 02.150
Array Dimensions: 00.000 x 00.000      Array Number Up:       0
Array Qty:       0
Tab Rout: NO                           Scoring: NO
Copper Weight: 1 oz                    Inner Copper Weight: 0.0
Solder Mask Sides: None                Solder Mask Color: None
Legend Silk Scrn: None                 Legd/Silk Scrn Color: None
Castellated Holes: no
Blind/Buried Vias: None                SM Plugged Via: no
Via-In-Pad: None                       Microvias: None
Plated Slots: no                       Plated Edges: no
CounterSinks: no                       CounterBores: no
CtrSinksPlated:      0                 CtrBoresPlated:      0
CtrSinksNon-Pltd:      0               CtrBoresNon-Pltd:      0
Ctrld Dielectric: no                   Ctrld Impedance: no
Etchback: no                           # Pem Nuts:          0

Order 2

 Material Type: FR4  Material Thickness: 0.062  Number of Layers: 2
 First Dimension: 2.400  Second Dimension: 2.200  Finish Plating: BB
 First Array Dimension: 0.000  Second Array Dimension: 0.000  Array Up: 0
 Copper Outers: 1.0  Copper Inners: 0  Smallest Hole Size: 0.015
 Top SMD Pads: 0  Bottom SMD Pads: 0  SMD Pitch: 0.000
 Solder Mask Sides: 0  Solder Mask Type: LPI  Solder Mask Color: None
 Silkscreen Sides: None  Silkscreen Color: None  CNC Route Points: 4
 Trace width/Space: 0.008  Tab Route: No  Scoring: No
 Gold Fingers: None  Plated Slots: No  Plated Edges: No
 Counter Sinks: No  Counter Bores: No  Dielectric: No
 Impedance: No  ITAR: False  Certification: IPC Class 2
 Blind/Buried Vias: None  Micro Vias: None  ViaInPad: None`

 

Barebones Specs

  • 2-layer, FR-4, 0.062″ thick
  • All-holes-plated
  • 6-mil line/gap minimum
  • Tin finish over 1-oz Copper
  • No internal routing (cutouts) and no scoring, tab rout, or drilled hole board separations.
  • Cut to rectangle shape only
  • No mask
  • No legend
  • Min size 1.25″ X 1.25″
  • Max size 12″ X 16″ (192 sq. in.)
  • Gerber 274X preferred
  • Excellon drill (English Units)
  • Minimum hole size 0.015
  • Maximum 35 drilled holes per sq. inch