# Data Matrix Based Low Cost Autonomous Detection of Medicine Packages
## 2 Proposed Methodology
### System Architecture  
The structure of the developed system is presented in Figure 2(a),b (frontal and bottom-up views, respectively), comprising a camera to acquire the images as well as a lighting system, in order to avoid being constrained by shadows or lack of brightness.  
The acquired image can contain several Data matrix codes restricted by the size of the work area, which is 200 mm \(\times\) 200 mm. The structure was assembled using MakerBeam small aluminum profiles and additive manufacturing (3D printing) parts. The prototype is a ready-to-go system since it has all the components installed and is also equipped with a power supply. It only requires to be connected by USB (Universal Serial Bus) to the computer (in this case study, from the hospital pharmacy) and the electrical grid. An illustrative image acquired by the camera is presented in Figure 4.  
Figure 3: Developed system structure: (**a**) Frontal view; (**b**) Bottom-up view.  
The system architecture schematic is presented in Figure 5. The proposed system is connected to the computer and it will be identified as a keyboard, the same process as the Data Matrix reader used in the current implementation of the presented case study. The Pro Micro Arduino board, composed of an ATmega3U4, is configured to be recognized as a keyboard by the MVO (Medicines Verification System) verification computer. The identified Data Matrix codes are processed by the Raspberry Pi library \(libdmtx\) ([[https://github.com/dmtx/libdmtx](https://github.com/dmtx/libdmtx)]([https://github.com/dmtx/libdmtx](https://github.com/dmtx/libdmtx)), accessed on 25 September 2022) and transferred one by one through a serial port to the Arduino that further sends it to the computer (using the defined protocol). The used integrated development environment was Lazarus, into the raspbian operating system. Moreover, the Arduino board is also used to perform an Human-Machine Interface (HMI) to the user, by one RGB led, one push-button, and also to control the lighting system (with 8+8 Watt LED panels). The RGB led allows the user to infer the state of the system from the LED color, while the push-button is used to start the acquisition process of a new image containing a Data Matrix, both presented in Figure 6. Regarding the feedback from the MVO to the computer, the connection has not been implemented yet.  
Figure 4: Acquired image from the camera according to a top-bottom perspective.  
Figure 5: System architecture schematic. The current process is illustrated by the blue arrows while the proposed methodology is represented by the black ones. The connection from the MVO to the computer, in order to give visual feedback on the medicine packages, has not been implemented yet.  
The serial port communication between Arduino and Raspberry uses the channel library developed by the authors that encapsulate several data that will be decoded at the target. The image is captured with a 12 Megapixels camera connected to the Raspberry pi camera BUS attached with an 8-50 mm C-Mount Zoom Lens. The illumination system allows having a lens aperture that enables a depth of field capable of detecting Data Matrix codes in boxes at a distance of 15-25 cm. The HMI is also composed of a monitor that gives information to the user about the Data Matrix detection (Data Matrix codes are bordered by green squares) and also the total number of decoded codes, as illustrated in Figure 7.