Wednesday, March 11, 2015

Introduction to Rapid Prototyping: Wearable Devices

“Wearables”, the word that defines the next revolution in consumer electronics, gadgets are moving from being portable or mobile to being simply…wearable, either embedded inside your shirt fabric or around your wrist, in your shoes or in the necklace you are wearing, and even inside your sunglasses, anything you wear or touch your body can be employed as a mount for such gadgets to either measure your biological vital signals like body temperature, pulse rate, blood pressure, motion & physical activity, muscles, heart & brain activity, and/or provide you with real-time assistance like geo-navigation, healthcare monitoring, personal assistance (appointments calendar, to-do list…etc.).
In this article we will discuss main guidelines of designing and prototyping for wearable devices, the basic rules for prototyping doesn't differ much than the ones discussed previously in the first two articles in the series “Introduction to Rapid Prototyping, adding to them the following guidelines to complete the full picture:
  • It has to be light weight (both the gadget and power source).
  • With very small physical profile.
  • Ultra-low power consumption.
  • Easy user interface.
  • Flexible, so it can be shaped on human body.
  • Easy to install and setup.
  • Material made of has to be skin-friendly and never cause any biohazard (e.g. skin irritation, allergies…etc).
  • The gadget has to be electrically safe (no electric shocks, short circuits, dissipated heat).
The three stages of a wearable device: 1. Sensing, 2. Signal processing, digitization, data processing & storage,  3. Data transmission to a remote host for further analysis and visualization.
Sensors:
Sensors are electronic devices that convert physical quantities like temperature, light, motion…etc. to electric signals so to be easily interfaced to a computer, since computers don’t understand anything except electric signals (this simple definition of sensors targets non-technical readers).
Let’s make a list of the physical quantities a wearable gadget would measure and sensors that can be used in each case:
Physical quantity
Example
Sensor
Suggested mounting
 Motion (for humans or objects)
Walking, running, physical exercising.
Accelerometer can measure object acceleration.
Gyroscope can measure tilting/angle of inclination.
Wristband, embedded in shoes or fabric.
Heart rate
Heart pulse rate per minute
Pulse rate sensor
Wristband, ear clip.
Fatigue and exhaustion
Heart activity
Electrocardiogram (ECG)
Embedded in fabric.
Body temperature
Skin surface temperature, ambient temperature
Thermistor & thermocouple sensor.
Wristband, embedded in fabric
Shock
Physical impact
Piezoelectric shock sensor
Embedded in shoes/footwear.
Force
Weight, muscle strength/force
Strain gauge
Embedded in shoes/footwear.
Touch
Finger tips touch
Capacitive pads
Embedded in fabric.
Light
Ambient light, reflected light from a certain source
Photo-diode.
Wristband, finger clip.
Surface bio-signals
Muscles and limbs activity
Electromyogram (EMG)
Embedded in fabric/cloth.
Mental stress/activity
Brain activity like concentration, stress, emotion
Electroencephalogram (EEG)
Embedded in eyeglasses or headwear.

Example of off-the-shelf sensors and modules:
·       MXR7900: 2-Axis accelerometer from MEMS IC can measure up to ±0.5g acceleration in X- and Y-Axis.
·       LPY503AL: 2-Axis gyroscope from ST Microelectronics can measure up to ±30° degrees in yow- and pitch-directions.
·       TMP36: Ambient temperature sensor IC from Analog Devices.
·       OPT101: Ambient light sensor IC from Texas Instruments.
Power storage
The wearable device requires a power source to keep it running for enough time to do the required measurement or assistance to the user; however the known constraints of physical profile and weight of the wearable device must be taken into consideration when choosing the power source.
So far batteries are the best option for wearables in terms of physical profile and portability, however they aren’t sustainable and require replacement or recharging on regular basis, there are three different kinds of batteries available in the market for wearables:
  • Lithium Ion (Li-ion) batteries: the most commonly used type of batteries used in electronics, with the advances in technology it comes in different shapes and forms (flexible and solid).
  •  Solid-state batteries: made of semiconductor materials, usually meet the size require but have a very low capacity compared to Li-ion ones.
  • Super-capacitors: a high capacity electrochemical capacitors, their size and leakage problem are the main obstacles to use them in wearables. 
Energy harvesting
Another way of providing electric power to wearables is energy harvesting (AKA. energy scavenging), it is the process of converting waste energy from the surrounding environment found in the forms of heat, motion or light to usable electric power, this field is fairly new in comparison to batteries and research didn’t achieve to a revolutionary design that can replace batteries or any other form of energy storage till the date of the article. There are three types of energy harvesting based on the waste energy they harvest:
  • Thermal energy harvesting: harvesting waste heat from the surrounding environment or  from human body, Thermoelectric Generator (TEG) is used for this purpose.
  • Vibrations energy harvesting (VEH) is the process of harvesting waste kinetic energy resulted from motion and vibrations into electricity by the means of electromagnetic, electrostatic or piezoelectric transduction.
  • Solar energy: as most of readers have read or saw it before working, Photovoltaic (PV) cells are used to convert sun light to electricity and by far it is the most successful form of energy harvesting, solid glass solar panels aren’t easy to use with wearables but flexible solar panels are more convenient and design-friendly. 
Interface & Communication:
Microcontroller Unit (MCU):
The microcontroller is the processing unit of the wearable device responsible of reading the signals from sensors, process them to become useful data, display it to the user and finally communicate it if required with any external device via wired (USB as an example) or wireless means (Bluetooth, Zigbee…etc.). The microcontroller unit has to meet the power requirement of low power consumption since the whole gadget is running on a limited power supply like a battery, the following microcontroller families are good candidates for wearable designs in the sense of low-power consumption and low cost:
  • Texas Instruments MSP430, 16-bits RISC CPU.
  • Microchip PIC18 and PIC12, 8-bits RISC CPU.
  • ST Microelectronics STM8, 8-bits RISC CPU.
  • Atmel ATmega, 8-bits RISC CPU.
Data display and communication:
Another important feature a wearable gadget must have is data display, either by sending it to an external device or on the gadget itself using a small LCD display or LED indicators, and because of the of limitations in power supply and physical profile design most wearable designers prefer to send data to an external device for display. There are two ways to communicate data to external world:
  • Data is stored on an on-board memory then the user can retrieve it by connecting the gadget to a computer or a smartphone wired or wirelessly using USB, Bluetooth, Wi-Fi or Near Field Communication (NFC).
  • Data is communicated in real-time to a nearby device via short range wireless technologies like Bluetooth, Wi-Fi, ZigBee or similar protocols.
And here are some wireless enabled boards and modules that can be used for wearables either stand-alone or combined with a microcontroller unit:
Wireless communication between the wearable and display device is the preferred option for designers because it meets the portability and simplicity requirements easily, however this comes on the expense of power consumption since wireless communication modules are relatively power hungry when compared to the rest of the wearable components (MCU and sensors), however designers were able to overcome this problem by either lowering the data rate (speed), range and non-continuous transmission, low power technologies like Bluetooth Low Energy (BLE) and ZigBee use these techniques to lower power consumption and extend battery life.

Other design ideas
  • As discussed previously wearables have to be small and light, also “flexible” if possible to take the shape of the human body/part it is worn on, and here comes the benefit of “flexible printed circuit board” (or Flex PCB), it is made of special polymers to be physically flexible and bend easily without any impact on the electric connections or components mounted on its sides.
  • Conductive threads/plates: can be used to detect electric connectivity from an outside source or help transmitting a specific signal through clothes fabric.
  • 3D printing: to accelerate prototyping of wearable gadgets 3D printing is a good option and much lower in cost in comparison of similar alternatives like mold injection and casting.
Flexible PCB
(Source: http://edablog.com/2009/03/10/utcp-wearable-electronics/)
Components manufacturers
This is a list of the most known manufacturers of sensors and semiconductors that can be used in wearable designs:
  • Inertial sensors (accelerometers & gyroscopes): MEMS IC, STMicroelectronics, Analog Devices.
  • Temperatures sensors: Maxim Integrates, Texas Instruments, STMicroelectronics, Analog Devices, Microchip Technologies.
  • Light sensing: Texas Instruments.
  • Analog Front End (AFE), Analog to Digital Converter (ADC), Sensor interface chips: Texas Instruments, Linear Technologies, Maxim Integrates, Analog Devices, Microchip Technologies.
  • Energy harvesting solutions: Linear Technologies, Texas Instruments, Cymbet.
  • Low-power microcontrollers: STMicroelectronics, Texas Instruments, Microchip Technologies.
  • Flexible solar cells: http://www.flexsolarcells.com/PowerFilm-Solar-OEM-Components.php
For board design the following software tools are quite helpful for PCB layout, schematic capture and 3D design & modelling:
  • PCB layout and schematic capture tools: DipTrace, KiCad, Altium, PCB Artist, OrCad, Mentor Graphics Pads.
  • 3D design & modelling: SolidWorks, AutoCAD Inventor.
And since you have reached this point in the article then possibly you are thinking of building your own board, these companies offer PCB manufacturing services at low cost for prototyping purposes:
Last but not least, this article is meant to be an introductory material for hobbyists and developers interested in learning rapid prototyping for wearable gadgets but it doesn’t cover everything; this article is meant to be your first step, meant to make you more hungry and curious to know more about wearables, so good luck.

--
Karim El-Rayes
March 11, 2015
Vancouver, Canada

Wednesday, November 12, 2014

Introduction to Rapid Prototyping: Internet of Things

Internet of Things, or IoT for short, is one of the new big trends in technology, in brief, it is about making everything and anything connected to the cyberspace of the internet, so you can access your home via your smartphone, or make your car talk to you or to other cars, from the smallest temperature sensor on top of your house to the biggest data centers and servers everywhere are going to be connected, though the matter of data security is still in debate but undoubtedly IoT will help to improve many services.

In this article, we will continue the discussion about different platforms for low-cost rapid prototyping, but we will be more specific and target only platforms suitable for IoT applications, compare them from price and technical perspectives. Mainly an IoT platform needs two features:
-        Internet connectivity, the platform must be equipped with some sort of a connectivity interface to the internet via a wired Ethernet, Wi-Fi, Bluetooth or at least with a USB that is connected to PC or a modem to connect it to the internet or any other sort of networks.
-         Web service: an IoT platform in most cases is required to have an onboard web server, not necessarily an advanced one; in many cases just a light weight web server is more than enough to communicate the data to other peers/terminals.

First let’s start with most common low-cost development kits that support network/internet connectivity via Ethernet and Wi-Fi, though they are quite handy for controls applications, compact form factor applications, home appliances and others but requires a lot of work on the low-level programming side, hardware wiring and packaging:  

-        Arduino YÚN: 66.36$
CPU: Atmega32U4 8-bit RISC.
Connectivity interfaces: wired Ethernet, Wi-Fi and USB
Development environment/IDE: Arduino IDE (C -like programming language).
Website:

-        Arduino Blend: 32$
CPU: Atmega32U4 8-bit RISC.
Connectivity interfaces: Bluetooth.
Development environment/IDE: Arduino IDE (C -like programing language).

-        Tiva C Connected LaunchPad: 20$
CPU: 32-bit ARM Cortex-M4/120 MHz
Connectivity interfaces: wired Ethernet, USB (host or device).
Development environment/IDE: TI Code Composer Studio (C/C++), Energia IDE (the Arduino IDE equivalent for TI Launchpad kits, C –like programming language).

-        SimpleLink Wi-Fi CC3200 LaunchPad: 30$
CPU: 32-bit ARM Cortex-M4.
Connectivity interfaces: Wi-Fi
Development environment/IDE: TI Code Composer Studio (C/C++), Energia IDE (the Arduino IDE
equivalent for TI Launchpad kits, C –like programming language).

-        Intel Edison: 50$
CPU: 32-bit Intel Quark/100 MHz.
Connectivity interfaces: Wi-Fi, Bluetooth.
Development environment/IDE: Edison Arduino IDE.
Note: Requires Arduino expansion kit for development and prototyping purposes.

-        Microchip Comm Demo Board: ~50$
CPU: Microchip 32-bit MIPS
Connectivity interfaces: Wi-Fi.
Development environment/IDE: MPLAB IDE and C32 compiler.
Website:

-        PIC32 Ethernet Starter Kit-I and -II: 75$ and 89$
CPU: Microchip 32-bit MIPS/80 MHz.
Connectivity interfaces: wired Ethernet, USB (host & device).
Development environment/IDE: MPLAB IDE and C32 compiler
Website:

Particle Core (formerly Spark Core): 39$
     CPU: ARM Cortex-M3/72 MHz.
     Connectivity interfaces: Wi-Fi.
     Development environment: Web-based IDE using REST API.
     Website: https://www.particle.io/

NodeMCU: ~7-13$
    CPU: 32-bit Xtensa LX3 Architecture (A.K.A. ESP8266).
    Connectivity interfaces: Wi-Fi.
    Development environment: Lua, ESPlorer, Arduino IDE.
    Website: www.nodemcu.com
    Arduino package for NodeMCU: https://github.com/esp8266/Arduino

HC-05 and HC-06 (Serial (UART) to Bluetooth module): ~3.5-5$
   CPU: N/A.
   Connectivity: Bluetooth and UART.
   Development environment: There is no standard development environment for the HC modules, they can be easily integrated with any system that supports standard UART interface.
   Datasheet:
   http://www.tec.reutlingen-university.de/uploads/media/DatenblattHC-05_BT-Modul.pdf

These platforms aren’t specifically designed for IoT applications but they support it through general purpose operating system (Android, QNX, Linux…etc) they operate on, the main advantage of such platforms is the high computational power they offer in comparison to other platforms mentioned previously like advanced webserver/web hosting, running complicated algorithms and multitasking, however, they aren’t suitable for low-power or battery powered applications:
                                                                              
-        Raspberry Pi Model A+: 20$
CPU: ARM11/700 MHz/256 MB.
Connectivity interfaces: USB (host), ability to connect to Wi-Fi or Bluetooth via USB Wi-Fi adapters.

-        Raspberry Pi Model B+: ~38$
CPU: ARM11/700 MHz/512 MB or 1GB.
Connectivity interfaces: wired Ethernet, USB (host), ability to connect to Wi-Fi or Bluetooth via USB Wi-Fi adapters.

-        BeagleBone Black: 55$
CPU: Texas Instruments AM335x ARM Cortex A-8/1 GHz.
Connectivity interfaces: wired Ethernet, USB (host), ability to connect to Wi-Fi or Bluetooth via USB adapters.

-        Intel Galileo: ~64$ (G1), ~75$ (G2)
CPU: 32-bit Intel Quark SoC X1000/400 MHz.
Connectivity interfaces: wired Ethernet, USB host and device.
Development environment: Arduino IDE, Linux port is available for this platform.

Other platforms designed specifically for IoT

-        Kinoma: 149$
Description: A JavaScript powered IoT construction kit
CPU: ARM/800 MHz.
Connectivity interfaces: Wi-Fi, Bluetooth, USB OTG.
Development environment: Kinoma Studio.
Website:  http://kinoma.com/

-        Wunderbar: 199$
Description: Wi-Fi enabled sensor modules (Humidity, Temperature, Light/Color, Motion…etc).
CPU: Freescale ARM Cortex-M4 MK24
Connectivity interfaces: Wi-Fi, Bluetooth.

-        1sheeld: 55$
Description: a platform that uses smartphone as an Arduino shield via a Bluetooth breakout board for connectivity purposes.
CPU: N/A; depends on the smartphone connected.
Connectivity interfaces: Bluetooth.

Update (December, 2014):

Your data to the Cloud:
Cloud platforms for IoT offer internet connectivity & communication, data visualization,  activity monitoring and remote access services for IoT devices/nodes; you can connect your device through any of these platforms to a personal/corporate emailing system, home automation, public access and many other applications, most known cloud platforms to date of the article:
- Exositehttp://exosite.com/ : For data visualization, logging and node's remote control.
- Temboohttp://www.temboo.com/ :data visualization, activity logging, node's remote control, communication via email and other social networking platforms, data storage...etc.
- Nexmohttps://www.nexmo.com/ : For communicating via Short Text Messages (SMS) with your node.
- IBM IoT Foundationhttps://internetofthings.ibmcloud.com/ : For data visualization, logging and node's remote control.
- PubNub: http://www.pubnub.com/ :data visualization, activity logging, remote control.

Last but not least, we all know technology advances rapidly, and all these kits and platforms we reviewed as the latest trend might get obsolete in the near future and something else will come up to replace them, all what I wanted is to give you the first step to get through the door of IoT electronics but my advice is keep developing yourself, update yourself with the latest and don’t wait.
   
The author would like to thank Hesham Omran, a multimedia researcher, for his input and contribution to the article.

--
Karim El-Rayes
Nov. 12, 2014
Vancouver, Canada

An example of a wireless controlled robotic arm over home Wi-Fi network using Texas Instruments Tiva C Connected LaunchPad development kit:

Wednesday, September 24, 2014

Introduction to Rapid Prototyping

Most of the time when a hardware engineer, hobbyists or technical instructor/tutor come up with an idea it takes him/her ages to realize it and build a proof of concept, in this article we are going to list as many of hardware platforms, CAD and software development tools required to accelerate prototyping and realize your idea in a shorter period of time.  
Basically, almost all hardware designs and products include one microcontroller unit (MCU) or more depending on complexity of the design, and usually MCU circuit might get complicated especially if you don’t have a full, clear image of the project, so a development kit would be the best solution, it takes away the burden of building MCU hardware and provide you with generic features to use for testing and prototyping like GPIO headers and easy wiring, LEDs, connectors (USB, DB-9…etc), so, here is a list of most popular low-cost MCU platforms:   

- Arduino platforms: a series of MCU platforms based on Atmel 8-bit and 32-bit microcontrollers, the cheapest one is Arduino Uno for 25$, development environment required: Arduino IDE (free). Website: http://arduino.cc/

- Texas Intsruments LaunchPad (LP) series: another low cost MCU kits based on Texas Instruments 16-bit and 32-bit microcontrollers, LP kits prices range from 10$ to 30$, development environment required: Energia (free) or Code Composer Studio (lite version is available for free).
Energia IDE: http://energia.nu/

- STM32VL Discovery kit: a low cost MCU kit based on STMicroelectronics ARM Cortex-M0 32-bit microcontroller, kit’s price: 15$, development environment required: IAR embedded workbench. Website: http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/PF250863?sc=stm32-discovery#

- Cypress PSoC 4 CY8CKIT-049 4xxx: a very low cost MCU kit (for 4$ only) based on Cypress PSoC4 microcontroller platform, development environment required: PsoC Creator (available for free on Cypress semiconductor website).

If you are looking for a low cost connectivity platform for home automation, data acquisition, controls, IoT (Internet of Things), remote access/sensing and computer interfacing applications then these are my recommendations:

MCU kits with Wi-fi connectivity:
- Texas Instruments CC3200 Launchpad (30$)
- Texas Instruments CC3100 (20$) and CC3000 (35$) boosterpacks (i.e. expansion boards) for Texas Instruments Launchpad Kit.
- Arduino wi-fi shield.

MCU kits with wired Ethernet connectivity:
- Arduino Ethernet, price: 51$.
- Texas Instruments Tiva C connected Launchpad, price: 20$.
- PIC32 Ethernet Starter Kit, price: 75$

MCU kits with USB connectivity:
- Texas Instruments MSP430F5529 Launchpad, low cost and very powerful platform for 13$ only.
- Texas Instruments Tiva C (for 13$) and Tiva C Connected Launchpad (20$) kits.
- PIC32 USB Starter Kit II, price: 55$.

But if you have your mind set to add USB connectivity to your design directly then you can use chipsets with standalone USB peripheral controller like:
- FTDI USB chipsets and modules (USB to UART/RS232, RS485, I2C, JTAG, SPI).
- Maxim Integrated MAX3420E USB peripheral controller with SPI.

Or use an MCU with built-in USB module like Microchip PIC18F4550 and PIC18F4553 microcontrollers, but they don’t come pre-programmed with USB stack, you will have to compile the USB stack and program MCU yourself.

For motor control and lighting related applications you will need an MCU with plenty PWM pins and capable of handling real-time control, like Texas Instruments C2000 LaunchPad  for 17$, but usually low cost kits don’t come with power drivers on-board, you will have to build additional circuit for this purpose or buy an expansion board for the kit that provides power drivers.
Note: power drivers are H-bridge circuits, power switches, power transistors.

If you are willing to build your own power driver circuit and control it from an MCU kit then these are my recommendations for chipsets (easy to use, their circuitry aren't complicated):
- L298: Full bridge IC (maximum current: 2A).
- L293B: quad push-pull driver for motor and actuators control (maximum current: 0.5A per channel).
- ULN2803: darlington pair array (8 pairs, each 500mA).
- ULN2069: darlington pair array (4 pairs, each 1.5A).
- L297: Stepper motor controller.

If you want to go more advanced to develop mobile applications and embedded operating systems for entertainment, display (with displays, touch screens or projectors via HDMI), gaming, standalone web-services and connectivity applications using any of the popular embedded operating systems (Android, embedded Linux, Windows mobile/CE, QNX OS) but you don’t want to spend a lot then I would recommend you these kits:
- BeagleBone Black (55$).
- Raspberry Pi (35$).

Second phase, if you are good at hardware and not afraid to build your own boards or willing to learn, these tools are quite useful for schematic capture and PCB layout (i.e. drawing schematics and printed circuit board layout/wiring):

- DipTrace: schematic capture and PCB layout tool, demo version is available for free.
- PCB Artist: PCB layout tool, free.
- Eagle PCB: schematic capture and PCB layout tool, free.

Now your design is ready and you want to build it, you have two options, to build your PCB yourself YouTube is full of videos and tutorials on how to do it OR you can send your design to a professional PCB fabrication/manufacturing services like:

Important note: depending on local preferences and availability choose your PCB fabrication/manufacturing, these aren't the best or the cheapest but the most convenient to me, might be different for you or where you are.
Hardware and software go hand-in-hand in most of modern designs, you can’t develop an MCU based design with writing a firmware for it, and these are my recommendations for software development tools you might need to speed up prototyping for your project:

C/C++ compiler and IDE (all free):

Other useful software libraries:
- DISLIN: C/C++/Fortran library for 2D/3D plotting and GUI design (free for academic and non-commercial use): https://www.mps.mpg.de/dislin/
- Basic4Android: for Android mobile apps development, free trial for 30 days is available: http://www.basic4ppc.com/
- Processing: A programming language and IDE used for rapid prototyping, supports development for both PC and Android OS (free): https://processing.org/
- MoSync: C/C++ Software Development Kit (SDK) and IDE for Android development, useful for rapid prototyping Android apps (free): http://www.mosync.com/
- VISA IVI: C/C++ library for communication with external devices over USB, TCP/IP, serial and PXI/VXI (free): http://www.keysight.com/en/pd-1985909/io-libraries-suite-162?nid=-33330.977662.00&cc=CA&lc=eng&cmpid=zzfindiosuite
OR from: http://ivifoundation.org/shared_components/Default.aspx
- SDL: C++ library for gaming and graphics (free): http://www.libsdl.org/
- GNU Scientific Library: C/C++ numerical library (free): http://www.gnu.org/software/gsl/
- HIDAPI: C/C++ library for communication with USB-HID devices (free): http://www.signal11.us/oss/hidapi/


--
Karim El-Rayes
Vancouver, Canada
September 24, 2014

Saturday, April 20, 2013

Quick USB Tutorial - Build your own USB device with PIC18F4550

Since I'm a big fan of USB technology, and I'd to share my experience about how to build your own USB device with everyone, so will introduce you a short tutorial about how to build a USB interface and where you can get the hardware and software required.
Before you start you will better comfortable with microcontrollers, C programming language and basic electronic circuits.

Why USB?
Because it’s a recent modern technology, you can find everywhere in all computers and handheld devices as well.

How to build a USB Interface?
- You need the hardware: a USB interfacing chip or a microcontroller with a built-in USB module.
- If you are using a microcontroller with a built-in USB module, then you will need the firmware that includes the “USB stack” to be downloaded on it, so the internal CPU can communicate over the USB.
- On the PC side, you will need a library that will communicate with the USB device, and it is dependent on the USB device "class" you decided to use, like if your hardware will appear as an USB HID class then you will need a C/C++/C#/Java...etc library to communicate with it, if you are using USB CDC class it is easier cause you can use COM (serial) port APIs to communicate with it.

Why I prefer USB CDC class interface devices more than other USB device classes?
- Because the microcontroller or the USB chip will appear to your PC as a virtual COM (serial RS-232) port, which ease the development of the application on your computer side to communicate with the USB device you designed, you can use the same APIs in C++/C#/Java or even Python to communicate.
Examples:

  • “MAX3420” USB chip from Maxim Integrated.
  • “FT2232” USB-to-Serial chip from FTDI.
  • Microchip “PIC18F4550”, a microcontroller with built-in USB module.
A ready-made USB projects for this microcontroller and others can be found inside "Microchip Application Libraries": 

Building USB interface with PIC18F4550 microcontroller:
I will share with you my experience about" how to build a USB interface" using PIC18F4550 microcontroller from Microchip, this tutorial is intended for people who are little experienced in Microchip microcontrollers.

First to know, USB is a mix between hardware and software stack, unlike PC parallel or serial ports interfaces which rely more on the hardware.

USB devices are categorized into classes, i.e. each group of USB devices that have similar features are grouped under what is called "Class", we have many USB classes like:

  • HID class for USB mice and keyboards.
  • Printer class for USB printers.
  • CDC class for USB-to-Serial converters and COM port communication.
  • Mass storage class for USB flash drives and HDD's.

In this tutorial I will show how to build USB-CDC class based device with the PIC18F4550 microcontroller, first download and install in sequence the following:


- MPLAB IDE from Microchip official website, registration required, its for free: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002
- C18 C-compiler from Microchip, Academic version is for free:
- Microchip application libraries, group of open source, ready-made projects developed by Microchip corporation that supports a wide range of their products, all projects developed in C: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en547784
After you finish installing everything, go to this path on your hard drive:
"C:\[Microchip Solutions Directory]\USB\Device - CDC - Basic Demo\Firmware\USB Device - CDC - Basic Demo\C18 - PICDEM FSUSB” project file.


Open project file "USB Device - CDC - Basic Demo - C18 - PICDEM FSUSB", this is a USB - CDC firmware for PICDEM development kit from Microchip Technologies, this kit is based on the PIC18F4550 microcontroller.
Build the project then burn it to your microcontroller, when you connect your microcontroller to a PC, a "New device found" wizard will pop-up, browse the device driver file in:
C:\[Microchip Solutions directory]\USB Device - CDC - Basic Demo\inf

After installation is done, open your device manager, you will find under "COM & LPT" your microcontroller installed as virtual COM port, from here you can interact and communicate with your microcontroller with the usual API's for COM port in any programming language you prefer.

This is a simple tutorial about how to build an application to interface COM in Win32 API's: http://msdn.microsoft.com/en-us/library/ff802693.aspx

and this a free and easy to use IDE and C/C++ compiler to develop your applications on the PC side: http://www.bloodshed.net/dev/devcpp.html




Continuing the discussion, you can modify the source code of the "CDC - Basic Demo - Firmware" project since its open source.


To add new headers to the code, search for headers files declaration in the code and add yours to them.


To add and declare new variables to the code search in the beginning in the code for a comment "Variables", under you can declare and initialize your variables.

To configure and enable modules of the PIC18F4550, you can do this in the "main( )" function, but take care not to configure any module inside the "while(1)" loop.

To add any I/O interacting process related to the microcontrollers I/O, you can add them inside the "while(1)" in the "main()" function or in "ProcessIO()" function, both ways are fine.






USB Interface circuit using PIC18F4550 microcontroller


Bill of Materials (BOM):
U1: PIC18F4550 8-bits microcontroller.
X1: 20 MHz crystal.
C1, C2: 18 pF capacitors.
C3: 470 nF tantalum capacitor.
R1: 1 K Ohm resistor.
PB1: push button.

Update (May 2014): 
Microchip has a newer version of the PIC18F4550 microcontroller, the PIC18F4553, its identical to the PIC18F4550 but with a better resolution built-in Analog to Digital converter (A/D) which is  12-bits (the old one is 10-bits only), to configure the USB stack to work with the new PIC18F4553 microcontroller please follow the instruction in this link: http://www.eee.metu.edu.tr/~design/lib/exe/fetch.php?media=lecture_notes:tutorial_1_-_implementation_of_a_usb_based_pic-to-pc_communication.pdf


Update (July 2016):
A copy of a USB-CDC firmware demo project for PIC18F4550 microcontroller based on Microchip Application Libraries is available on GitHub, read "ReadMe.txt" file first before setting up your project: https://github.com/kelray/USB-CDC-stack-for-PIC18F4550


If you are not familiar with Microchip development tools for PIC microcontrollers here is a simple starter guide how to use MPLAB IDE and C18 compiler from Microchip Inc. to develop applications and code for various PIC microcontroller in general and PIC18F4550 in specific as an example in this tutorial.

links and websites in the article might change or get outdated, so rely on google if  the link is not working.

This is an example project using PIC18F4550 microcontroller as a dual channel USB data-logger/oscilloscope:

Thursday, July 5, 2012

التجربة الكندية 3: التطوير للجميع, ممكن؟


حضرت من فترة, بحكم عملي في مجال الهندسة و ابحاث الالكترونيات, مؤتمر قصير لمدة وم واحد بمدينة تورنتو عقدته احد شركات الالكترونيات المشهورة و و آتى معها مجموعة من الشركات الصغيرة تستخدم مكونات من إنتاج الشركة الاولى في صناعة منتجاتها لعرضها, و كانوا قد عرضوا علينا اخر ما توصلوا إليه من منتجات و افكار, و الاهم عرضوا علينا اهم أدوات تصميم و تطوير بعض من هذه المنتجات و الكثير منها كان يعتمد على تقنيات حديثة للغاية كنا نعتقد ان الحصول عليها او الدخول الى نطاق تطويرها يتطلب الكثير من الإمكانيات, لكنهم يتيحوا لنا الفرصة ان نتعلم هذه التقنيات و الأدوات.
و في نهاية اليوم قال وجدت صديقي الالماني الذي حضر معي فعاليات هذا المؤتمر لاول مرة "إن ما رأيناه اليوم مبهر", صمت لبرهة و تذكرت كل المؤتمرات و المناسبات من نفس النوع التي حضرتها في كندا في الثلاثة اعوام الاخيرة و تذكرت ان كلها كانت مفيدة للغاية و في احيان كانت "مبهرة" مثلما قال صديقي, في هذا المقال سأحكي عن هذا النوع من المؤتمرات و بعض الظواهر النتائج المرتبطة بها و سأترك للقارئ رحلة الوصول إلى الاستنتاجات و الانعكاسات على صاحب التجربة.

التدريب و المؤتمرات
جزء لا بأس به من الشركات العاملة في مجال التكنولوجيا و تقنيات المعلومات بجميع فروعها يعتمد في جزء من سياسته الدعائية و الإنتشار على "الجامعات", اي ان يذهب الى الجامعات لتقديم عرض بسيط عن منتجات الشركة امام الطلبة و الاساتذة, و لا مانع من أن تقدم الشركة تدريب لمدة يوم او اكثر للطلبة "بدون مقابل" على احد منتجاتها لا سيما المنتجات التي تستطيع أن تخدم المجال الاكاديمي و العملي في نفس الوقت, و في احيان كثيرة تقدم هذه الشركات عينات من منتجاتها هدية للمشاركين على أمل أن يقرر احد الطلاب إستخدامها في مشروع خاص به او يوصى بها لزملاء آخرين او مستقبلا يوصى بها للشركة التي سيلتحق بها بعد ان ينهي دراسته. 
  
العينات
في دول العالم الاول شركات كثيرة في مجال تخصصي, الالكترونيات, تقدم العديد من العينات و الهدايا المجانية من منتجاتها, في المقابل يطلبوا من الشخص بيانات الاتصال به (الاسم, المهنة, التليفون او اي وسيلة اتصال آخرى), و يحتفظوا بها في قاعدة بياناتهم, ثم بعد فترة ما يبدأ مندوبي الشركة في الاتصال بالعملاء الذين حصلوا على عينات و هدايا ليسألوهم عن رأيهم و إن كان عندهم اي خطط مستقبلية لشراء منتجات الشركة و إستخدامها.

مهندس التطبيقات
تعرفت منذ سنوات قليلة على منصب غريب جدا موجود في اغلب الشركات العاملة في مجال إنتاج التقنيات المتقدمة و تقنيات المعلومات و البرمجيات, الا و هو منصب "مهندس تطبيقي" Application Engineer و هو منصب لم اسمع به عندما كنت اعمل بمصر, و ان كان بدء يظهر مؤخرا على استحياء في بعض الشركات, و لكن لم اعرف أهمية هذا المنصب الا بعد سفري لكندا, اكتشفت أن اغلب الشركات العاملة في المجال قد تمتلك إدارة كاملة من مهندسي التطبيقات, و مهام هذا النوع من المهندسين هو الذهاب في رحلات عمل لزبائن الشركة لتدريبهم على المنتج الذي اشتروه من الشركة, او الذهاب لزبائن محتملين للشركة او الذهاب للجامعات لعقد سلاسل التعريف و التدريب على منتجات الشركة, و مهندس التطبيقات يختلف في مهامه و اسلوبه و نوعية الخبرة المطلوبة من عن مهندس المبيعات Sales Engineer, حيث يكون يجب ان يتمتع بالقدرة على الشرح و توصيل المعلومة, الخبرة العملية و قدرة حل المشكلات للتواصل مع افكار العميل و تطلعاته في إستخدام منتج شركته ضمن مؤسسته.
نعود للموضوع الاساسي, مهندسي التطبيقات هم من رأيتهم يطوفون كندا لتقديم التعريف و التدريب و المشورة لطلبة الجامعات و و الاكاديميين و المهندسين من خلال المؤتمرات العملية القصيرة او المحاضرات و الندوات و غيرها.
لماذا تفعل الشركات كل هذا؟....ما هي مكاسبهم؟.....ما هي الانعكاسات التي تراها على المجال التقني من انتشار هذه الثقافة؟....في رأيي هذه الاسئلة تستطيع ان تحدد جوانب الإستفادة.

اكتب مقالاتي بشكل موجز حتى لا اصيب القارئ بالملل او الضجر, حيث اني لا اتمتع بمهارات كتابية عالية و اي استفاضة مني في الموضوع قد تضعف الاستفادة منه, و اشكرك على القراءة في جميع الاحوال.

كريم الريس
وواترلو, كندا
يوليو 5,
2012

Tuesday, June 12, 2012

التجربة الكندية 2 : المسؤلية الاجتماعية



لن اتحدث في هذا المقال عن المسؤلية الاجتماعية و أهمية العمل التطوعي او غيره من الانشطة الاجتماعية فقد تحدث الكثيرون قبلي عنها و أشهر من تحدث عن هذا الموضوع هو د. شريف عبد العظيم مؤسس جمعية رسالة بشكل اكثر تفصيلا و تحليلا و لكن سأسرد في المقال ما قابلته في كندا من حكايات و مواقف وبعض الاستنتاجات فيما يتعلق بالمسؤلية الإجتماعية و سأترك للقارئ التحليل و إستنتاج الدروس المستفادة.

عندما سافرت الى كندا للدراسة في بداية 2010, و كانت اول تجربة سفر لي خارج الحدود, بدأت بالاحتكاك مع المجتمع الكندي و لكن لم تتح لي الفرصة في البداية غير الاحتكاك و التفاعل مع طلبة جامعيين في مثل سني و ظروفي, و لكن بعد مرور بعض الوقت بدأت في التفاعل اكثر مع اشخاص من فئات عمرية و خلفيات عملية و ثقافية مختلفة, و قد لاحظت ان هناك البعض يشارك في بعض الانشطة بالمدرسة الابتدائية القريبة من منزله مثل القراءة للأطفال, و البعض يجمع الكتب و يرسلها "للمساجين", وجدت في الجامعة من يتطوع لمساعدة الطلاب الاجانب لتحسين لغتهم الانجليزية  بل و الاغرب, من وجهة نظري آنذاك, وجدت داخل الجامعة مكتب مختص بإدارة و توجيه الطلاب للأنشطة التطوعية تحت اسم WPIRG و عرفت انه يوجد مكتب مثله في كل الجامعات الكندية, و قابلت طلبة مدارس في المرحلة العمرية 8 ل 12 سنة يبيعون الشيكولاتة على ابواب المتاجر او في الشوارع الرئيسية لجمع تبرعات لمدارسهم, هناك من يجمع المعونات و الملابس القديمة للفقراء و ملاجئ المشردين او إرسالها الى احد الدول المنكوبة, احد المواقف التي أثارت انتباهي بشدة يوم انقطعت الكهرباء عن اغلب المدينة التي اعيش بها لعدة ساعات و كنت عائد في طريقي للمنزل لأرى واحد من سكان المنطقة يلبس "صديري فسفوري" و ينظم المرور في التقاطع القريب من المنزل نظرا لتعطل "إشارة المرور" نتيجة لإنقطاع التيار الكهربي.

الحكاية المذكورة كانت جزء من ملاحظاتي للأنشطة التطوعية في محيط المدينة التي اقطن بها, استنتجت أنه من الطبيعي او المعتاد أن تشارك في اي عمل تطوعي خلال اي مرحلة من عمرك, إذا عندما يرى الطفل الصغير الكل من حوله يشارك فيتعلم من الصغر المشاركة و التفاعل في العمل التطوعي, فالأمر اصبح له "بديهيا" الى حد ما.

داخل المؤسسات الكندية  "فكر" او ثقافة تعرف "بالمسؤلية الاجتماعية "Social commitment للمؤسسة, و هو يحدد و يؤسس لدور المؤسسة في التفاعل و خدمة المجتمع سواء على المستوى الوطني او المجتمع الموجود في المحيط الجغرافي للمؤسسة, حيث تنص اغلب قواعد المؤسسات الصناعية و الاقتصادية في كندا على مسؤليتها تجاه المجتمع الكندي و مشاركتها فيه, و ترد الحكومة الكندية على هذا التفاعل الاجتماعي بشكل ايجابي يتمثل في تخفيض ضريبي "مميز" لهذه المؤسسات حسب تفاعلها مع المجتمع و تقديمها مساعدات, بل و تقديم الشكر و التقدير لهذه المؤسسة و تقديم خدمات و تسهيلات عملية و مالية لهذه المؤسسة في حال تعرضها لأزمات.

في جامعة وواترلو, حيث درست, وجدت "عرف" او اسلوب متبع ليس فقط بهذه الجامعة و لكن باغلب الجامعات الكندية, خريجي الجامعات هنا فخورين جدا بالجامعات او المعاهد  التي درسوا بها و على اتم استعداد ان يقدموا يد العون للجامعة او المعهد الدراسي في اي وقت في شكل تبرعات, محاضرات و لقاءات مع طلاب الجامعة, التعاون مع الفرق البحثية و الانشطة الطلابية بالجامعة و دعمها من خلال المؤسسات التي يعملون بها, و الاهم, تحرص عليها إدارة الجامعة على بناء شبكة قوية للمساعدة في توظيف طلابها إما اثناء الدراسة فيما يعرف عندنا بالتدريب الصيفي او التدريب العملي لتنمية خبرتهم العملية و العلمية على حد سواء و مساعدة طلبة الجامعة بشكل غير مباشر في بناء شبكة علاقات تساعدهم في ايجاد وظائف بسهولة مستقبلا بعد تخرجهم, و إبقاء هذه الدائرة و الشبكة مستمرة و متشعبة.

عندما يصل اي من خريجي هذه الجامعات الى منصب مهم في الصناعة و مجالات السوق الآخرى في احيان كثيرة يتبرع اما هو شخصيا او عن طريق المؤسسة التي يعمل بها, عادة ما تكون هذه التبرعات في شكل معدات و ادوات معملية و هندسية غالية لا يقدر الطلاب على شراؤها, معامل كاملة التجهيز, نشرات علمية متطورة لا يستطيع العامة الحصول عليها, او تقديم الإستشارات العلمية و الفنية لطلاب.

هنا يأتي السؤال: "لماذا يتطوع هؤلاء؟......و ما مكاسبهم من العمل التطوعي؟".....كان هذا هو السؤال الذي طرحه عقلي وقتها حيث ولدت و عشت في بلد ثقافة العمل التطوعي بها نوع "شغل وقت الفراغ" و رفاهية عند اغلب الناس.....برغم مشاركتي في بعض الاعمال التطوعية البسيطة من قبل في مصر إلا إني لم أكن اعتبرها نوع من "الالتزام" او المسؤلية, لكن هنا النظرة مختلفة و الكل جاد, هنا جاء وقت التساؤل داخل نفسي و البداية لتغيير بعض من أفكاري تجاه هذا الموضوع.

كتبت هذه المقالة في فبراير 2012 و نشرت في شهر يونيو من نفس العام.  

كريم الريس
وواترلو, كندا
يونيو 12
2012

Sunday, December 4, 2011

التجربة الكندية 1: الجامعة

تعريف موجز بكاتب المقال, مهندس مصري حاصل على درجة الماجستير في الهندسة الكهربية من جامعة وواترلو بكندا, حيث عمل بالجامعة باحث و معيدا بها لمدة عامين, و من واقع ما عاصره يحكي لكم عن تجربته الشخصية و ملاحظاته عن التجربة الكندية في تنمية "حب العلم" و التعلم و تطوير ملكات البحث العلمي و الابتكار للنشأ في مرحلة التعليم ما قبل الجامعي و تحديدا للصغار ما بين عمر 7 و 14 سنة.
عندما بدأت دراساتي العليا في يناير 2010 كنت الاحظ من آن لآخر في محيط الجامعة و تحديدا في المباني او المناطق التي بها المعامل و الورش الهندسية الخاصة بالطلبة, حيث ان هناك معامل اخرى مخصصة لفرق الابحاث فقط و تختلف في تطورها و تخصصها عن المعامل المخصصة للطلاب و الانشطة العلمية, زيارات لاشخاص يبدو من اعمارهم انهم ليس من طلبة الجامعة و معهم عادة شباب اصغر سنا (في عمر طلبة المرحلة الثانوية حسب ما استنتجته), و اتضح لي انهم مجموعة من الاهالي مع ابنائهم الذين في غضون سنة او عدة اشهر سينهون مرحلة التعليم الثانوي و بدأوا مرحلة البحث عن افضل الجامعات للدراسة بها, و ان الجامعة تخصص لهم مجموعة من طلابها لإرشادهم داخلها و شرح إمكانيات الجامعة و نظامها التعليمي.
ثم لاحظت في الصيف و تحديدا اثناء الإجازة الصيفية للمدارس ان الجامعة تفتح ابوابها لطلاب المدارس من مختلف المراحل من خلال برنامج تعاون مع المدارس الموجودة في المدينة التي اقيم بها, وواترلو, لتقديم برنامج ترفيهي و تعليمي لهولاء الطلبة من خلال اشراكهم في العديد من الانشطة و التجارب العلمية المبسطة داخل حرم الجامعة, كذلك الذهاب بهم في جولات لفرق الابحاث المختلفة داخل الجامعة و على كل فريق بحث ان يعرض بشكل مبسط و ممتع نشاط الفريق العلمي و إن امكن بعض التجارب العلمية, و قد اتيحت لي الفرصة بشكل شخصي, كأحد اعضاء فريق "الفضاء و الصواريخ", ان اكون موجودا طوال شهر يوليو و اغسطس لمقابلة طلبة المدارس الصغار و شرح نشاط الفريق لهم و اعداد بعض التجارب العلمية المسلية لهم.
و اليوم, حيث انه أخر يوم لي في الجامعة كطالب, كنت متوجها لاحد المعامل التي اعمل بها, وجدت احد المباني ممتلئ باطفال اعمارهم بين السابعة و العاشرة, لاكتشف ان اليوم هو مسابقة "روبوت" شهيرة لطلاب المرحلة الابتدائية, ثم توقفت بعض الوقت لاشاهد جزء من فعاليات المسابقة, و الحق يقال برغم بساطة المسابقة من الناحية التنظيمية و لكن استمتعت برؤية ابتكارات و ابداع هؤلاء الصغار و كيف ان الجامعة تأخذ هذه المسابقة على محمل الجد كجزء من سياستها و مسؤليتها تجاه المجتمع.
هنا ينتهي الجزء الاول من ملاحظاتي خلال العاميين السابقين للتجربة الكندية, أرجو ان تكون مفيدة الى حد ما.