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.

K0demonkey

Member Since 27 Apr 2011
Offline Last Active Sep 08 2014 09:51 AM
-----

Posts I've Made

In Topic: HHP IT3800 Barcode Scanner

20 May 2011 - 06:49 PM

Any chance someone could attempt porting this PS2Keyboard Library to Netduino?

In Topic: LCD Help needed, 16x2s are boring

19 May 2011 - 05:14 PM

the display is 84x84 pixels, so each character needs to be defined by a bitmap telling which bits are on and off for a given character. Here is a little background if you are interested: http://www.instructa...g-a-custom-font

If you look at the first page of this thread, on the 7th post or so at the bottom it says:
"Notes: "NokiaCharacters.ASCII" is a public static class that contains the "public static byte[] ASCII = new byte[] {....};" thing. "

Basically take the byte array called ASCII from the 5th post on the first page and put it in its own class called NokiaCharacters.
Alternatively you could put the byte array right into your code.

Hope that helps,
Mike


Mike & All ...

Thanks so much for the help. Everything works!

Posted Image

Now on to get to email working. :D

In Topic: LCD Help needed, 16x2s are boring

19 May 2011 - 11:27 AM

@K0demonkey

It seems your wiring is not quite correct.
Pins 3 and 4 on the LCD are the clock pin and the data pin, you definitely need those to send data to the display.
They need to be connected to the SPI clock pin (Netduino PIN 13) and the SPI MOSI pin (Netduino PIN 11).


THANK YOU!

Posted Image

My next question is ... how do I print text to the screen?

I've tried Omar's code,
    public class Nokia_5110
    {
        private bool[] _offRow = new bool[84];

        private readonly byte[] _pow = new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 };

        private OutputPort _resetPort, _daComPin;
        private PWM _backlightPort;
        private SPI _dataPort;

        public bool[][] _pixelMap = new bool[48][];
        private byte[] _byteMap = new byte[504];

        private uint _backlight = 0;
        private bool _invd = false, _autoRefresh = true;

        public Nokia_5110(Cpu.Pin chipSelect = Pins.GPIO_PIN_D3, Cpu.Pin backlight = Pins.GPIO_PIN_D9,
            Cpu.Pin reset = Pins.GPIO_PIN_D7, Cpu.Pin dataCommand = Pins.GPIO_PIN_D8)
        {
            SPI.Configuration spiConfiguration = new SPI.Configuration(
                chipSelect,            // chip select port 
                false,                 // IC is accessed when chip select is low 
                0,                     // setup time 1 ms 
                0,                     // hold chip select 1 ms after transfer 
                false,                 // clock line is low if device is not selected 
                true,                  // data is sampled at leading edge of clock 
                2000,                 // clockrate is 15 MHz 
                SPI.SPI_module.SPI1   // use first SPI bus 
                );

            _dataPort = new SPI(spiConfiguration);
            _backlightPort = new PWM(backlight);
            _resetPort = new OutputPort(reset, true);
            _daComPin = new OutputPort(dataCommand, true);

            Initialize();
            Clear();
        }

        private void Initialize()
        {
            _resetPort.Write(false);
            _resetPort.Write(true);
            DataMode = false;
            _dataPort.Write(new byte[] { 0x21, 0xBF, 0x04, 0x14, 0x0C, 0x20, 0x0C });
            DataMode = true;
            Clear();
        }

        public void SetCursor(float x, float y)
        {
            DataMode = false;
            _dataPort.Write(new byte[] { (byte)(0x80 | (int)(x * 4)), (byte)(0x40 | (int)(y)) });
            DataMode = true;
        }

        public void WriteText(string text, bool noSpace = true)
        {
            DataMode = true;

            if (noSpace)
                foreach (char c in text.ToCharArray())
                    _dataPort.Write(NokiaCharacters.ASCII[c - 0x20]);
            else
            {
                byte[] letter = new byte[6];
                foreach (char c in text.ToCharArray())
                {
                    for (int i = 0; i < 5; i++)
                        letter[i] = NokiaCharacters.ASCII[c - 0x20][i];

                    letter[5] = 0x00;
                    _dataPort.Write(letter);
                }

            }
        }

        public void DrawRectangle(int x, int y, int width, int height, bool filled)
        {
            // thats what lines are for! oh right... I need to make a Draw line method...  
            if (width <= 1 || height <= 1)
                return;

            int endX = x + width, endY = y + height - 2;

            bool[] line = new bool[84];

            for (int p = x; p < endX; p++)
                line[p] = true;

            _pixelMap[y] = line;
            _pixelMap[endY] = line;

            if (!filled)
            {
                line = new bool[84];
                line[x] = true;
                line[endX - 1] = true;
            }

            for (int h = y + 1; h < endY; h++)
                _pixelMap[h] = line;

            if (AutoRefresh)
                Refresh();
        }

        public void Refresh()
        {
            int byteID = 0;

            for (int y = 0; y < 6; y++)
            {
                for (int x = 0; x < 84; x++)
                {
                    _byteMap[byteID] = ConvertToByte(_pixelMap[y * 8][x], _pixelMap[y * 8 + 1][x],
                                       _pixelMap[y * 8 + 2][x], _pixelMap[y * 8 + 3][x], _pixelMap[y * 8 + 4][x],
                                       _pixelMap[y * 8 + 5][x], _pixelMap[y * 8 + 6][x], _pixelMap[y * 8 + 7][x]);
                    byteID++;
                }
            }

            _dataPort.Write(_byteMap);
            SetCursor(0, 0);
        }

        private byte ConvertToByte(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7)
        {
            byte result = 0;

            result += (byte)((b7) ? _pow[7] : 0);
            result += (byte)((b6) ? _pow[6] : 0);
            result += (byte)((b5) ? _pow[5] : 0);
            result += (byte)((b4) ? _pow[4] : 0);
            result += (byte)((b3) ? _pow[3] : 0);
            result += (byte)((b2) ? _pow[2] : 0);
            result += (byte)((b1) ? _pow[1] : 0);
            result += (byte)((b0) ? _pow[0] : 0);

            return result;
        }

        public void Clear()
        {
            for (int r = 0; r < 48; r++)
                _pixelMap[r] = _offRow;

            if (_autoRefresh)
                Refresh();
        }

        private void Inverse(bool inverse)
        {
            _invd = inverse;
            DataMode = false;
            _dataPort.Write(inverse ? new byte[] { 0x0D } : new byte[] { 0x0C });
            DataMode = true;
        }

        public bool InverseColors
        {
            get { return _invd; }
            set { Inverse(value); }
        }

        private bool DataMode
        {
            get { return _daComPin.Read(); }
            set { _daComPin.Write(value); }
        }

        public uint BacklightBrightness
        {
            get
            { return _backlight; }
            set
            {
                if (value > 100)
                    value = 100;

                _backlightPort.SetDutyCycle(value);
                _backlight = 100;
            }
        }

        public bool AutoRefresh
        {
            get { return _autoRefresh; }
            set { _autoRefresh = value; }
        }
    }

but the dev environment is complaining that NokiaCharacters does not exist in the current context.

In Topic: LCD Help needed, 16x2s are boring

18 May 2011 - 08:02 PM

I purchased the Nokia display from Adafruit.

It looks like this:
Posted Image

Posted Image

In following AlfredBr's code [HERE] I have this board wired like this:

Nokia Pin 1: Netduino Gnd
Nokia Pin 2: Netduino 3.3v
Nokia Pin 3: Empty
Nokia Pin 4: Empty
Nokia Pin 5: D1
Nokia Pin 6: D8
Nokia Pin 7: D1
Nokia Pin 8: D5

Posted Image

I am no longer getting the PWM.cs error, but I still cannot get this display to work. I do see the backlight come on when I load the program to debug, but nothing is being drawn on the screen.

Is there anything else I should be looking at? This hardware stuff is totally new to me.

Shan

In Topic: LCD Help needed, 16x2s are boring

13 May 2011 - 05:47 PM

If you are stepping though the code using "Step Into" command (usually F11), try "Step Over" (F10) instead. PWM.cs is included in Netduino SDK source.


Thanks everyone. I am wondering if my issue is due to installing the 32-bit SDK instead of the 64-bit SDK on my Windows7 x64.

I've reinstalled and will try again this weekend.

Shan

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.