Skip to content

Displaying Intel Galileo IP address on a 16×2 LCD

September 26, 2014

I’ve had problems with Galileo Watcher showing Galileo boards on Windows 8.1. It works fine on Windows 7 and as far as I am aware Windows Firewall is configured correctly. I was also a little inspired by this question on stackoverflow, I’ve copied the title of the question for this blog post. The nub of the question is this…

“What’s the best way do get and show the Galileo IP address on the display instead of “Hello!” message?”

I’ve used the 16×2 LCD with netduino projects and decided to have a go. The only answer to the  question suggested using the Windows APIs to get the IP address in string form and then use lcd.print to print the string to the LCD. I thought I would add a bit more value and also print the computer name to the LCD.

I decided to split the problem into three steps:

  • Write a C++ console app to get the IP address (and other network adapter properties)
  • Get the LCD sample app (http://ms-iot.github.io/content/16x2LCD.htm) working
  • Merge the two projects and display the Galileo IP address on a 16×2 LCD

Step 1 – Writing a console app to get the IP address:
The GetAdaptersInfo page on MSDN gives a good example of a suitable console application. The application worked fine on my laptop. The Galileo runs a modified version of Windows with a subset of Win32 so I copied the console application to the Galileo and ran it successfully:

GetIPAddress

I now had code capable of retrieving the IP address and Computer Name.

Step 2 – Get the LCD sample app working:
I followed the instructions on setting up the 16 x 2 LCD from the sample applications on github. Unfortunately the project would not build. As a quick fix I modified the include files in the local package:

      • Add #ifndef directive to Print.h:
      • Remove the inheritance from the Print class in Stream.h

Step 3 – Merge the two projects
This was pretty straightforward, the only change I made between the console app and the Galileo project was changing from GetComputerName to GetComputerNameA to print the computer name to the LCD. The code snippet below runs in setup:

	lcd.begin(16, 2); // columns and rows, LCD unit (it calls clear at the end of begin)
	lcd.setCursor(0, 0);

	DWORD len = 16;
	char cName[16];

	GetComputerNameA(cName, &len);

	lcd.print(cName);
	
	PIP_ADAPTER_INFO	pAdapterInfo = NULL;
	PIP_ADAPTER_INFO	pAdapter = NULL;
	ULONG				ulOutBufLen = sizeof(IP_ADAPTER_INFO);
	DWORD				dwRetVal = 0;

	pAdapterInfo = (IP_ADAPTER_INFO *)MALLOC(sizeof(IP_ADAPTER_INFO));
	if (pAdapterInfo == NULL) {
		printf("Error allocating memory needed to call GetAdaptersinfo\n");
	}

	if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
		FREE(pAdapterInfo);
		pAdapterInfo = (IP_ADAPTER_INFO *)MALLOC(ulOutBufLen);
		if (pAdapterInfo == NULL) {
			printf("Error allocating memory needed to call GetAdaptersinfo\n");
		}
	}

	if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
		pAdapter = pAdapterInfo;
		lcd.setCursor(0, 1);
		lcd.print(pAdapter->IpAddressList.IpAddress.String);
	}

	if (pAdapterInfo)
		FREE(pAdapterInfo);

Computer name and IP address on a 16×2 LCD display…
16x2lcd

I’ll tidy up the source code and update the blog post shortly…

15 Comments leave one →
  1. Rick permalink
    September 27, 2014 5:12 pm

    Please Include in detail what you did for step 2, as I can’t get the example progam to work
    thanks
    rgb

  2. September 27, 2014 9:22 pm

    As a quick fix I modified Print.h and Stream.h, the files are located in {Galileo Project Folder}\packages\Microsoft.IoT.Galileo.Arduino.1.0.5\build\native\include. For Print.h I added:

    #ifndef _PRINT_H
    #define _PRINT_H

    class Print
    {
    // Rest of print class
    }

    #endif

    For Stream.h I changed:

    class Stream : public Print -> class Stream

    I checked the github repository and Print.h includes the changes, Stream.h still inherits from Print (https://github.com/ms-iot/galileo-sdk/tree/develop/source).

    I also modified RS, ENABLE, D0, D1, D2, D3 to match the LCD configuration I used for a netduino project.

  3. Rick permalink
    September 28, 2014 2:03 am

    Thanks for the instruction. I have now moved on to other errors, but should be able to fix them.
    It is strange that I didn’t get the updated print.h as just installed a week a go. I will install from the GitHub.
    In any case, it is really annoying when the examples don’t work. One would think someone at Microsoft would have checked them prior to putting them on their site.
    thanks again for your help
    rgb

  4. rick permalink
    September 28, 2014 10:47 am

    Hi
    Sorry to bother you again, but which liquid crystal library did you use?
    I keep getting the following errors which I assume are related to the liquid crystal library
    Error 4 error LNK1120: 3 unresolved externals C:\Users\com03\Documents\Visual Studio 2013\Projects\DFRLCD\Debug\DFRLCD.exe DFRLCD

    Error 1 error LNK2019: unresolved external symbol “public: __thiscall LiquidCrystal::LiquidCrystal(unsigned char,unsigned char,unsigned char,unsigned char,unsigned char,unsigned char)” (??0LiquidCrystal@@QAE@EEEEEE@Z) referenced in function “void __cdecl `dynamic initializer for ‘lcd”(void)” (??__Elcd@@YAXXZ) C:\Users\com03\Documents\Visual Studio 2013\Projects\DFRLCD\DFRLCD\Main.obj DFRLCD
    Error 2 error LNK2019: unresolved external symbol “public: void __thiscall LiquidCrystal::begin(unsigned char,unsigned char,unsigned char)” (?begin@LiquidCrystal@@QAEXEEE@Z) referenced in function “void __cdecl setup(void)” (?setup@@YAXXZ) C:\Users\com03\Documents\Visual Studio 2013\Projects\DFRLCD\DFRLCD\Main.obj DFRLCD
    Error 3 error LNK2019: unresolved external symbol “public: void __thiscall LiquidCrystal::setCursor(unsigned char,unsigned char)” (?setCursor@LiquidCrystal@@QAEXEE@Z) referenced in function “void __cdecl setup(void)” (?setup@@YAXXZ) C:\Users\com03\Documents\Visual Studio 2013\Projects\DFRLCD\DFRLCD\Main.obj DFRLCD

    thanks and sorry to bother you again

  5. September 28, 2014 6:00 pm

    No worries Rick. I used LiquidCrystal.cpp and LiquidCrystal.h from github (https://github.com/arduino/Arduino/tree/master/libraries/LiquidCrystal). I downloaded the two files to the Galileo project folder and added them to the Galileo project. Hope this helps.

    • Rick permalink
      September 30, 2014 11:50 am

      I have been using the same arduino files, so strange getting an error. I left a message on the windows community board, hopefully someone will come up with an answer. I tried removing and reinstalling everything and still ge the same error. Visual Studio did an update and now when I create a new project it has the new print.h. In addition, it doesn’t matter if I make the change to stream.h or not, I get the same error.
      All I can guess is it has something to do with 64bit version of windows 7.
      thanks
      rgb

      • September 30, 2014 2:13 pm

        I’ve used the Galileo SDK with VS2013 on both Windows 8.1 and Windows 7 x64 without any problems. The only VS updates I’ve got pending at the moment are SQL Server, Azure and the Windows Phone 8.1 emulators. Have you got nuget package restore enabled on the solution?

      • Rick permalink
        October 1, 2014 12:34 am

        Hi er
        I have nuget package restore enabled and made the change to print.h (commented out Aruduino.h), but still same error. I don’t understand why it s complaining about passing an unsigned char, when it is being passed integers,but could be I don’t really know much about win32 environment. Also, do you know of a good reference to the commands being used? For example, where did the Log command come from? Isn’t Arduino, Isn’t Win32, Isn’t wiring. at least as far as I can tell.
        thanks

      • October 1, 2014 11:33 am

        If you have nuget restore enabled then Print.h / Stream.h will be overwritten each time you build the project, undoing changes you have made locally to any package file. I’m finding it easier at the moment to have a local nuget package for the Galileo SDK, instructions on setting one up can be found here https://github.com/ms-iot/galileo-sdk. Unfortunately I don’t know of a reference to available commands apart from looking through the files, e.g. Log is defined in Arduino.h. Hope this helps.

      • Rick permalink
        October 1, 2014 11:59 am

        Hi
        Well the new Print.h has the changes needed to prevent the initial error and I get the same errors mentioned earlier no matter if I use the original or modified version of Streams.h. All I can guess is that there is a bug in Visual Studio Express. I was really interested in Windows on the Galileo as thought I would have access to devices and tools not available with the standard Linux version, but now see this is not the case, so probably not worth the effort. I think I will put it away for a while and maybe check back in the future to see if anything has improved. Thanks for you help
        regards
        rgb

      • Richard Bradley permalink
        October 3, 2014 5:37 am

        Hi Microsoft came up with the answer see

        http://connect.microsoft.com/windowsembeddedIoT/feedback/details/985115/problems-with-lcd-example

        Thanks for you help rick

      • October 3, 2014 3:39 pm

        No worries Rick, do you have a working LCD now?

      • Richard Bradley permalink
        October 3, 2014 3:42 pm

        Hi Yes it works, and am now trying to figure out how you were able to display the IP address. This is really a lot harder than Linux There is also a message on the board under advanced topics about adding drivers. Doesn’t look easy regards rgb

  6. September 30, 2014 7:07 am

    I was also having trouble with the LCD example code. Particularly with intellisense and something to do with Inheritance as well and the Print function being redefined in the process.
    Just wondering the process to remove inheritance from the stream class? It seems that duplicate objects were created with Print.

  7. September 30, 2014 2:09 pm

    I think I’ve managed to track down the cause of the compilation errors, here goes…

    Print.h has an include directive to Arduino.h, Arduino.h has an include directive to Stream.h and Stream.h had an include directive to Print.h causing a circular dependency. The Arduino,h include directive needs to be deleted from Arduino.h to removed the circular dependency. Microsoft released version Galileo SDK version 1.0.6-alpha (Prerelease) yesterday which includes the #ifndef _PRINT_H fix but doesn’t address the circular dependency. Galileo SDK version 1.0.5 requires both the #ifndef _PRINT_H fix and removing the “Arduino.h” include directive from Print.h to fix the circular dependency. Hope this helps.

Leave a comment