Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

USB-annunciator of the time of taking medications. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Medicine

Comments on the article Comments on the article

Elderly people who are forced to take medications regularly often experience difficulty in self-compliance with their regimen. But sometimes not only health, but also life itself depends on the timely implementation of the doctor's prescriptions. In addition to the usual organizational methods of solving the problem, technical means can also be used. These include the proposed signaling device, which daily, according to the schedule entered into it, gives signals that remind you of the need to take medication.

Many older people, for obvious reasons, have difficulty working with modern software products. As for signaling devices, most of them are actually somewhat modernized alarm clocks that are unable to work according to a schedule even with two or three types of drugs and are not ergonomically adapted for use by elderly people.

The general view of the signaling device developed by the author, which has eight independent channels (according to the number of cells for drugs), each of which can be configured to give up to four reminder signals per day (32 signals in total), is shown in Fig. 1. To enter or adjust the medication schedule, this device is connected via USB to a computer on which a special program is launched. When the schedule is loaded, the alarm works autonomously.

Medication Timer USB
Rice. 1. General view of the signaling device

Both the hardware and software parts of the signaling device are designed to be used by the elderly, including those with impaired vision. The handling of the device is extremely simplified, and the program uses algorithmic and interface solutions that significantly increase the convenience of work. In addition, electrical safety measures have been taken in the design of the signaling device.

The signaling device is powered by ~230 V mains, and in the event of a power failure in it, it automatically switches to power from the built-in rechargeable battery. The power consumed from the mains does not exceed 5 W, the battery life of 800 mAh reaches three days. This ensures the safety of the schedule even during a long power outage.

The diagram of the signaling device is shown in fig. 2. The principle of its operation is simple: every second the microcontroller program compares the value of the current time with the specified signaling time. In case of a match, the device beeps, which is one of several melodies, selected at will, and turns on the indicator light of the corresponding medicine cell. At the same moment, the time of this signal is shifted one day ahead. To turn off the sound and light signals, just press the confirmation button SB1.

Medication Timer USB
Rice. 2. Signaling device circuit (click to enlarge)

The ATmega8A-PU (DD1) microcontroller used in the signaling device is capable of operating at a supply voltage reduced to 2,7 V. The microcontroller clock frequency of 12 MHz is set by the ZQ1 quartz resonator. The sound signaling unit is assembled on the UMS8-08 (DD2) musical synthesizer chip. The microcontroller turns on the sound signal by applying a high level to the input S of the synthesizer chip. The signal sounds continuously until you press the SB1 button. The sound source is a piezo emitter HA1. The volume is controlled by a variable resistor R16. Melodies are sorted by pressing the SB2 button during playback. More detailed information about microcircuits of the UMS series is given in [1].

The signaling device has a transformer source of stabilized voltage 5 V, not shown in the diagram, assembled according to the traditional scheme on an integrated stabilizer 7805. In the event of a power failure in the mains, the device switches to power from the GB1 battery. The average current consumed from it does not exceed 5 mA. In the presence of mains voltage, the battery is continuously recharged thanks to the VD5, VD6, R18 circuit. However, it is recommended to turn it off once a month and perform a full cycle of discharging to a voltage of 3 V and charging using an external charger.

The microcircuit of the musical synthesizer UMS8-08 can be replaced with another one from the UMS7 and UMS8 series. They differ only in the set of melodies. It is permissible to replace the KT3102B transistor with KT3102G, KT3102E or imported BC547, as well as with KT315B or KT315G, if the resistance of the resistor R17 is reduced to 51 kOhm. Instead of KD522B diodes, KD521A, KD521B, KD522A, 1N4148 and similar ones are suitable. All fixed resistors - S2-33N or MLT. Oxide capacitors C3 and C6 - K50-83, K50-16 or imported. The remaining capacitors are ceramic K10-73-1b, K10-17v. Any LEDs are suitable in cases with a diameter of 5 mm of the desired glow color. In the author's version, a green LED is installed as HL1 so as not to disturb the patient in vain, the rest are red. Connector XS1 - USB-BF socket.

The GB1 battery is made up of three AA size Ni-Mh batteries with a capacity of 80o mAh. You can use batteries of a different capacity, but it is desirable to select a resistor R18 of such resistance that the initial charging current of a battery discharged to a voltage of 3 V is numerically equal to 0,1 of its nominal capacity.

The signaling device is assembled on a standard perforated mounting plate measuring 70x50 mm with a perforation pitch of 2,54 mm. Mounting method - hinged with hot-melt adhesive fixation. Due to the simplicity of the circuit, printed wiring was not used. All elements of the device, except for HL2-HL9 LEDs, are placed in an IP67 plastic electrical junction box with dimensions of 80x80x40 mm.

Connector XS1 is located on a small printed circuit board, in front of it a hole of the appropriate size is cut out in the wall of the box. Elements HA1, HL1, GB1, R16, SB1 are fixed on the lid of the box with hot glue. The SB2 button, which is not related to operational controls, is located on the circuit board. On fig. 3 shows the relative position of the circuit board and remote elements inside the junction box.

Medication Timer USB
Rice. 3. Mutual arrangement of the circuit board and remote elements inside the junction box

Medicines are placed in a typical cassette for radio components of eight cells with drawers. Each of its cells has dimensions of 112x55x120 mm. The overall dimensions of the cassette holder are 224x110x120 mm. Since the cells are not airtight, but they are quite capacious, medicines should be stored in their original packaging. The cassette holder also provides protection from light, which is necessary for storing certain types of medicines. On the front panels of the cells, grooves are provided for tablets with the names of medicines.

The junction box is fixed on the left side wall of the cassette with M3 screws and nuts. LEDs HL2-HL9 are located one by one on the front panel of each cell and are connected to the device by flexible wires laid in PVC tubes inside the cells and bundled on the back side of the cassette. The length margin of each pair of wires going to the LEDs must ensure the free extension of the cell to 75 ... 80% of the fully open state.

The USB_HID_ Note.hex file attached to the article should be loaded into the program memory of the microcontroller. The configuration of the microcontroller must correspond to that shown in Table. 1. A properly assembled device does not require adjustment. The desired brightness of the LEDs can be set by changing their current within 5 ... 10 mA with a selection of resistors R7-R15.

Table 1

Ranks Condition
CKOPT 0
CKSEL[3:0] 1111
SUT[1:0] 10
GROUND 1
W.D.E. 1
RSTDISBL 1

From the point of view of the USB specification, the device belongs to the HID class [2] with a software implementation of the USB interface based on the well-known AVR V-USB driver [3]. Let me remind you that in this case it is required to switch the interface to low-speed USB 1.1 mode, which, according to the specification, is done using a resistor connected between the interface lines D- and Vbus (in this case, this is the resistor R4).

One of the typical options for connecting the microcontroller with its low voltage power supply through diodes VD1 and VD2 was used. The use of these diodes is desirable despite the presence of a battery, since it excludes the influence of its voltage on matching the logical levels of the USB bus and the microcontroller.

The microcontroller operates at a clock speed of 12 MHz, one of a number allowed for V-USB. Its program is written in C in the AVR Studio 4 development environment. The program text (file main.c) contains a detailed commentary. The vusb-20100715 driver release [4] and the WinAVR-20100110 compiler [5] were used.

The V-USB library is well-documented, so only aspects directly related to the implementation of the project or related to its features will be considered here. The step-by-step process of creating a program based on the V-USB library is described in detail in [6].

The main points to pay attention to when creating a program in AVR Studio:

- all files from the usbdrv folder of the V-USB archive should be copied to the project folder;

- files usbdrv.c, usbdrvasm.S, oddebug.c should be added to the AVR Studio project (through the context menu item "Add Existing Source File(s)..." in the project tree);

- in the project settings (Projects → Configuration Options → General → Frequency, Hz) the clock frequency of the microcontroller must be set equal to 12000000 Hz. Based on this value, AVR Studio will determine for the compiler the F_CPU constant that V-USB uses.

The required V-USB configuration is contained in the usbconfig.h file, which must also be located in the project folder. The standard configuration file should be replaced with the one attached to the article. In table. 2 lists the most important constants defined in this file. The ability to freely develop USB HID devices is related to an important point - it must use pairs of VID / PID identifiers according to the USB-IDs-for-free.txt document from the V-USB library [3].

Table 2

Constant Value Content
USB CFG IOPORTNAME D Bus connection port
USB CFG DMINUS BIT 4 The bit of the port to which the D- line is connected
USBCFGDPLUSBIT 2 The bit of the port to which the D+ line is connected (must be connected to the INTO interrupt input)
USB CFG INTERFACE CLASS 3 (HID) Device class
USB CFG MAX BUS POWER 100 Maximum current consumption from the USB bus. mA
USB CFG HID REPORT DESCRIPTOR LENGTH 22* HID report descriptor length
USB CFG VENDOR ID OxCO, 0x16 Device manufacturer ID
USB CFG DEVICE ID 0xDF, 05xXNUMX Product ID

*) This value must be equal to the size of the PROGMEM usbHidReportDescriptor character array in the program.

The program uses the UNIX time format, where the time value is the number of seconds that have passed since 00:00:00 UTC on 01.01.1970/XNUMX/XNUMX. The pdata variable is used to pass timestamps - four-byte UNIX timestamps.

The maximum number of signals given per day is specified in the program by the constant NUM_CALLS. The u_time array of size NUM_CALLS+1 is used to store time values. In this case, the element of the u_time[NUM_CALLS] array contains the current time, and the rest - the time of the signals. Each channel (cell of the drug cassette) has four array elements. For example, the first cell - elements from u_time[0] to u_time[3], the second - from u_time[4] to u_time[7], etc. If the array element value is equal to zero, the corresponding signal is considered inactive. This approach allows us to simplify the algorithm for transmitting and processing information.

The descriptor describing the package structure and the usbFunctionWrite and usbFunctionRead information transfer procedures are based on standard solutions. The basic functions are described in detail in the header file usbdrv.h from [3]. The procedures are supplemented with conditions for checking the number of processed channels. The number of array elements received by the device from the computer is one more than that sent, because the computer always transmits the current time for synchronization.

At the beginning of the main() procedure, the I/O registers are configured, the clock frequency division factor is set to 256, and the timer register TCNT1 is loaded with the number needed to form a time interval of 1 s. Timer overflow interrupts are disabled by default.

After that, the program enters the main loop. If there is no USB connection, global and timer 1 overflow interrupts will be enabled. In the for loop, each element of the u_time[i] array with a non-zero value will be checked for equality to the current time. If a match is found, the sound signal and LED of the corresponding cell will be turned on, and the response time of this channel will be increased by 86400 s (per day).

Then the level is checked at the input PB0. If it is low (button SB1 is pressed to confirm the reception of the signal), all outputs will be set to low logic levels, which will turn off the signals.

In parallel with this, every second, on overflow of timer 1, the interrupt handling procedure TIMER1_OVF_vect is launched. It restores the TCNT1 counter preset, increments the current time value in the u_time[NUM_CALLS] array element, changes the state of the PB1 output (the HL1 LED connected to it flashes with a period of 2 s).

When a device is connected to USB, the PC5 input receives a high level from the Vbus line of the USB bus. In this case, the if (PINC & (1<<5)) condition disables timer 1 overflow interrupts and activates the V-USB driver. The HL1 LED turns on and lights up continuously.

After activating the V-USB driver, it becomes possible to exchange information via USB. The usbPoll() function is called in the loop, keeping the interface active in the absence of information exchange. The information transfer process is described in more detail in the section of the article concerning the program for a computer.

Let's move on to the consideration of a computer program for entering a schedule into the USB_HID_Note signaling device. As can be seen from its main window (Fig. 4), special attention during the development process was paid to optimizing the interface to ensure ease of use for older users. The program runs under Windows XP, Windows Vista, Windows 7, Windows 8, Windows Server 2003, Windows Server 2008. It has not been tested under Windows 10 and Windows Server 2012, but there is reason to believe that it will work fine.

Medication Timer USB
Rice. 4. The main window of the computer program for entering the schedule into the signaling device

After launching the program with the annunciator connected to the computer, press the on-screen button "To plug". A message will be displayed indicating the result of the connection attempt. If it was successful, the on-screen buttons will become available. "read all" and "Save".

To enter the schedule, it is enough to select the cell number from the first drop-down list (selector), and the signal number for this cell - from the second list. Then set the desired signaling time, click on the checkbox to the left of the number to enable or disable the selected cell and signal combination (the color of the flag changes) and write the name of the drug in the only available line. The name of the drug is tied to the cell number, so the contents of the line only change when the first selector is switched. The enable flag refers to the selected combination of cell and signal numbers.

So fill in all the necessary cells. The default state of the cells is off, there is no need to activate them all. If necessary, cell settings can be changed. The entered values ​​are saved dynamically.

By pressing the on-screen button the schedule is transferred to the signaling device and written to the configuration file. A message will be displayed on the transfer result. The schedule stored in the detector can be read from it by pressing the on-screen button . After that, it can be viewed in the program window, edited, if necessary, and loaded back into the detector. Pressing the on-screen button erases the name of the drug in the corresponding window, making it possible to write another one.

An important feature of the signaling device is the stop of the timer of the current time when connected to USB. At the moment of closing the computer program, the schedule and current time are automatically written to the signaling device (synchronization). Therefore, after closing the program, you should disconnect the USB cable from the signaling device as soon as possible in order to minimize the difference between the true and "system" time.

However, even a difference of several minutes is not critical in this case, so no measures have been taken to eliminate this feature. If, after the completion of the USB_HID_Note program, the signaling device accidentally remained connected to the computer for a long time, it is enough to start this program again, press the on-screen button then on and right there on or just close the program. The correct timing will be restored by the annunciator, after which the USB cable can be disconnected.

The drug names are stored in the program configuration file and displayed on the computer screen when the signaling device is connected. Along with entering the schedule into the program, care should be taken to ensure that each cell of the cassette holder is provided with a tag with the appropriate inscription.

The USB_HID_Note program is written in C++ in the Qt 5.3.2 programming environment. The choice of this environment is due to its free, cross-platform, wide capabilities and unique built-in tools for creating and debugging applications of any level, combined with the flexibility of interface solutions. The implementation type of the application is Qt Widget. Widget source code - widget.cpp file. The entire project is compiled into the USB_HID_Note_ pro.zip archive attached to the article.

A feature of the program is a direct call to the functions of the SetupAPI and HID libraries. Therefore, the computer on which compilation takes place must have the setupapi.lib and hid.lib files corresponding to the version of its operating system. These files are usually included in the WinDDK. To avoid the need to completely install the entire WinDDK package, the files of various versions from WinDDK 7600. 16385.1 are collected by the author into one winddk_libs folder, which is available on the edition's FTP server. Compilation and debugging can be done under Windows 7, Windows Server 2008 R2, Windows Vista SP1, Windows Server 2003 SP1, Windows XP SP3 or later. The .pro file must explicitly specify the full paths to the libraries, for example, as in Table. 3.

Table 3

Medication Timer USB

The compiled executable file of the program along with the configuration files (.cfg) and styles (.qss) are located in the USB_HID_Note folder attached to the article. The necessary Qt dynamic libraries (.dll files) are also located there. As you know, this requirement is mandatory for any application developed in Qt. The list of these libraries for the case under consideration is given in Table. 4.

Table 4

Medication Timer USB

All libraries are copied from the ..ToolsQtCreator in folder, except for the last two, which are copied from ..5.3mingw482_32pluginsplatforms and placed in the appropriate subfolder of the program's working folder. You can also copy them yourself from the computer on which the program was compiled to the working or system folder of the program (archive size - 126 MB, unpacked - 400 MB).

The program algorithm is based on the standard solutions given in [7]. Implementation features are associated, first of all, with the use of different programming languages ​​(in contrast to those described in the source Delphi and C#). To use the HID API and SetupAPI functions, you need to include the hidsdi.h and setupapi.h header files, respectively.

The on-screen button click handler is the on_Connect Button_clicked() procedure. First, the driver function HidD_GetHidGuid determines the GUID associated with the HID. The SetupAPI functions are then called to create an interface enumerator and get the device's HID name. This is described in detail in [7] on p. 333. In this case, the functions of determining the name of the product or its serial number are intentionally not used. Only the VID/PID pair is checked. This is done to avoid the possibility of commercial use of the device. The VID/PID values ​​are set by the Dev_VID_PID constant in the global_vars.h file.

Once the device is discovered, control is transferred back to the HID driver. The CreateFile function requests its handle, HidD_GetPreparsedData returns a pointer to a buffer containing information about device parameters, and HidP_GetCaps returns a structure with the values ​​of these parameters.

Unlike the commonly used method with the report size assigned directly in the program, here its value is determined by the element of the Caps.FeatureReportByteLength structure, obtained from the descriptor. This allows you to create a more universal solution that does not require making changes to the program and recompiling it when the report size in the device descriptor changes.

The actual exchange of information takes place using the HidD_Get Feature (reading) and HidD_SetFeature (writing) functions, called in the corresponding data_read () and data_transfer () procedures in cycles in accordance with the number of cells. As already noted, the number of array elements received by the signaler is one more than those sent, since the computer always transmits the current time for synchronization.

A detailed commentary describing the purpose of the most important procedures is available in the text of the program. The purpose of the rest of the procedures is either standard or intuitive, for example, on_comboBox_ currentIndexChanged() - the comboBox index change event handler. The commented out qDebug lines and their companions were only for debugging the program. If you need to debug and view the progress of the exchange of information in the built-in Qt debugger window, all these instructions should be uncommented.

The program stores the general configuration in the settings.cfg file. It has a plain text format, if necessary, it can be edited manually. Its [General] section contains the number of cells NUM_BOX=8 and the number of signals per cell NUM_BOX_CALL=4, in the [view] section the position of the program window on the screen is set by integers. The [names] section contains drug names by cells, the [used] section contains cell activity flags, the [times] section contains response time values ​​in UNIX timestamp format. The latter are mainly informational in nature, since the operating values ​​are in the memory of the microcontroller of the signaling device. When editing the file manually, please note that the name parameters are in the C/C++/Java source code format (for example, u3256).

And in conclusion, a few recommendations for those who wish to independently change the number of signals given by the device. If the number of cells is fixed, the number of signals per cell is relatively easy to change. In the microcontroller program, for this it is necessary, firstly, to change the NUM_CALLS constant. Its value should be equal to the product of the number of cells and the maximum number of signals per cell. In the case considered in the article, it is equal to 8x4=32. Second, in the switch... case... procedure, the number of case statements in each line must be equal to the number of signals per cell. In this case, the arguments of the case statements must form a continuous sequence from 0 to NUM_CALLS-1. The function body and the break statement remain unchanged. The program must then be saved and recompiled.

The computer program does not require any adjustments. It is enough to change the value of the NUM_BOX_CALL constant (the number of signals per cell) in the settings.cfg file. It must strictly comply with the program of the microcontroller.

Programs for the microcontroller and computer can be downloaded from ftp://ftp.radio.ru/pub/2017/01/signal.zip.

Literature

  1. Drinevsky V., Sirotkina G. Musical synthesizers of the UMS series. - Radio, 1998, No. 10, p. 85.
  2. Universal Serial Bus. HID information. - URL: usb.org/developers/hidpage/.
  3. V USB. - URL: obdev.at/products/vusb/index.html.
  4. Driver archivevusb-20100715. - URL: obdev.at/downloads/vusb/vusb-20100715.tar.gz.
  5. Compiler WinAVR-20100110. - URL: sourceforge.net/projects/winavr/files/WinAVR/20100110/WinAVR-201 0 0110-install.exe/download.
  6. USB for AVR. Part 2. HID Class on V-USB. - URL: we.easyelectronics.ru/electro-and-pc/usb-dlyaavr-chast-2-hid-class-na-v-usb.html.
  7. Agurov P. The practice of USB programming. - S.-Pb.: "BHV-Petersburg", 2006.

Author: D. Pankratiev

See other articles Section Medicine.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Machine for thinning flowers in gardens 02.05.2024

In modern agriculture, technological progress is developing aimed at increasing the efficiency of plant care processes. The innovative Florix flower thinning machine was presented in Italy, designed to optimize the harvesting stage. This tool is equipped with mobile arms, allowing it to be easily adapted to the needs of the garden. The operator can adjust the speed of the thin wires by controlling them from the tractor cab using a joystick. This approach significantly increases the efficiency of the flower thinning process, providing the possibility of individual adjustment to the specific conditions of the garden, as well as the variety and type of fruit grown in it. After testing the Florix machine for two years on various types of fruit, the results were very encouraging. Farmers such as Filiberto Montanari, who has used a Florix machine for several years, have reported a significant reduction in the time and labor required to thin flowers. ... >>

Advanced Infrared Microscope 02.05.2024

Microscopes play an important role in scientific research, allowing scientists to delve into structures and processes invisible to the eye. However, various microscopy methods have their limitations, and among them was the limitation of resolution when using the infrared range. But the latest achievements of Japanese researchers from the University of Tokyo open up new prospects for studying the microworld. Scientists from the University of Tokyo have unveiled a new microscope that will revolutionize the capabilities of infrared microscopy. This advanced instrument allows you to see the internal structures of living bacteria with amazing clarity on the nanometer scale. Typically, mid-infrared microscopes are limited by low resolution, but the latest development from Japanese researchers overcomes these limitations. According to scientists, the developed microscope allows creating images with a resolution of up to 120 nanometers, which is 30 times higher than the resolution of traditional microscopes. ... >>

Air trap for insects 01.05.2024

Agriculture is one of the key sectors of the economy, and pest control is an integral part of this process. A team of scientists from the Indian Council of Agricultural Research-Central Potato Research Institute (ICAR-CPRI), Shimla, has come up with an innovative solution to this problem - a wind-powered insect air trap. This device addresses the shortcomings of traditional pest control methods by providing real-time insect population data. The trap is powered entirely by wind energy, making it an environmentally friendly solution that requires no power. Its unique design allows monitoring of both harmful and beneficial insects, providing a complete overview of the population in any agricultural area. “By assessing target pests at the right time, we can take necessary measures to control both pests and diseases,” says Kapil ... >>

Random news from the Archive

The battery heals itself 22.11.2013

Scientists from Stanford University have developed the first electrode that has the property of self-healing. This can significantly extend the life of lithium-ion batteries for electric vehicles, smartphones and other devices. The secret lies in the coating of the electrode with an elastic polymer, which tightens microcracks in the electrode material that occur during battery operation.

"Self-healing plays a critical role in the survival and longevity of animals and plants," commented Chao Wang, a Stanford University researcher and co-lead of the project. "So we decided to provide this property to lithium-ion batteries so they can last longer. ".

Wang came up with the idea of ​​covering the electrode with an elastic polymer after meeting a team in a lab that is developing electronic skin for robots. He took the material used for this purpose as a basis, adding graphite nanoparticles to the polymer so that the material conducts an electric current.

“We found that the lifetime of the silicon electrodes increased 10 times after we coated them with the polymer we created,” Wang said, explaining that within a few hours, the polymer completely eliminates any microcracks in the thickness of the electrode.

Under laboratory conditions, the researchers were able to perform 100 battery recharge cycles without degrading its capacity. The goal is to achieve 500 cycles for a smartphone battery and 3 cycles for an electric car battery.

As the scientists explained, they took the silicon electrode because silicon is the most promising material for the manufacture of electrodes, since it contains a huge number of ions. However, this property has a downside - with each charge, the electrode increases in size by a maximum of 3 times, again decreasing to the nominal size when the battery is discharged. This process leads to a rapid destruction of the structure of the material and a drop in the properties of the battery.

Other interesting news:

▪ Environmentally friendly cooling agent

▪ F-15 will be equipped with laser guns

▪ Navigator that understands natural speech

▪ Material that restores nervous tissue with electrical impulses

▪ Charge your phone on the street

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ site section Clocks, timers, relays, load switches. Article selection

▪ article by Lavoisier Antoine Laurent. Biography of a scientist

▪ What tree trunk is the largest in circumference? Detailed answer

▪ article Red cloudberry. Legends, cultivation, methods of application

▪ article Monoblock car amplifier based on the TDA7294 chip. Encyclopedia of radio electronics and electrical engineering

▪ article Magic x-ray machine. Focus secret

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024