This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to display a sensor reading from stellaris launchpad EK-Lm4F120XL on a Kentec EB-LM4F120-L35

Other Parts Discussed in Thread: EK-LM4F120XL

Hello all.

I am trying to display data from a sensor on to my touch screen, and I'm not sure where to place the value so it will appear on my Kentec Touchscreen. Can anyone please help? I am using root code from the push-button widget as a structure so I can figure this out.

The value I want to display is 'ulSpeedAvg', and I would like to display it where the text "ulSpeedAvg" appears in the Widget. I have read the values from ADC, and I know ulSpeedAvg is working. I would like to display the values in numerical format.

Board: Stellaris Launchpad EK-LM4F120XL

Screen:Kentec EB-LM4F120-L35

Software: Code Composer, version: 5.5.0.00077

Here is my code with notes:

/*
NORTHERN ILLINOIS UNIVERSITY:COLLEGE OF ENGINEERING AND ENGINEERING TECHNOLOGY
T - 478: SENIOR DESIGNII
SUPERMILEAGE TEAM
MATTHEW CAMPBELL AND JARED SMITH
*/

//Root code from Lab 5: Stellaris Workbook & MyWidget in grlib

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h" //This is the ADC library
#include "driverlib/fpu.h" //Floating Point
#include "driverlib/gpio.h" //For LEDs

#include "driverlib/pin_map.h"//I think for the Pin Mapping??

#include "inc/hw_ints.h" //Macros that define the interrupt assignment on Stellaris devices (NVIC)
#include "driverlib/interrupt.h"//Defines and macros for NVIC Controller (Interrupt) API of DriverLib.
//This includes API functions such as IntEnable and IntPrioritySet.
#include "driverlib/timer.h"//Defines and macros for Timer API of driverLib. This includes API functions
//such as TimerConfigure and TimerLoadSet.

#include <stdbool.h> //Not sure about these:http://forum.stellarisiti.com/topic/1840-adc-output/
#include <stdint.h>

#include "grlib/grlib.h"//Graphics Library
#include "grlib/widget.h"//Widget Library
#include "grlib/canvas.h"//Background Graphics Library
#include "grlib/pushbutton.h"//Push-button functionality
#include "drivers/Kentec320x240x16_ssd2119_8bit.h"//Display properties Library
#include "drivers/touch.h"//Touch-features Library

#include "inc/hw_ints.h" //You added this from Lab 5 pg.86
#include "driverlib/timer.h" //You added this from Lab 5 pg.86

#include "utils/ustdlib.h" //These libraries from Lab 6

#include "driverlib/hibernate.h"//Hibernate Library
#include "driverlib/systick.h"//Clock Library(??)

#include "driverlib/fpu.h" //Floating Point. LAB 5


/*END LIBRARYS AND DECLARATIONS*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

//The below line of code directly addresses any issues in debugging with regard
//to library calls.
#ifdef DEBUG //from lab 5
void__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

extern tCanvasWidget g_sBackground;
extern tPushButtonWidget g_sPushBtn;
extern tCanvasWidget g_psPanels[];


void OnButtonPress(tWidget *pWidget);
Canvas(g_sHeading, &g_sBackground, 0, &g_sPushBtn,
&g_sKentec320x240x16_SSD2119, 0, 0, 320, 23,
(CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT),
ClrBlack, ClrWhite, ClrRed, g_pFontCm20, "Last Lap Time", 0, 0);
Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sHeading,
&g_sKentec320x240x16_SSD2119, 0, 23, 320, (240 - 23),
CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn, &g_sHeading, 0, 0,
&g_sKentec320x240x16_SSD2119, 60, 60, 200, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL), ClrGray, ClrWhite, ClrRed, ClrRed,
g_pFontCmss22b," ", 0, 0, 0, 0, OnButtonPress);//Note "ulSpeedAvg" in this line; I am attempting to display this value
//g_pFontCmss22b, "ulSpeedAvg", 0, 0, 0, 0, OnButtonPress);

tBoolean g_BlueLedOn = false;


//The below code is button-pressing functionality
void OnButtonPress(tWidget *pWidget)

{
g_BlueLedOn = !g_BlueLedOn;//so far, this just turns on the red LED...
if(g_BlueLedOn)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x04);//You deleted "0x02" from the code line after GPIO_PIN_2. "0x04"is Blue LED. Green isPin_3, ox08
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x00);//you deleted "0x00" from the line after GPIO_PIN_2
}
}

//#define SERIES_LENGTH 9
//float ulSpeedAvg[]=0;//Took out [SERIES_LENGTH]

int main(void)
{

//ADC Code Below:
unsigned long ulADC0Value[4];
volatile unsigned long ulSpeedAvg=0;//Initialize this value to 0
//This variable is used to store speed data
//declared as 'volatile' so that each variable
//will not be optimized out by the compiler and
//will be available to the 'Expression' or 'Local'
//window(s) at run-time

//Clock set to run @ 40 MHz
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);//This line enables the ADC 0 module

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);//Enables LEDs

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);//**I'm pretty sure this enables PE3 section
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);//**I'm pretty sure this initializes PE3 as an ADC. This gives PE3 (ADC Input channel 0)

SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);//This samples 250k samples a second

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //Used to initialize LEDs

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00);//Turn off Red LED. Trouble shooting technique; Red LED always on...
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0x00);//Turn off Blue LED. Trouble shooting technique; Blue LED always on...

//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x04);//Turn on Blue LED (0x04) to ensure the pinwrite occured

//SysCtlDelay(10000000);//Delay for about 1 second some amount. May need to change

//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x00);//Turn off LED

ADCHardwareOversampleConfigure(ADC0_BASE, 64);//Each sample in the ADC FIFO will
//be the result of 64 measurements averaged together.

ADCSequenceDisable(ADC0_BASE, 1); //Disables ADC sequencer 1

ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
/*Above line Configures the ADC sequencer,uses ADC 0, sample sequencer 1,
processes to trigger the sequence, and uses the highest priority.*/

ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);//This may be the temperature sensor: '...TS'
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);//replaced "ADC_CTL_TS" with "ADC_CTL_CH0"p.40 on periph.driver pdf
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);
/*Configures steps 0 - 2 on sequencer 1 to sample the sensor (ADC_CTL_TS).
Code will average all four samples of temperature sensor data on sequencer 1 to calculate the
speed, so all four sequencer steps will measure the temperature sensor.*/

ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);//changed "ADC_CTL_TS"to"ADC_CTL_CH0"
/*Sample the sensor(should be ADC_CTL_CH0) and configure the interrupt flag (ADC_CTL_IE) to be set when
the sample is done. Tell the ADC logic that this is the last conversion on sequencer 1 (ADC_CTL_END).*/

ADCSequenceEnable(ADC0_BASE, 1);//enable the ADC sequencer 1

//GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);

Kentec320x240x16_SSD2119Init();// Initialize the display driver.


TouchScreenInit();
TouchScreenCallbackSet(WidgetPointerMessage);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);
WidgetPaint(WIDGET_ROOT);


//SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

//SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);//This line enables the ADC 0 module

//CanvasTextSet(&g_sTitle, g_pcPanelNames[0]);


while(1)
{

WidgetMessageQueueProcess();//took this from below

ADCIntClear(ADC0_BASE, 1);/*Indication that the ADC conversion is complete will be the ADC interrupt status flag.
Code makes sure that the flag is cleared before writing code that depends on it.
*/

ADCProcessorTrigger(ADC0_BASE, 1);//triggers the ADC conversion


while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}

ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value);

ulSpeedAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3])/4;//need to change to floating point
//This is the sensor average

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x02);//Turn on Red LED (0x02) to ensure the ulSpeedAvg triggered

SysCtlDelay(SysCtlClockGet() / 12);//Delays for some value. May need to change.

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00);//Turn off LED


//The below code is used for troubleshooting
/*if (ulSpeedAvg <= 0)
{

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x00);//Turn off Blue LED (0x04)

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0x08);//Turn on Green LED (0x08)

//SysCtlDelay(SysCtlClockGet() / 10);//Delays for some value. May need to change.

//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0x00);//Turn off Green LED (off is 0x00)
}

else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x04);//Turn on Blue LED (0x04) to ensure the ulSpeedAvg triggered
//SysCtlDelay(SysCtlClockGet() / 12);//Delays for some value. May need to change.

//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0x00);//Turn off LED
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0x00);//Turn off Green LED (0x08)
}*/
}
}