Showing posts with label AVR Tutorials. Show all posts
Showing posts with label AVR Tutorials. Show all posts

Wednesday, 21 January 2015

Arduino & Raspberry Pi Camera Interface

Yes,we learned that we can take mobile phone camera modules from almost all mobile phones to inteface them with our advanced hobby electronics projects just as with any other standard add-on modules. Since this calls for an appropriate microcontroller, it is better to use Arduino or Raspberry Pi microcontroller as a utile platform.
Raspberry Pi camera
Recently I’ve received a Raspberry Pi camera board. The camera, comes with a ribbon cable already attached to it,is a small size (25mm x 20mm x 9mm) board where a fixed focus 5MP camera module is attached. Part number of the camera module (from OmniVision) is OV5647. At the heart of the OV5647 camera module is a 1/4” color CMOS QSXGA (5 megapixel) image sensor with OmniBSI ™ technology. This Raspberry Pi camera module can be used to take high definition video, as well as stills photographs. It is easy to use for novices, but has plenty to offer advanced users looking to expand the knowledge.
Raspberry PI comes with two first-rate connectors on board. One is between Ethernet and HDMI, and the other is near GPIO. The one closer to Ethernet connector is Camera Serial Interface (CSI ). This CSI is directly connected to the Raspberry Pi GPU which can process images without ARM intervention 
While connecting the camera module to the CSI port (located behind the Ethernet port) of the Raspberry Pi board,ensure that camera cable is inserted in right way, ie the blue strip in the flexible cable is towards the Ethernet (LAN) port. Once you are connected,enable the camera software, test the camera and try using it with Bash or Python. As I am a newbie in the Raspberry Pi world, I haven’t drudged enough into all features and capabilities of my borrowed Raspberry Pi (and the camera module). If you want to leap into the future of amazing possibilities, have a look at the documentation
The Raspberry Pi camera board transfers data through an extremely fast camera serial interface (CSI-2) bus directly to the system-on-chip (SoC) processor. It does this through a 15-pin ribbon cable, also known as flexible flat cable (FFC), and connects to the surface mount ZIF 15 socket in the Raspberry Pi board. As you may noted, the camera module on this official Raspberry Pi camera board is identical to the camera modules (ccd imagers) found in many mobile phones
Luckily, most of the mobile phone cameras are not only MIPI compliant but also CSI compliant (see the first part of this article). The 15-pin Raspberry Pi CSI interface connector pinout is also included here to help you to keep proceed with your tinkering ideas. Note that, in Raspberry Pi, there are two flexible Flat Cable (FFC) connectors (S2 & S5). S2, near to the micro USB connector, is the Display Serial Interface (DSI). It allows low-level interfacing with LCDs and other displays with Raspberry Pi. It is a 15-pin surface mounted flexible flat connector, providing two data lanes, one clock lane, 3.3V and GND. S5, located between LAN and HDMI connector is the MIPI Camera Serial Interface 2 (CSI-2) connector for camera modules. It is a 15-pin surface mounted flat flexible connector, providing two data lines, one clock lane, bidirectional control interface compatible with I2C, 3.3V and GND. The data transmission interface in CSI is unidirectional differential serial interface with data and clock signals (the physical layer of this interface is the MIPI Alliance Standard for DPHY).
Arduino camera
Adding a camera to your Arduino UNO is not very difficult, because ArduCAM ™ Shield is infront of you. You can find a good tutorial on ArduCAM here
This tutorial will demonstrate how to use the ArduCAM shield on Arduino UNO board, aim the point and press a snapshot button you will get a BMP picture saved on the SD/TF card!
ArduCAM shield hardware integrates all the necessary components to interface with camera modules. User only need a extra support camera modules and a TF/SD card to start image capture. The ArduCAM shield includes a ArduChip which handle complex timing between MCU and LCD, Camera, FIFO. It exports a standard SPI serial interface and can be interfaced with wide range of microcontrollers. Further, ArduCAM shield includes two sets of pin out, identical in function. One is Arduino standard, it can be well mate with standard Arduino boards like UNO, MEGA2560, Leonardo and DUE etc. The other one is alternative port which can be connect to any platform like Raspberry Pi. After the great success of ArduCAM shield Rev.B, the ArduCAM team now released a more powerful ArduCAM shield Rev.C with amazing new features. This revision supports camera modules including OV7660, OV7670, OV7675, OV7725, OV2640, OV3640, OV5642 and MT9D111.
CMOS image sensor interface divided into two classes, one is DVP (Digital Video Port) interface, the other is MIPI Mobile Industry Processor Interface. The main difference between DVP and MIPI is that DVP is parallel interface and the MIPI interface is high speed differential serial interface. MIPI interface provide higher data band width than DVP interface and support higher resolution and frame rate
Image sensor is usually cheap and you can buy them for as little as $5.00 on eBay. However, when it turn into a “microcontroller-compatible camera module”, the finished board costs a lot more. In conclusion, I would have to say that it is worth spending time and effort to make your own camera modules, because the experience of reverse engineering and hacking is really interesting (at least for me). This is just a starting point, as promised I will come back with useful updates in near-future





 

Sunday, 28 December 2014

ATmega8 Line Follower Robot (LFR) Project

Robotics is the branch of technology that deals with the design, construction, operation, and application of robots, as well as computer systems for their control, sensory feedback, and information processing. The word robotics comes from Runaround, a short story published in 1942 by Isaac Asimov. Robot is an electro-mechanical machine that is guided by a computer program or electronic circuitry.
A robot system contains sensors, control systems, manipulators, power supplies and software all working together to perform an assigned task. One of the most basic autonomous robot you can build is a line following robot(LFR). The purpose of this AVR tutorial-part 23 is to help you build a Line Following Robot using an inexpensive AVR chip, that can follow an arbitrary path!
LFR-Overview
Our LFR is fairly a good line follower robot, consists of low-priced electro-mechanical parts, electronic components, and a microcontroller chip-based processor circuitry. Bare essentials are listed below:
  • Robot Chassis
  • Robot Motors
  • Caster Bullets
  • Robot Wheels
  • IR Sensor Cards
  • IC L293D
  • IC Atmega8
  • Motor Clamps, Switches,B attery Holders, Batteries, Small Electronic Components, Screws & Nuts, etc.
The line follower logic can be divided into two (sensing and controlling) segments. At first, LFR logic observes the track pattern ahead. In the second phase, the logic operates two drive motors (left and right) as per the informed track status. The infrared sensor card contains infrared light emitting diodes and infrared photodiodes.
The dual-channel motor controller is a simple H-Bridge driver chip L293D. Brain of the line follower robot is one Atmega8 microcontroller.
LFR-Mechanical Assembly
First of all attach motors, clamps and wheels as illustrated here. Next, attach two caster bullets (front and rear) at the bottom of the chassis. Finally, drill suitable holes in the chassis to fit all remaining parts such as finished circuit board, sensor cards, battery holder, pcb spacers, supporting clamps, etc.
The battery holder can be fitted at the rear-top of the chassis, just near the caster bullet. Best location for main circuit board is the centre-top of the chassis. The infrared sensor cards (left and right) should be fitted at the front-side of the chassis, in downward direction, so that infrared sensor components (light sender and receiver) can comfortably catch the underneath path.
Take a note, our LFR follows a path with black track on white surface. To sense the track properly, infrared sensors must be placed on the chassis in such a way that they are very close to the track level. Ensure that distance between two infrared sensor card (left and right) must be 3 to 6mm greater than the width of the marking on the track.
P23-4
LFR-System Logic
As described earlier, our LFR is a simple robot which will follow a black line on a white background. This AVR chip-based LFR has a very simple logic, discussed below using if-else in the pseudo code.
IF (Left side of the LFR is about to touch the left side of the track) Turn Right; ELSE IF (Right side of the LFR is about to touch the right side of the track) Turns Left; ELSE Move Forward;
If both infrared sensors (left and right) are on the white surface, the LFR will move forward, and if both sensors are on black surface, the LFR will stop. When the left sensor is on white and right sensor is on black, LFR will take a right-turn. Similarly, when the right sensor is on white and left sensor is on black, LFR will take a left-turn. These four cases are the only possible conditions for a basic line follower robot.
LFR-IR Sensor Card Circuit diagram
Our LFR has two infrared sensor cards (left and right) on the bottom of the chassis for detecting the black tracking indicant on the path. Each sensor card is a combination of an infrared LED, infrared photodiode, and a comparator chip works on 5V DC supply. The comparator circuit is wired using one-part (½) of the LM358 IC.
In the default jumper condition (JP:1+2), output of the infrared sensor card is at a logic-low (L) state, when it detects a black color, and vice versa. Remember, we need two identical infrared sensor cards; one for left side, and other one for right side!
→ Part 24: To be concluded in next part

Mobile Phone Camera Interface Primer – 1

Today almost every mobile phone contains a camera. In principle, mobile phone camera is a sensor/camera module designed for use across a range of mobile phone handsets and accessories. It embeds high quality still camera functions and also supports rich video. For these camera modules designed to work with any host with a standardized camera interface, separate hardware accelerator device (coprocessor) can be integrated in the mobile phone system to run the associated image processing algorithms in hardware where the baseband cannot support this processing load.
Or these camera modules can be directly connected to a baseband or multimedia processor. No dedicated coprocessor is required in the second configuration because the image processing is done in software (or hardware) within the baseband processor. Ofcourse, you can take these cameras from mobile phones and inteface them yourself with your advanced hobby electronics projects just as with any other standard add-on modules. However, good knowledge in popular camera interface techniques is a prerequisite to proceed with your succeeding dream project.
Behind The Camera Interface
Because the companies that make mobile phone cameras and the companies that make the application processors are usually different, there is a need for standardization of the camera/application processor interface. MIPI (mobile industry processor interface) Alliance has been on top of this, and the main connection is a fast serial interface known as CSI (camera serial interface).
The mobile phone handset industry had a need for a standard interface to attach camera subsystems to a host device, such as an application processor. In response, MIPI developed CSI2 several years ago. The Camera Working Group – develops and maintains camera serial interface and supporting documents – released the CSI-2 v1.0 specification in 2005. The group produced CSI-3, a next generation interface specification based on the MIPI foundation of UniPortM, in 2012.
CSI-2 consists of a DPHY and a CSI-2 transmitter at the camera and receiver on the application processor. The DPHY provides the physical interface, and the transmitter and receiver cover encoding, packing, error handling, lane distribution, assembly of image data stream, etc. However, the increasing pixel count and frame-rate is driving the need for even higher bandwidth, hence CSI-3. CSI-3 has a new MPHY, and each MPHY has a bandwidth of up to 6Gb/s per lane, with up to 4 lanes. The next level up is the Unified Protocol layer (UniPro). This defines a unified protocol for connecting devices and components designed to have high speed, low power, low pin count, small silicon area high reliability and so on.
CSI-2: The “Camera Serial Interface2 Specification” defines an interface between a peripheral device (camera) and a host processor. The host processor (baseband, application processor) here denotes the hardware and software that performs essential core functions for telecommunication or application tasks. Two high-speed serial data transmission interface options are defined. The first option – referred to in this specification as the “DPHY physical layer option” – is a unidirectional differential interface with one 2-wire clock lane and one or more 2-wire data lanes. The physical layer of this interface is defined by the MIPI Alliance Specification for DPHY. The second high-speed data transmission interface option, -referred to in this specification as the “CPHY physical layer option”- consists of one or more unidirectional 3-wire serial data lanes, each of which has its own embedded clock. The physical layer of this interface is defined by the MIPI Alliance Specification for CPHY. The Camera Control Interface (CCI) for both physical layer options is a bidirectional (SDL-SDA) control interface compatible with the I2C standard.
CSI-3: This interface technology is much easier to implement in both hardware and software than the existing technologies. CSI-3 is a new standardized data and control interface between the camera subsystem and the host device. Note that, within a camera subsystem, various components such as a RAW camera sensor, an SoC (system – on a – chip) camera, or a multi-chip camera module can be connected to each other using a proprietary interconnect, or CSI-3.
The VX6953CB Camera Module
The VX6953CB 5.1 megapixel EDOF (Extended depth of field) camera module (from ST) is designed for use across a range of mobile phone handsets and accessories. It embeds high quality still camera functions and also supports HD video. VX6953CB produces raw Bayer 5 Mpixel images at 15 fps in RAW10, and supports the CCI control as well as CCP 2.0 and CSI-2 (D-PHY v1.0 compliant) data interfaces. As stated, the VX6953CB has both CCP2.0 and MIPI CSI-2 video data interfaces selectable over the camera control interface (CCI).
The image data is digitized using an internal 10-bit column ADC. The resulting pixel data is output as 8-bit, 10-bit or 10-8 bit compressed data and includes checksums and embedded codes for synchronization. The interface conforms to both the CCP 2.0 and MIPI CSI-2 interface standards. The sensor is fully configurable through a CCI serial interface. The module is available in a SMOP (small optical package) type package measuring 6.5 x 6.5 x 4.6 mm. It is designed to be used with a board-mounted SMIA65 (standard mobile imaging architecture) socket or flex cable.
Pinout and pin description of VX6953CB camera module, as viewed from the bottom of the module, is shown below. In the pinout table, note that pads T1-T8 are ST Test Points.

Since only a minimal list of external components is required, the VS6953CB features allow straight forward integration into custom-designs. VS6590 is another near-similar camera module from ST, but with only 0.5 Megapixel resolution (800Hx600V)and CCP 1.0 serial video interface.
  • CCP → CCP stands for Compact Camera Port, the interface standard for portable cameras, developed by SMIA (standard mobile imaging architecture) -an organization promoting the standardization of mobile phone (cellphone) interfaces.
  • CCI → This is usually a two or three-wire interface used to control the sensor module. Though named differently by different vendors (e,g. Serial Camera Control Bus, SCCB by Omni Vision), it usually confirms to the I2C standards (defined by Philips).
  • SMIA → SMIA (Standard Mobile Imaging Architecture) is an imaging architecture especially suitable for mobile application use. The scope of SMIA covers a raw bayer output image sensor head: It specifies housing, mechanical interconnection, functionality, register set and electrical interface
In the next figure, you can see the camera wiring in a Nokia 2700C (Nokia 2700c2 RM-561) mobile phone circuitry. In the schematic diagram, the 12-pin camera connector is labelled as X3300. The camera module can be safely removed from this connector/socket using a special “Nokia Camera Remover Tool”, available as a service accessory. For more details, refer the official service documentation/service schematics published by NOKIA™.





Referenced Documents (including but not limited to):
  • MIPI Alliance Standard for Camera Serial Interface 2 (CSI-2) v1.0
  • MIPI Alliance D-PHY Specification (v00-90-00)
  • High-Speed interface Technology for Image Data Transmission (FIND Vol.26)
  • Camera Sensor Driver Development and Integration (PATH PARTNER)
  • SMIA 1.0 Introduction and Overview (NOKIA & ST)
  • Arasan’s White Papers & Articles
Part 2 → Mobile Phone Camera and Arduino/Raspberry Pi