Main Site Documentation

Temperature Humidity Unable to Update T35 Display?


#1

I’m getting started with my first projects here with the .NET MF and I have a FEZ Spider with a Temperature Humidity module from Seeed that I’m trying to use.

My code is really simple, below is my Program.cs for some clarity. I have a very simple setup, a single “image” that is being displayed to a WPF window. Once clicked I call “RequestMeasurement” on the TemperatureHumidity Module. I have a handler added to then update the UI. Debugging I can see that it does actually get called but the line to update the text content isn’t being fired off.

With WinForms I’d think of this as a threading issue, but I don’t see any way to actually see/fix it.


private Image imgButton1;
        private Image imbButton2;
        private Text txtFeedback;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {

            temperatureHumidity.MeasurementComplete += new TemperatureHumidity.MeasurementCompleteEventHandler(tempUpdated);

            SetupUI();

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
        }

        void tempUpdated(TemperatureHumidity sender, double temperature, double relativeHumidity)
        {
         //Update label   
            txtFeedback.TextContent = string.Concat("Temp: ", temperature.ToString("0.0"), " Humidity: ", relativeHumidity.ToString("0.0"));
        }

        public void SetupUI()
        {
            var window = display.WPFWindow;
            var canvas = new Canvas();
            window.Child = canvas;

            //Add the first button
            var imgButton1 = new Image(Resources.GetBitmap(Resources.BitmapResources.Button1));
            imgButton1.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(Button1_Pressed);
            canvas.Children.Add(imgButton1);
            PositionElemen(imgButton1, 10, 5);

            //Add the textbox
            txtFeedback = new Text(Resources.GetFont(Resources.FontResources.NinaB), string.Empty);
            canvas.Children.Add(txtFeedback);
            PositionElemen(txtFeedback, 20, 200);
        }

        private void PositionElemen(UIElement element, int x, int y)
        {
            Canvas.SetTop(element, y);
            Canvas.SetLeft(element, x);
        }
        void Button1_Pressed(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            temperatureHumidity.RequestMeasurement();
        }

#2

To add a bit more to this. I added some basic structure to the code to help debug, I added a LED and in my update method, I change the color based on difference in temp from previous readings. This appears to be working as one would expect. But my debug message isn’t displayed either

void tempUpdated(TemperatureHumidity sender, double temperature, double relativeHumidity)
        {
            if (previousTemp <= temperature)
                led.TurnColor(GT.Color.Red);
            else
                led.TurnBlue();

            previousTemp = temperature;

            var message = string.Concat("Temp: ", temperature.ToString("0.0"), " Humidity: ", relativeHumidity.ToString("0.0"));
            Debug.Print(message);
            txtFeedback.TextContent = message;
        }

Looking at the debug window I get

#### Exception System.ArgumentException - 0x00000000 (1) ####
#### Message: 
#### System.Number::ValidateFormat [IP: 0056] ####
#### System.Number::Format [IP: 0008] ####
#### System.Double::ToString [IP: 000d] ####
#### Sample_UI_Interface_Module.Program::tempUpdated [IP: 0031] ####
#### Gadgeteer.Modules.Seeed.TemperatureHumidity::OnMeasurementCompleteEvent [IP: 0042] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 004a] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001d] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 001c] ####
#### Sample_UI_Interface_Module.Program::Main [IP: 001a] ####

A first chance exception of type ‘System.ArgumentException’ occurred in mscorlib.dll
Error invoking method “Gadgeteer.Modules.Seeed.TemperatureHumidity” (check arguments to Program.BeginInvoke are correct)

Thoughts?


#3

remove your “0.0” formats in ToString and see if that changes it; possibly just the netmf tostring’s don’t have that format capability.


#4

Ok, now I feel a bit dumb…

Hm…how to round…


#5

http://msdn.microsoft.com/en-us/library/cc506840.aspx is the string format reference for int32, and can give you the insight you want.


#6

temperature.ToString("F1")

is what you want.

#################################################

Pop in the TinyCLR community IRC channel and ask/chat

about whatever you want.

Details here: http://www.tinyclr.com/forum/topic?id=7210

#################################################


#7

Hi,

I find your example very useful and tried to copy it but I cant find getBitmap and BitmapResources.Button1.
I think they must be defined before. How can I do it?? Have I to import the available buttons (I suggest that there are predefined standard buttons which can be used).
I see only Font Resources in Project Explorer.


#8

SB - best to post a new thread with your question.