Reputation: 3
I'm running the 16x2 LCD sample from Windows Developer Program for IoT (https://ms-iot.github.io/content/16x2LCD.htm). What's the best way do get and show the Galileo IP address on the display instead of "Hello!" message? Regards.
Code
stdafx.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include "arduino.h"
#include "LiquidCrystal.h" // we need this library for the LCD commands
Main.cpp
#include "stdafx.h"
int RS = 4;
int ENABLE = 5;
int D0 = 6;
int D1 = 7;
int D2 = 8;
int D3 = 9;
LiquidCrystal lcd = LiquidCrystal(RS, ENABLE, D0, D1, D2, D3); // define our LCD and which pins to use
int _tmain(int argc, _TCHAR* argv [])
{
return RunArduinoSketch();
}
void setup()
{
Log(L"LCD Sample\n");
lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit (it calls clear at the end of begin)
lcd.setCursor(0, 0);
lcd.print("Hello!");
lcd.setCursor(0, 1);
lcd.print(3.14159, 4); // prints a double, the 2nd number is the digits to print after the .
}
void loop()
{
}
Upvotes: 0
Views: 906
Reputation: 1
The GetAdaptersInfo page on MSDN gives example code for obtaining the IP address. I essentially added the code below to the setup function of a Galileo project and displayed the IP address on a LCD:
lcd.begin(16, 2); // columns and rows, LCD unit (it calls clear at the end of begin)
lcd.setCursor(0, 0);
lcd.print("IP Address:");
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);
}
I wrote a blog post that shows the approach I took to get it working. Hope this helps.
Upvotes: 0
Reputation: 70
I would use Windows APIs to get the IP address in string form and then use lcd.print to print the string to the LCD.
This MSDN page does a good job of explaining and showing how to use the Windows APIs to get the IP Address.
Upvotes: 1