Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

i2C netduino won't work!


  • Please log in to reply
27 replies to this topic

#1 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 17 February 2011 - 08:31 PM

Hi all. i2c lcd is driving me crazy and I would really appreciate a bit of help.

I have the lcd of the attached pdf file.

As explained in the manual, I soldered a jumper on R1. I put 4 connectors, one for each pin ( VDD, VSS, SCL,SDA).

I connected netduino to the LCD this way:

PINS NETDUINO PINS LCD
------------- --------
4 8(SDA)
5 7(SCL)
5V
GND

If I am not wrong, I don't need any more on the hardware side. Once I plugged it, I get the lcd on. The easiest test I want to try first is to turn on/off the lcd. According to the manual, to turn off the lcd I need to do an i2c.write(0xFE42) without parameters.

As far as I know there are two posssibilities to write into specific address:

Note : this is just a small sanpshot of the whole class:

        public void Write(I2CDevice.Configuration config, byte[] writeBuffer, int transactionTimeout)
        {
            
// Set i2c device configuration.
I2CDevice.Configuration _slaveConfig = new I2CDevice.Configuration(0x50, 100);
            

            // create an i2c write transaction to be sent to the device.
            I2CDevice.I2CTransaction[] writeXAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer) };

            lock(_slaveDevice)
            {
                // the i2c data is sent here to the device.
                int transferred = _slaveDevice.Execute(writeXAction, transactionTimeout);

                // make sure the data was sent.
                if (transferred != writeBuffer.Length)
                    throw new Exception("Could not write to device.");
            }
        }

  public void WriteSomethingToSpecificRegister()
        {
            I2CBus.GetInstance().WriteRegister(_slaveConfig, 0x3C, new byte[2] { 0xF4, 0x2E }, TransactionTimeout);
        }

I think I have to use the method WriteSomethingToSpecificRegister() but I can't address a 2byte address like OxFE41, Just a 1 byte address.

By using both methods I get nothing. The lcd does not turn off...what am I doing wrong?

Thank you!

thanks a lot!

Attached Files

  • Attached File  LCD.pdf   573.14KB   45 downloads


#2 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 17 February 2011 - 08:38 PM

this gets me an error : " program.exe could not write to device

I2CBus.GetInstance().Write(_slaveConfig, new byte[2] { 0xFE, 0x42 }, TransactionTimeout);

where _slaveConfig has address 0x50 and Time = 100Khz and TransactionTime is 1000

#3 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 18 February 2011 - 12:56 PM

any ideas? please, I don't really know what is going on because apparently is kind of easy to do what I want to do. thank you!

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 February 2011 - 01:08 PM

Asaak, If you can please post a small project which shows the issue you're having, we can help a bit more. Right now, I'm not totally clear on the error you're getting. Chris

#5 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 18 February 2011 - 01:54 PM

Have you tried using the Write method to send your 2 bytes as a byte array? I'm fiddling with 12c (for a HMC6352 compass module) and finding it awkward to work with compared to serial or SPI. I notice the display you have can be used with both of these protocols - I might be less frustrating to try with one of those if your project allows for it.

#6 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 18 February 2011 - 06:54 PM

I would attach a project example but I wasn't allowed to by the webform.Instead, I have put all the classes I use.
According to the pdf, to turn off the lcd I need to send a 0xFE 0x62 without parameters. In the example, I show a method to do so but the problem is that "address" is a byte, not a double byte like 0xFE 0x62 so I can not use that...and if I use the write method nothing happens as well...I must be doing something wrong but I can't figure out what...

Thanks for the help!

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace example
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            LCD lcd = new LCD(0x50);

            byte[] address = { 0xFE, 0x42};
            byte data = null;

            lcd.WriteSomethingToSpecificRegister(address, data); // here is the problem


        }

    }
}

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace example
{
    class LCD
    {
        private I2CDevice.Configuration _slaveConfig;
        private const int TransactionTimeout = 1000; // ms
        private const byte ClockRateKHz = 100;
        public byte Address { get; private set; }

        /// <summary>
        /// Example sensor constructor
        /// </summary>
        /// <param name="address">I2C device address of the example sensor</param>
        public LCD(byte address)
        {
            Address = address;
            _slaveConfig = new Microsoft.SPOT.Hardware.I2CDevice.Configuration(address, ClockRateKHz);
        }

        public byte[] ReadSomething()
        {
            // write register address
            I2CBus.GetInstance().Write(_slaveConfig, new byte[] { 0xF2 }, TransactionTimeout);

            // get MSB and LSB result
            byte[] data = new byte[2];
            I2CBus.GetInstance().Read(_slaveConfig, data, TransactionTimeout);

            return data;
        }

        public void  WriteSomething(byte[] data)
        {
            // write register address
            I2CBus.GetInstance().Write(_slaveConfig, data, TransactionTimeout);
        }

        public byte[] ReadSomethingFromSpecificRegister()
        {
            // get MSB and LSB result
            byte[] data = new byte[2];
            I2CBus.GetInstance().ReadRegister(_slaveConfig, 0xF1, data, TransactionTimeout);

            return data;
        }

        public void WriteSomethingToSpecificRegister(byte register, byte[] data)
        {
            I2CBus.GetInstance().WriteRegister(_slaveConfig, register, data, TransactionTimeout);
        }
    }
}


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace example
{
    public class I2CBus : IDisposable
    {
        private static I2CBus _instance = null;
        private static readonly object LockObject = new object();

        public static I2CBus GetInstance()
        {
            lock (LockObject)
            {
                if (_instance == null)
                {
                    _instance = new I2CBus();
                }
                return _instance;
            }
        }

        private I2CDevice _slaveDevice;

        private I2CBus()
        {
            //this._slaveDevice = new I2CDevice(new I2CDevice.Configuration(0x50, 100));
            this._slaveDevice = new I2CDevice(new I2CDevice.Configuration(0, 0));
        }

        public void Dispose()
        {
            this._slaveDevice.Dispose();
        }

        /// <summary>
        /// Generic write operation to I2C slave device.
        /// </summary>
        /// <param name="config">I2C slave device configuration.</param>
        /// <param name="writeBuffer">The array of bytes that will be sent to the device.</param>
        /// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param>
        public void Write(I2CDevice.Configuration config, byte[] writeBuffer, int transactionTimeout)
        {
            // Set i2c device configuration.
            _slaveDevice.Config = config;

            // create an i2c write transaction to be sent to the device.
            I2CDevice.I2CTransaction[] writeXAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer) };

            lock (_slaveDevice)
            {
                // the i2c data is sent here to the device.
                int transferred = _slaveDevice.Execute(writeXAction, transactionTimeout);

                // make sure the data was sent.
                if (transferred != writeBuffer.Length)
                    throw new Exception("Could not write to device.");
            }
        }

        /// <summary>
        /// Generic read operation from I2C slave device.
        /// </summary>
        /// <param name="config">I2C slave device configuration.</param>
        /// <param name="readBuffer">The array of bytes that will contain the data read from the device.</param>
        /// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param>
        public void Read(I2CDevice.Configuration config, byte[] readBuffer, int transactionTimeout)
        {
            // Set i2c device configuration.
            _slaveDevice.Config = config;

            // create an i2c read transaction to be sent to the device.
            I2CDevice.I2CTransaction[] readXAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(readBuffer) };

            lock (_slaveDevice)
            {
                // the i2c data is received here from the device.
                int transferred = _slaveDevice.Execute(readXAction, transactionTimeout);

                // make sure the data was received.
                if (transferred != readBuffer.Length)
                    throw new Exception("Could not read from device.");
            }
        }

        /// <summary>
        /// Read array of bytes at specific register from the I2C slave device.
        /// </summary>
        /// <param name="config">I2C slave device configuration.</param>
        /// <param name="register">The register to read bytes from.</param>
        /// <param name="readBuffer">The array of bytes that will contain the data read from the device.</param>
        /// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param>
        public void ReadRegister(I2CDevice.Configuration config, byte register, byte[] readBuffer, int transactionTimeout)
        {
            byte[] registerBuffer = { register };
            Write(config, registerBuffer, transactionTimeout);
            Read(config, readBuffer, transactionTimeout);
        }

        /// <summary>
        /// Write array of bytes value to a specific register on the I2C slave device.
        /// </summary>
        /// <param name="config">I2C slave device configuration.</param>
        /// <param name="register">The register to send bytes to.</param>
        /// <param name="writeBuffer">The array of bytes that will be sent to the device.</param>
        /// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param>
        public void WriteRegister(I2CDevice.Configuration config, byte register, byte[] writeBuffer, int transactionTimeout)
        {
            byte[] registerBuffer = { register };
            Write(config, registerBuffer, transactionTimeout);
            Write(config, writeBuffer, transactionTimeout);
        }

        /// <summary>
        /// Write a byte value to a specific register on the I2C slave device.
        /// </summary>
        /// <param name="config">I2C slave device configuration.</param>
        /// <param name="register">The register to send bytes to.</param>
        /// <param name="value">The byte that will be sent to the device.</param>
        /// <param name="transactionTimeout">The amount of time the system will wait before resuming execution of the transaction.</param>
        public void WriteRegister(I2CDevice.Configuration config, byte register, byte value, int transactionTimeout)
        {
            byte[] writeBuffer = { register, value };
            Write(config, writeBuffer, transactionTimeout);
        }
        public void provaMeva(I2CDevice.Configuration config, int transactionTimeout)
        {
            byte[] writeBuffer = { 0xFE, 0x72 };

            Write(config, writeBuffer, transactionTimeout);
        }
    }
}



#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 February 2011 - 12:12 AM

Asaak, Does the I2C device require a "repeated start bit" between the address and the request for data? If so, you'll want to update to the latest v4.1.1 alpha/beta firmware and use its "internaladdress" feature. If all else fails, maybe we can get one of the devices here and play... Chris

#8 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 10:06 AM

Thanks Chris for the answer. Well...I don't know. Where can I find this? I attach the LCD pdf and I will reproduce the page regarding to communication to see if you could tell me yes or no to your question:

Built‐in LCD Controller: PIC 16F690
http://www.newhavend...s/PIC16F690.pdf

Communication Information
This display uses a built‐in PIC 16F690 for serial communication.

I2C protocol:
To enter the I2C mode, place a jumper on R1.
SDA and SDK have pull‐up resistors (10K Ohm) on R7 and R8.
The default I2C address is 80 (50 hex). The I2C address can be changed to any 8‐bit value by command function, with
the exception that the LSB (least significant bit) must always be ‘0’. Once the I2C address has been changed, it will be
saved in the system memory, and it will revert back to the default address if either RS232 or SPI protocol is selected.
The I2C interface is capable of receiving data at up to 100KHz‐clock rate.

SPI protocol:
To enter the SPI mode, place a jumper on R2.
SPI mode has a normally high level idle clock. When Slave Select is LOW, data is sampled on the rising edge of the
Clock.
The SPI interface is capable of receiving data at up to 100KHz‐clock rate.

RS232 protocol:
To enter the RS232 mode, both R1 and R2 should be open.
The RS232 signal must be 5V TTL compatible. Communication format is 8‐bit data, 1 Stop bit, no parity, no handshaking.
Default BAUD rate is 9600, and is changeable with a command function. Once the BAUD rate has been
changed, it will be saved in the system memory, and it will revert back to the default address if either I2C or SPI
protocol is selected.

ASCII TEXT
To display normal text, just enter its ASCII number. A number from 0x00 to 0x07 displays the user
defined custom character, 0x20 to 0x7F displays the standard set of characters, 0xA0 to 0xFD display
characters and symbols that are factory‐masked on the SPLC780D controller. 0xFE is reserved.

Here, if I try this example doing lcd.test(), I don't get a communication error but simply it does nothing.


        public void test()
        {
            string hola = "hellow";
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            byte[] bytesToSend = encoder.GetBytes(hola);

            byte[] command = new byte[2];
            //command to turn off the display
            command[0] = 0xFE;
            command[1] = 0x42;

            byte[] prefix = new byte[1];
            prefix[0] = 0x42;

            //0xFE 0x47 turn on cursor
            // write register address
      
            I2CBus.GetInstance().Write(_slaveConfig, command, TransactionTimeout);
            I2CBus.GetInstance().Write(_slaveConfig, bytesToSend, TransactionTimeout);
            WriteSomethingToSpecificRegister(0xFE, prefix);
            
        }

I have tried to unplug scl/sda and I noticed that if I try to write with scl unplugged then I get a communication error impossible to write to device. If I do the same with sda, no error is shown.

In the same pdf, there is an example of a serial communication. Here it is:

/*****************************************************/
/*
Serial_LCD_Test.c
Program for writing to Newhaven Display Serial LCDs

(c)2010 Curt Lagerstam - Newhaven Display International, LLC. 

 	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
*/
/*****************************************************/

#include "e:\2321_tester\tester_init.h"

/********************************************************************
*                                                                   *
*                    MAIN PROGRAM                                   *
*                                                                   *
********************************************************************/
void main(void)
{
	OSCCON |= 0x73;			// internal RC, 8MHz

	PORTA = 0x00;
	TRISA = 0xFF;			// B'1111 1111'
	PORTB = 0x00;
	TRISB = 0xFF;			// B'1111 1111'
	PORTC = 0x75;			// B'0111 0101'
	TRISC = 0x00;			// B'0000 0000'
	GIE = 0;
	INTCON = 0x00;		    // disable all interrupt
	INTCON2 = 0x00;			// enable port B pull-up
	INTCON3 = 0x00;

/********************************************************************
 set up adc for analog inputs
 ADC clock = Fosc/8 (1 uSecond), adc off, 
 AN0 is contrast input, AN1 is backlight brightness input
********************************************************************/
	ADCON0 = 0x00;
	ADCON1 = 0x0D;			// RA0, RA1 are analog inputs
	ADCON2 = 0x15;			// left just, 4TAD, Fosc/16, 0001 0101

/********************************************************************
 set up timer 0 for 10 millisecond interrupt
 timer 0 is a general purpose timer
********************************************************************/
	T0CON = 0x46;			// timer 0 control register
	T1CON = 0xB0;			// timer 1 off
	
	spi_ss = 1;
	
	if (!i2c_sel) {
		com_mode = 3;		// I2C
		init_i2c();
	}
	else {
		if (!spi_sel) {
			com_mode = 2;	// SPI
			init_spi();
		}
		else {
			com_mode = 1;	// RS232
			init_rs232();
		}
	}

/* END OF SPECIAL REGISTER INITIALIZATION */

	tick_100m = 9;			// 100 millisceond counter
	tick_1s = 9;			// 1 second counter

	TMR0L = 100;			// initialize to 100 counts
	TMR0ON = 1;
	TMR0IF = 0;
	TMR0IE = 1;
	
	contrast = 0;
	contrast_f = 0;
	bright = 0;
	bright_f = 0;
	serial_busy = 0;
	
	TXREG = 0;
	PEIE = 1;
	GIE = 1;				// enable global interrupt

	delay_ms(100);			// waiting for LCD to initialize
		
	lcd_clear();
// Set Contrast
	tx_packet[0] = 0xFE;
	tx_packet[1] = 0x52;
	tx_packet[2] = 40;		// contrast 1 - 50
	send_packet(3);

// Set Backlight Level
	tx_packet[1] = 0x53;
	tx_packet[2] = 15;		// backlight 1 - 15
	send_packet(3);

	tx_packet[1] = 0x48;	// underline cursor off
	send_packet(2);
	
	delay_ms(1000);

//*********************************************************
	for (i = 0; i < 16; i++) {	// "NewHaven Display"
		tx_packet[i] = text6[i];
	}
	send_packet(16);
		
	lcd_cursor(0x40);
	delay_ms(100);
	
	for (i = 0; i < 16; i++) {	//"Serial LCD Demo"
		tx_packet[i] = text7[i];
	}
	
	send_packet(16);
	
	
	temp = 0;
	
	for (;;) {

// Contrast Control
		if (contrast_f && !serial_busy ) {
			tx_packet[0] = 0xFE;
			tx_packet[1] = 0x52;
			tx_packet[2] = contrast_save;
			send_packet(3);
			
			contrast_f = 0;
		}

// Backlight Brightness
		if (bright_f && !serial_busy) {
			tx_packet[0] = 0xFE;
			tx_packet[1] = 0x53;
			tx_packet[2] = bright_save;
			send_packet(3);
			
			bright_f = 0;
		}
	}
}	/* end main	*/

/********************************************************************
 send 'x' byte of the tx_packet[] to the serial port
********************************************************************/
void send_packet(unsigned int x)
{
	unsigned int ix;
	
	led = 1;
	serial_busy = 1;				// set busy flag
	switch (com_mode) {
		case 1:						// RS232 mode
			for (ix = 0; ix < x; ix++) {
				while (!TXIF);
				TXREG = tx_packet[ix];
			}
			while (!TRMT);
			break;
			
		case 2:						// SPI
			spi_ss = 0;
			delay_cycles(5);
			for (ix = 0; ix < x; ix++) {
				SSPBUF = tx_packet[ix];
				while(!BF);
				temp = SSPBUF;
				delay_us(5);		// reduce effective clock rate
			}
			delay_cycles(5);
			spi_ss = 1;
			break;
			
		case 3:						// I2C
			i2c_busy(0x50);			// send address
			
			for (ix = 0; ix < x; ix++) {
				SSPBUF = tx_packet[ix];
				wait_sspif();
			}
			
			PEN = 1;				// send stop bit
			while (PEN == 1);		// wait until stop bit finished

			break;
			
		default:
			break;
	}
	led = 0;
	serial_busy = 0;				// clear busy flag
}

/********************************************************************
  wait for SSPIF set routine, add a software counter to ensure the
  routine does not hang.
********************************************************************/
void wait_sspif(void)
{
	loop_hi = 9;
	loop_lo = 0xC4;
	SSPIF = 0;
	while (!SSPIF && loop_hi) {
		loop_lo--;
		if(!loop_lo)
			loop_hi--;
	}
	SSPIF = 0;
}

/********************************************************************
  i2c_busy routine poll the ACK status bit to see if device is busy
********************************************************************/
void i2c_busy(unsigned char x)
{
	SEN = 1;				// start bit
	while(SEN);				// wait until start bit finished

	while (1) {
		SSPIF = 0;
		SSPBUF = x;			// send write command
		wait_sspif();		// wait until command finished

		if (ACKSTAT) {		// check ACK, if 1, ACK not received
			RSEN = 1;		// then sent start bit again
			while (RSEN);	// wait until start bit finished
		}
		else
			break;
	}
} 
	
/********************************************************************
 set lcd cursor
********************************************************************/
void lcd_cursor(unsigned int x)
{
	tx_packet[0] = 0xFE;
	tx_packet[1] = 0x45;
	tx_packet[2] = x;
	send_packet(3);	
	delay_ms(10);
}

/********************************************************************
 clear one line of display
********************************************************************/
void clear_line(unsigned int x)
{
	unsigned int ij;
	
	for (ij = 0; ij < x; ij++) {
		tx_packet[ij] = 0x20;
	}
	send_packet(x);
}

/********************************************************************
 lcd clear
********************************************************************/
void lcd_clear(void)
{
	tx_packet[0] = 0xFE;
	tx_packet[1] = 0x51;
	send_packet(2);
	delay_ms(10);
}

/********************************************************************
  initialize for USART interface
********************************************************************/
void init_rs232(void)
{
	TXSTA = 0x26;			// rs232 transmit status register
	RCSTA = 0x80;			// serial port enable
	BAUDCTL = 0x08;			// BRG16 = 1;
	SPBRG = 207;
	SPBRGH = 0;
}

/********************************************************************
 initialize for spi interface
********************************************************************/
void init_spi(void)
{
	TRISC |= 0x10;
	SSPCON1 = 0x32;			// master, 125K CLK, CKP = 1
	
	temp = SSPBUF;
	SSPOV = 0;
	SSPIF = 0;
}

/********************************************************************
 initialize for i2c interface
********************************************************************/
void init_i2c(void)
{
	TRISC |= 0x18;			// RC3, RC4 as inputs
	SSPSTAT = 0x00;
	SSPADD = 19;			// 100K Hz
	SSPCON1 = 0x28;			// i2c master, enable SSP

	temp = SSPBUF;
	SSPOV = 0;
	SSPIF = 0;
	SSPIE = 0;				// enable I2C interrupts
}

/********************************************************************
  ADC read routine, read the selected adc channel and put the result
  in adc_result.
********************************************************************/
void adc(unsigned char n)
{
	switch (n) {
		case 0:				// adc channel 0, contrast
			ADCON0 = 0x03;
			break;
			
		case 1:				// adc channel 1, backlight
			ADCON0 = 0x07;
			break;
			
		default:
			break;
	}
					
	while (GODONE);				// wait for end of convert
	adc_result = ADRESH;
	if (adc_result > 250)
		adc_result = 250;
}

/*****************************************************************************/
/* interrupt routines                                                        */
/* timer 0 is set to interrupt at 100 Hz rate.                               */
/*****************************************************************************/
#int_timer0
void timer0_isr(void)	/*interrupt handler routine*/
{
	restart_wdt();		// reset watchdog timer
	TMR0L = 100;
			   		
/********************************************************************
                 10 millisecond functions 
********************************************************************/
	if (tick_wait10)
		tick_wait10--;
	   		
	if (tick_100m) {
   		tick_100m--;
   	} 

/********************************************************************
                 100 millisecond functions 
********************************************************************/
   	else {				// 100 millisecond function
   		tick_100m = 9;	// reload 100 millisecond timer
   			
		if (tick_wait100)		// general purpose 100 mSecond timer
			tick_wait100--;
			
			adc(0);					// read contrast setting
			contrast = adc_result / 5;
			if (!contrast)
				contrast = 1;
				
			if (contrast != contrast_save) {
				contrast_save = contrast;
				contrast_f = 1;
			}

			adc(1);					// read backlight setting
			bright = adc_result / 15;
			if (!bright)
				bright = 1;
				
			if (bright != bright_save) {
				bright_save = bright;
				bright_f = 1;
			}
	
		if (tick_1s) {
			tick_1s--;
		}
/********************************************************************
                    1 second functions 
********************************************************************/
		else {
			tick_1s = 9;		// reload 1 second timer
		}
	}
}	/* end of timer 0 interrupt routine */




Any help would be great thanks!

#9 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 10:15 AM

Chris, I think what you were asking is somewhere between pages 184 and 187 of this pdf here -> http://www.newhavend...s/PIC16F690.pdf

#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 February 2011 - 10:17 AM

Asaak, It looks like the LCD has built-in pull-up resistors. So you should be fine there. Also, it looks like your I2C address defaults to 0x50 (within the 7-bit range) and I don't see any other glaring issues that could be causing problems. My first concern is that we're starting with a huge amount of code here. It should be possible to create a "first test" to just turn the display on and off. With about 4 lines of code. If you can get rid of the I2CBus code, etc. etc. and just boil it down to a "new I2CDevice", "CreateWriteTransaction", and "Execute" set of code...that is probably going to help a bunch here. With this much code and without a device to test against (or any logic analyzer at your location), it's going to be hard to narrow it down. We should start simple. Chris

#11 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 11:37 AM

Here, the simpliest piece of code I think I could write for my purpose. First I send the turn off command and nothing happens, then I send a word which, according to the lcd datasheet if I send the ascii directly it will print. Again, nothing happens.

           /*
             * 0x50 address of the lcd
             * 100 Khz clock
             * 
             */
            I2CDevice lcd = new I2CDevice(new I2CDevice.Configuration(0x50,100));


            /*
             * 0xFE 0x42 no parameters -> turn off display ( nothing happens ) 
             * 
             */
            
            I2CDevice.I2CTransaction[] writeCommandAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] {0xFE, 0x42}) };
            int transferred = lcd.Execute(writeCommandAction, 1000);

            string hola = "hellow";
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            byte[] bytesToSend = encoder.GetBytes(hola);


            I2CDevice.I2CTransaction[] writeWordAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(bytesToSend) };
            transferred = lcd.Execute(writeCommandAction, 1000);


It executes fine, no errors...but nothing in the LCD. I haven't tried with the firmware you suggested. I will do it.

#12 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 11:40 AM

the value of transferred variable is only 1...in both cases.

#13 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 February 2011 - 11:45 AM

Asaak, Do you have access to a logic analyzer (such as the Saleae Logic)? Unfortunately we're murking around in the dark if we can't see what's actually happening on the digital lines. Also, can you use the display in a SPI mode? That might simplify things for you here... [Finally, where can someone buy one of these displays?] Chris

#14 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 11:54 AM

here where you can buy the lcd -> http://www2.mouser.c...VZ7KOwwNV%2bA== I can work in spi mode, I just need to solder the connector of r2 resistor. why is it easier? I don't know how spi works, I need to take a look at it. Sadly, I don't have a logic analyzer..this is why I am in the dark as you said..

#15 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 12:31 PM

The reason why I want it working using i2c is twofold: LCD supports it, and it only need two wires, and this is something very interesting because I do really want to have the rest of the pins free for other connections.

#16 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 01:20 PM

I successfully updated the firmware but now I don't know how to configure repeated start/stop bit. Any help with that?

#17 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 February 2011 - 01:31 PM

I successfully updated the firmware but now I don't know how to configure repeated start/stop bit. Any help with that?

I don't think that the display requires repeated start bit. The repeated start bit feature applies when reading data _from_ an I2C device such as an EEPROM. [I had thought that perhaps some of the commands were reading data from the display earlier...but looking at the data sheet it appears that it is write-only.]

Chris

#18 Tecchie

Tecchie

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationGermany

Posted 19 February 2011 - 04:44 PM

It executes fine, no errors...but nothing in the LCD. I haven't tried with the firmware you suggested. I will do it.


Why do you always try to send the 'display off' as a first command in your examples? If that command works, you certainly won't see anything if the following send commands do actually work!
And 'display off' does not mean that the background lighting goes off, it just disables the LCD part. So i don't see why you are certain that the 'display off' command is not working.

I'd try the following code. And please reset the display (by unplugging it from power) before trying the code, so you can be sure it isn't in some strange state due to your other tests beforehand.

            I2CDevice lcd = new I2CDevice(new I2CDevice.Configuration(0x50,50));

            string hola = "hellow";
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            byte[] bytesToSend = encoder.GetBytes(hola);

            I2CDevice.I2CTransaction[] writeWordAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(bytesToSend) };
            transferred = lcd.Execute(writeCommandAction, 1000);


#19 Asaak

Asaak

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 February 2011 - 05:55 PM

I've tried this code as Tecchie said:

  OutputPort light = new OutputPort(Pins.ONBOARD_LED, true);

            I2CDevice lcd = new I2CDevice(new I2CDevice.Configuration(0x50, 50));
            int bytesTransferred = 0;

            string hellow = "hellow";
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            byte[] bytesToSend = encoder.GetBytes(hellow);

            I2CDevice.I2CTransaction[] writeCommandAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(bytesToSend) };
            bytesTransferred = lcd.Execute(writeCommandAction, 1000);

            if (bytesTransferred != bytesToSend.Length)
            {
                light.Write(false);
            }

nothing happens. It says it has sent all the 6 byte to transfer, even if I unplug all the LCD wires. on_board led turns off like if all the bytes have beens successfully transfered...but they are not.

#20 klotz

klotz

    Advanced Member

  • Members
  • PipPipPip
  • 60 posts

Posted 20 February 2011 - 04:13 AM

I have a Newhaven display running in .NETMF, you can look a working code on http://www.fezzer.co...ial-lcd-display . While this was done FEZ Panda, the code should work on Netduino. Give it a look. I will try it with the Netduino tomorrow morning myself so I can post a demon with the Netduino




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.