Sunday, August 21, 2016

PCB Battery Clip

Just a small update to the battery powered nodes. Until now I had used a piece of tape to hold the PCB to the battery pack. It was always a pain when changing the batteries or accidentally hitting the node and watching it fall apart. I also wanted to try my hand at Fusion 360, so this seemed like the perfect opportunity.

Fusion 360 sketch of PCB battery holder clip

I still have a lot to learn in using Fusion 360 but I got the job done, um sort of. I had issues extruding the width less than I had initially and I didn't want to start over. So canceling the print worked good enough at the size I wanted.

Fusion 360 model of PCB battery holder clip

It came out quite nice. I just need to learn Fusion 360 properly.

PCB battery holder in action


Wednesday, June 22, 2016

C.H.I.P. by Next Thing Co


After a year of waiting it has arrived: the $9 computer from Next Thing Co. When it launched on Kickstarter, there was no reason to skip backing this one to at least see what it was all about. Now that it has arrived I am quite happy that I did. For such a large project it would hardly be worth calling it late. My reward was due May 2016 and I received it June 2016. Very good compared to most crowd sourcing campaigns. I selected the C.H.I.P. plus battery reward, but before it shipped you could add accessories. I added the VGA adapter and an extra C.H.I.P. That way I can use it on my desk attached to my monitor since the DVI input is already in use. With the Raspberry Pi I have to connect it to the TV if I want to mess with it directly. At this price it's cheap enough to buy more than one that you can dedicate to a project and just fuggedaboutit.

$9 C.H.I.P. and accessories


Monday, June 20, 2016

nodeLED

As a hacker, I know all too well how much workbench space is vital. Alongside my three monitors, I have an extended desk that houses my soldering irons, compartment shelving, and countless projects, among other tools and devices. One constant that seems to get in my way is an old desk lamp. That’s where this project came to light, ha! I decided to design my own lamp using an analog RGBW LED strip. This board I designed will give you the tools to design your own WiFi controlled light source.



The boards' controller is run by the NodeMCU which is connected to an N-Channel MOSFET for each color of the RGBW LED strip. Trimpot for brightness and two user buttons (that can be setup to change modes, possibly) were also added. A 5v regulator was then added so the power can be shared with 9-12v input for the LED strip. The nodeMCU will be updated by wireless as well.




My idea is to have the nodeMCU be a web server for direct control via a web page. The site will have various configurations including color options, number of channels, animations (like fade effects) and a timer. I’d like to have it connect to MQTT server to integrate with larger servers such as openHAB.

You can follow the details of the project on Hackaday.io

https://hackaday.io/project/11521-nodeled

Sunday, June 19, 2016

JeeNode to MQTT Gateway

It's been a few months since I have worked on openHAB but that is mostly due to focusing on FriedCircuits, Hackaday Prize and the Maker Faire. Not a dull moment around here! I finally sat down while watching some tube (or rather crystals) to start work on the JeeNode to MQTT gateway. Up to this point if you have read my other posts I have still relied on DomotiGA to get the JeeNode data into openHAB. This is because DomotiGA has support for JeeNodes. I noticed the sensor nodes weren't checking in again which usually is because DomotiGA is not running, this time I think it just needed a restart plus one node actually needs batteries. This prompted me to finally get around to writing the gateway. Once complete I won't need DomotiGA and the desktop UI so I can use Ubuntu server for my rebuild of openHAB.

After some research I was able to get receive the data over serial, split it and shift the bits into separate variables to publish over MQTT. Using the Paho MQTT python library it is trivial to connect and publish. I decided to map out it out as JeeNode/node#/name/value. Simple. I should mention this code is assuming the JeeNode is running the room node sketch or at least using the packet format. My remote nodes and receive node code is on Github if needed. Here is a graphical view of the tree for one node.

MQTT JeeNode Map

Thursday, June 9, 2016

Switchmate

Last year my friend and I backed the Switchmate on Indiegogo.  At the time I didn't have much of a home automation setup - just two window nodes and the slider.  Not even any connected bulbs and I was still on DomoitaGA so I didn't have any of the fancy rules I now have in openHAB.  Over the course of the campaign, they had different deals so I ended up with three rewards.  I had actually forgotten about them, in part because since switching to openHAB and getting connected light bulbs, the need for these switches seemed diminished.  But one day I was pleasantly surprised to receive a shipping notice.  A few days later I received the package in the mail and boy was I surprised!  The quality and presentation was excellent - not what I expected at all.  Curious about them?  Read on!



Sunday, April 24, 2016

Routing High Speed Signals and USB

Eventually in most hobbyists' path, one will end up working with high speed signals. These days so many microcontrollers support USB and even ones that don't can use software USB. Of course using a microcontroller is the answer to every engineering problem, right? Most of us just work with USB 2.0 connected directly to a microcontroller for uploading and serial communications. With advent of the USB Tester, I have learned more about USB than I ever thought I would. Recently I have dived into USB 3. Which compared to 2.0, is so much more sensitive to your PCB routing as I found through trial and error. I have seen many projects on the various blogs and for sale on the usual sites that don't follow or even try to route correctly. With USB 2.0 for the most part you can get away with it and it will still work. To help save you some time, I would like to share my findings that should help prevent PCB re-spins just due to USB not working. This is by no means an exhaustive guide to high speed routing as there are plenty of application notes across the web for that. I will list a few at the end of this post that I found helpful.

I am not by any means an expert on high speed signals, but I have learned enough to get the job done. In the end I was fortunate that my desktop PC had the first USB 3 controller made by Renasas which is much more sensitive than my laptop so I knew if it worked it would work for anyone. 

Diagram of USB Differential Pair (Wikipedia)


High speed signals use differential pairs instead of a single trace or a clock / data pair like I2C. By using a pair of traces you can cancel out noise. One is positive and the other negative. The idea is that electromagnetic interference would affect both signals and therefore would be canceled out since the receiving end looks at the difference of the two. Using a 2 channel oscilloscope you can connect to both signal and do a bit of math to see the resulting signal.

With USB 2.0 I was able to get away with branching (breaking out D+/D-). These are terms that you will come across with working with high speed signals. 
  • Branching is when the traces are not direct from one point to another and have a split.
  • Stubs is if the signal hits a via with a pin in it from the top layer instead of the bottom layer to from a straight path. 
USB 2.0 only uses 1 differential pair vs USB 3 which uses 2 for full duplex operation. If you are using the Type-C connector you have duplicates of each pair plus for reversibility and extra signals for detecting orientation and other signal types.

USB Type-C Pin Out (Credit someone on the internet)

Important things to consider while laying out your board. 
  • Calculate trace width and spacing to maintain 90Ohm differential (Calculator) This will also depend on the PCB you will be using. In my case OSHPark lists the specs of their PCB.
  • Maintain trace length of each pair. CAD tools have a differential pair routing tool along with meander to adjust traces for matching. A better way is to add a little length on the end of the short trace before connecting to your pad instead of having to meander which will affect the 90Ohm differential target. It can take a bit of time though to get it just right.
  • Use as few vias as possible as they affect signal integrity.
  • Route using 45degree angles instead of 90. I think this is to avoid reflections. 
  • Avoid stubs by using a via before routing to a through hole part so you are on the bottom layer. 
  • As much as possible, route above/below a continuous ground plane. On 2 layers boards this is pretty much impossible. With USB 3 it really should be a 4+ layer board. 
  • Signals should be on the outer layers. 
  • As always use the shortest path possible. (The Wozinack way ;))
  • Another one that may be hard to do is don't cross signals above or below another signal. Ideally there should be a ground plane there anyway. 
  • One way to avoid inverted pairs having to cross over each other is to mirror a part but then you have to deal with parts on both sides which may or may not be an issue for you. You should check with your assembly house if going that route. I have been able to reflow boards twice in this case. Surface tension usually keeps parts them from falling off. 
  • Remember that higher speed signals travel along the skin of the copper so surface area is your friend and reduces impedance and attenuation on the signal. (More info)
  • Type-C cable only has 1 pair of differential pairs for USB 2.0 on the A side of the connector. B is unconnected. So I believe that means you should tie A and B together or maybe there is a mux IC for USB 2.0.

USB 3 Differential Pairs Example


It seems a lot to take in for a hobbyist but after awhile it starts to make sense. PCBs are getting cheaper so if it doesn't work out you can keep trying different designs until it works. 

Here is my settings in Eagle CAD for a 2 layer board from OSHPark pictured above.

Eagle CAD Differential Trace Settings

Eagle CAD Length Settings

There is a minimum error in length but I always try to get it 100% matched.


Links I found during my research:
http://www.digikey.com/en/articles/techzone/2016/feb/usb-3-1-usb-type-c
https://www.fairchildsemi.com/application-notes/AN/AN-6103.pdf (PDF)
http://www.cablewholesale.com/cgi-bin/articlelink.cgi?article=SALES_ART_2015-03-30&key=653bc4866500468368db5e966ba1ea767ed58693&link=/support/technical_articles/introducing_10_gigabit_usb_31.php
http://www.edn.com/design/test-and-measurement/4438870/USB-3-1-testing-part-2--Type-C-cable-assemblies
http://www.cypress.com/file/151566/download
http://www.xmultiple.com/xwebsite-forum-USB-TypeC.htm (Good one with cable wiring)
https://en.wikipedia.org/wiki/USB_Type-C
https://www.element14.com/community/servlet/JiveServlet/previewBody/36206-102-2-218482/Introduction%20to%20USB%203.0%20Protocol.pdf (PDF)
https://www.synopsys.com/Company/Publications/DWTB/Pages/dwtb-convert-usb-design-type-c-2015q1.aspx
http://electronics.stackexchange.com/questions/125011/how-does-usb-type-c-handle-reverse-polarity
http://kevinzhengwork.blogspot.de/2014/09/usb-type-c-configuration-channel-cc-pin.html
http://www.mouser.com/publicrelations_techarticle_3cs_of_usb_2016final/
http://www.usb.org/developers/docs/hs_usb_pdg_r1_0.pdf (PDF)
http://electronics.stackexchange.com/questions/41851/how-critical-is-the-layout-of-usb-data-lines-how-does-my-layout-look
http://www.ti.com/lit/an/spraar7e/spraar7e.pdf (PDF)
http://www.belden.com/blog/broadcastav/understanding-skin-effect-and-frequency.cfm (Skin Effect)
http://www.appfruits.com/2015/03/building-your-own-custom-teensy/ (Links to calc)
http://www.multek.se/engelska/engineering/pcb-structures-2/differential-microstrip-impedance-calculator-2 (Calculator)

Monday, March 21, 2016

Quest for a Logic Analzyer

Since I started this adventure in hardware I have wanted to get an logic analyzer. I have an older but good oscilloscope that only goes so far when it comes to digital logic signals. I could go for the Saleae, but if I am going to do that I would rather sprint for the higher end model which is an easy $400+. In the mean time I was on a quest to find a low cost option. Upon my travels of the interwebs I found a few options. There's Dangerous Prototype's bus pirate (which I have) or their openbench logic. There are also the microcontroller options using, say, a Teensy or STM32. Then when I came across the BeagleLogic, it seemed like it fit what I had in mind. And actually, if I remember correctly, I saw it during the Hackaday Prize 2015. Funny how you end up somewhere on the Internet you've been before but have long forgotten.



The BeagleLogic is a logic analyzer based on the Beaglebone created by Kumar Abhishek, a semi-finalist of the Hackaday Prize Best Product 2015. What makes the BeagleLogic special is it uses the BeagleBone PRUs which are basically 200Mhz microcontrollers attached to the ARM CPU with shared memory. This is one thing that sets the BeagleBone apart from other SBCs. I have always been interested in the PRUs but they are a bit complicated and I've yet to have the time to investigate. I wish Ti would make an easy way to use them like Arduino did for microcontrollers. For me it's more of the lack of time to learn them when I have so much going on with other projects.


Features:

  • 100MSPS
  • 14 Channels (13,14 require you to disable eMMC)
  • 320MB Capture Buffer
  • 5V tolerant inputs
  • Web Interface
  • Capture interfaces from the BeagleBone itself
  • Opensource 

At the moment, you have to make your own BeagleLogic. There isn't a place to order it. In addition, you need your own Beaglebone. Hardware wise, all it provides is the ability to probe up to 5V. since the BeagleBone ADCs only accept 1.8V signals. The BeagleLogic is fairly simple to make with the help of OSHPark. With a bit of drag soldering it would be easy to hand solder as well. I opted to order a stencil from OSHStencils and use my re-flow oven just to make it look nice and professional.




OSHPark Shared Project: (Just click order now)
https://oshpark.com/shared_projects/PKPgfF7q

Bill of Materials:
https://docs.google.com/spreadsheets/d/12azxrOXTphC75ShBOmVUEJG1oJav0N1jhAYYi9JiIA4

Notes:
  • You don't need the EEPROM parts anymore but the footprints are on the PCB if needed.
  • The transistor BSS138 was out of stock on Digikey so I ordered samples from Fairchild. 
  • I did have some issues with the cape affecting the power on boot process. It's okay during a reset though. So you can't attach it till after you power up. 
Software is where the magic happens. There is a pre-made image for the BeagleBone with everything loaded and configured to use the BeagleLogic. It's a recent image based on Debian instead of the older Armstrong builds. The nice thing is that it doesn't flash the eMMC so you can leave your existing setup alone and just pop in the SD card when you need your logic analyzer. Which is another reason that makes it a good option. I can still use the BeagleBone hardware for other projects and not keep it collecting dust in between uses.



BeagleLogic is setup to be used in two ways. One is the web based interface. Just power it up and fire up your web browser. You can use the USB NIC which will put the BeagleBone at 192.168.7.2:4000 or plug in the on-board Ethernet or even use WiFi with a USB dongle. Plenty of options for connecting to it.


There aren't many options in the web interface but it's a great start to be expanded. In my case I couldn't get the "Dump Raw Data" option to work, unless it saves to the BeagleBone and it's not downloaded via the browser which is what I was expecting. If you have a I2C bus that only talks a few times a second, it can be challenging to find the data just by scrolling. There is software triggering but you can't use it via the web interface. You can by means of the command line, which is the second way to capture your data.

The command line tools are provided by the Sigrok software suite. The output file can be exported to the desktop app, PulseView to do protocol decoding.

First you have to capture from the command line and specify how you want to trigger, which channels and the sample rate / sample limit.

Example:
debian@beaglebone:~$ sigrok-cli -d beaglelogic -c samplerate=5m -o outputfile.sr -C P8_45,P8_46 --samples=10000 -t P8_45=e,P8_45=e

Using WinSCP on Windows you can copy the output file to your desktop and open it with PulseView. The PulseView binary for various operating systems are available.


From this point, select the protocol using the last icon on the toolbar. Finally just click the protocol tab to configure it. (This took a bit to figure out.) Select the pins that map to clock and data in this case.


If you need to, look at timing use the cursors tool.




The BeagleLogic is a great inexpensive logic analyzer especially if you have a BeagleBone laying around collecting dust as I did. (It was supposed to eventually be for a robot project but now I want to use the new BeagleBone Blue.) The BeagleLogic has a lot of potential to be a full feature tool. One big thing that is missing is the ability to connect to it directly form the host without having to copy a file each time. I haven't tried running PulseView directly on the BeagleBone then using VNC to connect. Even as is, it's a useful tool and a good place to start if you have never used a logic analyzer. Be sure to visit Kumar's blog http://theembeddedkitchen.net/ There is a lot of good info - especially on PRUs. I had actually came across it researching some STM32 SDIO stuff earlier this year.


Due to the nature of OSHPark, I have two extra fully assembled. If anyone is interested in them please send me an email. william at blog domain.

Here are some other links with more info on BeagleLogic and Sigrok.
https://github.com/abhishek-kakkar/BeagleLogic/wiki/Using-BeagleLogic:-Post-processing
https://github.com/abhishek-kakkar/BeagleLogic
http://beta.beaglelogic.net/use-beaglelogic/
https://sigrok.org/wiki/Supported_hardware
https://hackaday.io/project/4395-beaglelogic
http://hackaday.com/2015/02/19/turn-your-beagleboneblack-in-to-a-14-channel-100msps-logic-analyzer/


Correction: The BeagleLogic doesn't need the ADC's but the BeagleBone GPIO's are only 3.3V

Sunday, December 20, 2015

openHAB Last Sensor Update

A few of the sensor nodes are battery powered so it is important to know if they have stopped transmitting. My previous system (which is still feeding openHAB) tracks last seen time stamp. In openHAB you have to set an item and a rule to handle that. This is one of the items at the bottom of this post that is required to remove my reliance on DomotiGa.



All this requires is one item to store the time stamp and a rule to update it whenever the sensor item receives a change. The only catch in my case is if the new value is the same as the current, it seems it is not triggered as an update. I am not sure if it is DomotiGa not sending or openHAB not triggering. So during the night I don't get as many updates. It's fine for now because when I setup a JeeNode to MQTT bridge, I can have that trigger the time stamp regardless if there is a sensor value change.

Items
 
DateTime        office_lastupdate       "Last Update [%1$tm.%1$td.%1$tY %1$tr]" 
 

You can use this site to help you format the datetime to suit your needs.
http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html


Rule
rule "Last Update Office"
when
        Item office_lightlevel received update or
        Item office_temp received update or
        Item window_office received update
then
        office_lastupdate.postUpdate(new DateTimeType())
end
 



Sitemap
 
 Text item=office_lastupdate valuecolor=[office_lastupdate>300="red",>240="purple",>120="orange",>0="green",<0 data-blogger-escaped-code="" data-blogger-escaped-red="">

Using the value color option you can quickly at a glance look at the time since update based on the color. Just adjust the values in seconds.


Reference
https://community.openhab.org/t/show-date-time-of-last-sensor-update/2114/9