Main Site Documentation

Panda II TempSensor


#1

I tried running the TempSensor example snippet, and I am not seeing any temp readings. I think the problem is with the debug.print command, you have to be in the emulator mode? But, if I change the program property to emulator, then it does not find the Panda. I tried a Console.Writeline, but that is not a valid command. What am I missing now?

Thanks


#2

Run a simple program with Debug.Print and make sure it works first.


#3

I made a simple program with a debug.print statement, not expected results. It puts up a weird looking sample.emulator screen, but it does not display my debug.print statement.


#4

Debug.Print works on Panda II and on emulator.

The text is printed in the Output window of VS2010, not on the device…


#5

OK, this is probably a stupid question, but where is the output window? I am using VS 2010 C# express, and I am not seeing any window opening up when I ‘Start Debugging’. I have always used ‘Start Debugging’ to run a program, am I supposed to use something else?


#6

Not sure about Express,but check View->Output (Ctrl+W,O)


#7

Learn something new every day, the output window. I enabled it, and when I run the program below, it shows “Device not detected”. I have all the connections plugged in correctly, and in the right spots, but no go. So, is this a bad e_block?

[CODE]
using System;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace TempSensor
{
public class Program
{

    public static void Main()
    {
        // Change this to your correct pin!
        Cpu.Pin myPin = (Cpu.Pin)FEZ_Pin.Digital.An2;

        OneWire ow = new OneWire(myPin);
        ushort temperature;

        // read every second
        while (true)
        {
            if (ow.Reset())
            {
                ow.WriteByte(0xCC);     // Skip ROM, we only have one device
                ow.WriteByte(0x44);     // Start temperature conversion

                while (ow.ReadByte() == 0) ;   // wait while busy

                ow.Reset();
                ow.WriteByte(0xCC);     // skip ROM
                ow.WriteByte(0xBE);     // Read Scratchpad

                temperature = ow.ReadByte();                 // LSB 
                temperature |= (ushort)(ow.ReadByte() << 8); // MSB

                Debug.Print("Temperature: " + temperature / 16);
                Thread.Sleep(1000);
            }
            else
            {
                Debug.Print("Device is not detected.");
            }

            Thread.Sleep(1000);
        }
    }
}

}
[/CODE]


#8

Oh! you are not seeing them because you are even running the program I do not think. Start here and make sure you can load your applications nicely http://wiki.tinyclr.com/index.php?title=First_Project


#9

When you run are you seeing th eemulator window pop up ?

If so, please select the correct transport and device on the project properties.


#10

No, the emulator window does not pop up. I do see, at the bottom of the window where it shows that the device is rebooting, and ready. Then it starts with the “Device not detected.” Well, at this point I know I have a good button, and LEDs.


#11

This maybe related to insufficient power.

Is the board connected directly to PC or through a HUB? powered hub? Try to use power pack?


#12

It is connected to a Hub that has it own power source. I will see if I have a 6-9V power supply laying around, I know I have 9-12V supply.


#13

I just tried the board with a power source, and it still shows “Device not detected”. So, shall I call it a bad e-block?


#14

Open MFDeploy and try to ping the device.


#15

Can you move the sensor to another port (may be Di2) and modify you code and test


#16

I just did the ping thing, and it showed a “Pinging… TinyCLR”. I tried all of the sockets with no success.
Hmm, I wonder what is going on.


#17

[quote]I just did the ping thing, and it showed a “Pinging… TinyCLR”. I tried all of the sockets with no success.
Hmm, I wonder what is going on.[/quote]

That is success :slight_smile: It responded with TinyCLR :slight_smile:


#18

No Gus, he is facing a problem with the temperature e-block and no the Panda. The “device not found” is being printed from the else part of the code. He is modifying the code from the documentation.

Can some one who has the eblock, Panda II and Connect, test the code for repro ?


#19

Yes, I want to verify that I get a “Pinging… TinyCLR”, but I also get a “Device not found” when I run the program. And I did mention that I tried all of the sockets, I remembered to change the code for each socket tested.


#20

I don’t have an e-block, but i have a pair of DS18B20s on wires that i can test that code with. It seems to work fine for me, at least basically. I only get integers for temp readings (i had this issue before; its annoying and i don’t know why it was fixed really… When i didn’t get a device found it always ended up being that i had forgotten something physically, like grounding it or the power resistor was out etc…

Try this, if you finally do get the device found:

using System;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace TempSensor
{
    public class Program
    {

        public static void Main()
        {
            // Change this to your correct pin!
            Cpu.Pin myPin = (Cpu.Pin)FEZ_Pin.Digital.Di6;
            OneWire ow = new OneWire(myPin);
            ushort temp;
            double last = 0;
            double tempc = 1; // temperature in degrees Celsius
            while (true)
            {

                if (ow.Reset())
                {
                    ow.WriteByte(0xCC);
                    ow.WriteByte(0x44); // Start temperature conversion

                    while (ow.ReadByte() == 0)
                    {
                        ow.Reset();
                        ow.WriteByte(0xCC);
                        ow.WriteByte(0xBE); // Read Scratchpad

                        temp = ow.ReadByte();                   // LSB
                        temp |= (ushort)(ow.ReadByte() << 8);   // MSB

                        tempc = (temp * .0625);
                        if (tempc != last)
                        {
                            Debug.Print("Temp: " + tempc.ToString("F4") + "C");
                            last = tempc;
                        }
                    }
                }
                else
                {
                    Debug.Print("Device is not detected.");
                }

                Thread.Sleep(1000);
            }
        }
    }
}