📜 ⬆️ ⬇️

School call to .NET Micro Framework with remote control

Post reveals the implementation of the school call using the FEZ Domino debug board. The schedule is managed via a web page. FEZ Domino has ported the .NET Micro Framework . C # programming language. The prehistory of the post is ...
Habrovchan prostosergik published the post New Year's Raspberry - fasten the HD44780 screen to the Raspberry Pi . In the comments between me and prostosergik, a dispute arose about the appropriateness of using Raspberry Pi for these tasks. prostosergik in the comments reported on the already completed project of the school bell on the Raspberry Pi.
Later the post School call on the Raspberry Pi with remote control was published. Now it is my turn to implement this task.

According to the results of the correspondence formed the following TK:
Purpose: to include a call in accordance with the schedule of school calls in the school
Mechanism of work: the call is made in accordance with the filed signal "1" on the contact relay. When the relay closes, the bell rings.
Requirements

Implementation
I must say, due to technical limitations on the Arduino UNO R3, it was not possible to fully implement this project.
When choosing a controller was guided by the following rules

FEZ Domino is not mentioned in the title, not by chance. The program code between microcontrollers running on the .NET Micro Framework is always portable without changes, subject to the version. In this case, FEZ Domino is easily replaced with the NET Duino Plus 2 card, without sacrificing functionality.

List of components used:

All components can be bought in bulk on Aliexpress.com , it will be significantly cheaper.
FEZ Domino specification:
image

Unfortunately, FEZ Domino has long been discontinued, so the nearest analogues are lower

Wiring diagram
image
Device Photos:
View from above
image
A bunch of Fez Domino, Ethernet Shield, I / O Expansion Shield, in stack mode
image
image

Device launch
When launched, WatchDog is set to 20 seconds, in case the device hangs.
//Enable Watchdog GHI_LowLevel.Watchdog.Enable(1000 * 20); 

The counter is reset
 GHI_LowLevel.Watchdog.ResetCounter(); 

Initialization of interrupts on buttons
 //      FEZ_Components.Button Button_ManualCall = new FEZ_Components.Button(FEZ_Pin.Interrupt.Di5); //     FEZ_Components.Button Button_HardReset = new FEZ_Components.Button(FEZ_Pin.Interrupt.Di6); //     Button_ManualCall.ButtonPressEvent += new FEZ_Components.Button.ButtonPressEventHandler(Button_ManualCall_ButtonPressEvent); //     Button_HardReset.ButtonPressEvent += new FEZ_Components.Button.ButtonPressEventHandler(Button_HardReset_ButtonPressEvent); 

Then set the sleep mode to 5 seconds to reset the default settings. The LED is lit and the inscription on the “Starting ...” screen is displayed.
Reading settings from an SD memory card
 //  appset = new AppSettings(); appset.ReadSettings(); 

Network initialization
 netinter = new netinteface(); 

Reading time from RTC. RTC is integrated into the chip. To ensure the progress of the clock, it is necessary to connect the battery v3.3 to the contacts
 Utility.SetLocalTime(RealTimeClock.GetTime()); 

Run time synchronization stream with NTP server. The synchronization interval is set in the settings.
 Thread ThreadUpdateTimeNTP = new Thread(UpdateTimeNTPThread); ThreadUpdateTimeNTP.Start(); 

Starting the call flow. Matches current time and time of calls. In case of coincidence, gives a call.
 Thread ThreadTimeBells = new Thread(TimeBells); ThreadTimeBells.Start(); 

Launch Web Server
 Webserver server = new Webserver(); 

    .      string[] confstr = {appset.SyncTimeDelayMin.ToString(), appset.CurTimeBell[0].ToString("HH:mm"), … appset.CurTimeBell[7].ToString("HH:mm")}; server.StartServer(confstr); 

Features of the implementation
From Arduino UNO had to be almost immediately abandoned for the following reasons:
At the same time, network and SD card operation is not supported. There is an implementation of ladyada Arduino Ethernet + SD , but I didn’t manage to launch it.
Arduino supports two parallel threads or two interrupts.
In my implementation, I got 4 threads: interruption to the button for manual call serving, synchronization with the NTP server, call tracking time flow, server maintenance flow http. For Arduino, UNO is too much.
Compared with the project on the Raspberry pi, the ease of implementation of support for Watchdog.
Unfortunately, tracking the presence of a physical Ethernet data medium does not work (it is impossible to determine whether the device is connected to the switch). In the event of a physical break, the network must be initialized. As a solution to this problem, periodically poll (ping) some node (by IP address) on the network. In the absence of a response, re-initialize the network. But this is a CLR flaw for the FEZ Domino microcontroller.
Call time tracking is done with second accuracy. To exclude the “call skip” situation, the previous time and the new one are saved. The “call skip” situation arises due to the time spent on executing the program code and the pause in the stream - 1 second.
 public static void TimeBells() { string NowLocalTime = ""; DateTime NewTime; DateTime OldTime = DateTime.Now.ToLocalTime(); OpredCallZvon ocz; while (true) { //  NewTime = DateTime.Now.ToLocalTime(); //   NowLocalTime = NewTime.ToString("HH:mm:ss"); //   foreach (DateTime dt in appset.CurTimeBell) { ocz=new OpredCallZvon(NewTime,OldTime,dt); if (ocz.isCall) { LCD.setCursor(0, 1); LCD.print("NOW ZVONOK "); RunBell(); } } OldTime = NewTime; Thread.Sleep(1000); } } 

At the time of the call, the LED is on.
RTC is embedded. Enough to power up the pins VBAT IN and Ground.
To simplify the templates, html pages were placed in the resources to the project.
Used libraries:

The implementation took 3 days x 4 hours = 12 man-hours.
Sometimes, with http requests, an exception was detected about the excess of RAM (~ 62KB). Because of this, it was necessary to apply the new settings only when rebooting, not on-line.
Costings
NoTitleqtypriceAmount, $
oneNetduino Plus 2one59.9559.95
2Relay Moduleone1.741.74
3RGB 3 Color Full Color LED any colorone1.991.99
fourStandard Button Switch Sensor Module21.292.58
fiveLCD module Blue screen IIC / I2C 2004 5Vone7,67,6
6MicroSD memory cardone3.143.14
7Mounting base, wiresonetenten
TOTAL87

Video:

Screenshots:
image
image
image

Code:
FEZ_Domino_Zvonok.zip

')

Source: https://habr.com/ru/post/246853/


All Articles