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.

NicholasSTG's Content

There have been 16 items by NicholasSTG (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#36215 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 29 September 2012 - 12:21 AM in General Discussion

I've got to trackdown the 'why' but changing the driver's SetPixel to

          private void SetPixel(int x, int y, ushort color) {
            if ((x < 0) || (x >= Width) || (y < 0) || (y >= Height)) return;

            var index = ((y * Width) + x) * sizeof(ushort) - y * 4;    

            if (index < 0 || index >= SpiBuffer.Length) return;
            SpiBuffer[index] = (byte) (color >> 8);
            SpiBuffer[++index] = (byte)(color);
        }

seems to have done the trick. The check on the index is just there because I was debugging.



#36210 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 28 September 2012 - 11:07 PM in General Discussion

What abt drawline? Did u try it?


I did.

I wrote this code to sort of see what was happening

public static void Main() {
            // DisplayPicture();

            tft.ClearScreen((ushort)AdaFruitST7735.Colors.White);
            // DisplayGradient();

            // DisplayCircles();

            for (int x = 0; x < 86; x++ )
            {
                tft.DrawPixel(x, 20, (ushort)AdaFruitST7735.Colors.Red);
            }

            for (int y = 0; y < 10; y++)
            {
                tft.DrawPixel(10, y, (ushort)AdaFruitST7735.Colors.Red);
            }

            for (int x = 0; x < 100; x++)
            {
                tft.DrawPixel(x, 5, (ushort)AdaFruitST7735.Colors.Green);
            }

            tft.DrawLine(50, 50, 50,100,(ushort)AdaFruitST7735.Colors.Blue);

            tft.DrawLine(50, 50, 100,50,(ushort)AdaFruitST7735.Colors.Yellow);

            tft.Refresh();

            // tft.ClearScreen();
            // DisplayLines();

            // DisplayColorFlow();
        }

The result looked like the attachment.

It seems that the 0 point is wrong so when the it tries to calculate a horizontal line the shifts in the register get out of whack.

2012-09-28 15.05.12.jpg



#36206 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 28 September 2012 - 09:26 PM in General Discussion

Does ur circle changed direction?


The circles do animate when I use the appropriate method, yes.

IT almost seems as if 0,0 is in the wrong spot which throws off all of the other calculations.



#36204 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 28 September 2012 - 09:03 PM in General Discussion

I'm guessing you did not have this issue with the skewing?



#36202 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 28 September 2012 - 08:35 PM in General Discussion

I also downloaded that entire commit from codeplex and it did not make a change.



#36201 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 28 September 2012 - 08:27 PM in General Discussion

Thanks for all your help. Your Driver seems to help and seems to be different than the version I got when I downloaded the latest from the netduino library.

I now get a picture, but it seems ... 'skewed'.

For instance

public static void Main()
        {
            // DisplayPicture();

            tft.ClearScreen((ushort)AdaFruitST7735.Colors.White);
            // tft.DrawCircle(AdaFruitST7735.Width / 2, AdaFruitST7735.Height / 2, AdaFruitST7735.Width / 4, (ushort)AdaFruitST7735.Colors.Red);
            tft.DrawCircle(50, 50, 10, (ushort)AdaFruitST7735.Colors.Red);
            tft.Refresh();
            /*
            DisplayGradient();
            */
            // DisplayCircles();
            /*
            tft.ClearScreen();
            DisplayLines();
            */
            // DisplayColorFlow();
        }

generates a picture like the following

Posted Image

I've checked the wiring, etc and it all seems to be good. I also downloaded the ExtededSpiConfiguration class from the same revision as your code, just in case it was that.

It didn't make a change.



#36180 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 28 September 2012 - 02:39 PM in General Discussion

Hmmm, that's where I sourced my code originally.

I've just commented out a couple of lines since I don't have an SD card in the screen

public static AdaFruitST7735 tft = new AdaFruitST7735(Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D8, speedKHz: 40000);

        public static void Main()
        {
            // DisplayPicture();

            tft.ClearScreen();
            DisplayGradient();

            DisplayCircles();

            tft.ClearScreen();
            DisplayLines();

            // DisplayColorFlow();
        }

There's no change, still all scrambled. The code is running (I've tried breakpoints in the Program.cs class and AdaFruitST7735 class and it is hitting them as it is should) so I'm not sure what's up.

I've checked all the wiring multiple times.

When the program starts the screen goes white and then scrambles. The scrambling occurs when the AdaFruitST7735 class is initiated (in the ClearScreen method).



#36118 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 28 September 2012 - 04:22 AM in General Discussion

var lcd = new AdaFruitST7735(Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D8);


This seems to be the code I tried already, but I tried anyways and still have the same problem. Did you get this to work?



#35868 Having a problem with my adafruit ST7735 LCD

Posted by NicholasSTG on 23 September 2012 - 09:53 PM in General Discussion

I am experiencing the exact same problem. Did you ever manage to resolve the issue?


Did you resolve this? I am having the same issue.



#21807 Sparkfun MP3 Player Shield

Posted by NicholasSTG on 17 December 2011 - 08:43 PM in Netduino 2 (and Netduino 1)

Hello Nicholas.
What's exactly the problem? Could you post some code that you tried to get it work?
Upon what you're saying the player does not play any song?
Cheers


I'm terribly sorry, I was on my way out the door and wasn't thinking.

The code is below, but I have two files on the MP3 card and when it tries to play the second it simply stops all program execution. My first instinct was that it was trying to play the song and simply could not (and was not really locked, but just taking a long time), but the track is only 4 seconds and program execution takes easily 2 minutes before I stop it.

Main Program

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

namespace NetduinoMp3
{
    public class Program
    {
        private static readonly int FileBufferSize = Vs1053.BufferSize * 10;

        public static void Main()
        {
            Debug.Print(DateTime.Now.ToString());
            String sdroot = "MP3SD";
            StorageDevice.MountSD(sdroot, SPI_Devices.SPI1, Pins.GPIO_PIN_D9);
                        
            String[] files = Directory.GetFiles(@"\" + sdroot);
            Debug.Print("file count: " + files.Length);

            Vs1053.Initialize();
            Vs1053.SetVolume(0xFEFE);

            for (var i = 0; i < files.Length; i++)
            {
                Debug.Print("filename: " + files[i]);
                Vs1053.SetVolume(0x60,0x60);
                var fileStream = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, FileBufferSize);

                Vs1053.SendData(fileStream);

                fileStream.Close();
            }
        }
    }
}

Shield Class


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

namespace NetduinoMp3
{
    public static class Vs1053
    {
        // GPIO ports:
        static private OutputPort _reset;
        static private InterruptPort _dreq;

        const Cpu.Pin PinBsync = Pins.GPIO_PIN_D7;  // was 2
        const Cpu.Pin PinDreq = Pins.GPIO_PIN_D2;   // was 3
        const Cpu.Pin PinReset = Pins.GPIO_PIN_D8;  // was 6  // NOTE: This doesn't map to an actual pin
        const Cpu.Pin PinCs = Pins.GPIO_PIN_D6;     // was 9

        // Define SPI Configuration for VS1053 MP3 decoder:
        static private readonly SPI.Configuration DataConfig = new SPI.Configuration(PinBsync, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);    // changed speed from 3000 to 1000
        static private readonly SPI.Configuration CmdConfig = new SPI.Configuration(PinCs, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);        // changed speed from 3000 to 1000
        static private SPI _spi;

        // Registers:
        const int RegisterSciMode = 0x00;
        const int RegisterSciVol = 0x0B;
        const int RegisterSciClockf = 0x03;

        public static readonly int BufferSize = 32; // was 96
        private const ushort SciMode = 0x880;  // SM_SDINEW (default) + SM_EARSPEAKER_HI

        static private bool _isInitialized;
        static private readonly byte[] ReadBuffer = new byte[BufferSize];
        static private readonly byte[] CmdBuffer = new byte[4];

        static private readonly AutoResetEvent AutoResetEvent = new AutoResetEvent(false);

        public static void Initialize() {
            if (_isInitialized)
                Shutdown();
 
            _spi = new SPI(CmdConfig);
            _reset = new OutputPort(PinReset, true);
            _dreq = new InterruptPort(PinDreq, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
            _dreq.OnInterrupt += _dreq_OnInterrupt;
 
            _isInitialized = true;
 
            Reset();
 
            CommandWrite(RegisterSciMode, SciMode | (1 << 2));
            CommandWrite(RegisterSciClockf, 7 << 13);
            CommandWrite(RegisterSciVol, 0x2424);
 
            _spi.Config = DataConfig;
        }

        private static void _dreq_OnInterrupt(uint port, uint state, DateTime time)
        {
            if (state == 0)
            {
                AutoResetEvent.Set();
            }
            else
            {
                AutoResetEvent.WaitOne();
            }
            _dreq.ClearInterrupt();
        }

        private static void Reset()
        {
            _reset.Write(false);
            Thread.Sleep(1);
            _reset.Write(true);
            Thread.Sleep(1);
        }

        static private void CommandWrite(byte address, ushort data)
        {
            CmdBuffer[0] = 0x02;
            CmdBuffer[1] = address;
            CmdBuffer[2] = (byte)(data >> 8);
            CmdBuffer[3] = (byte)data;

            _spi.Write(CmdBuffer);
        }

        static private ushort CommandRead(byte address) {
            CmdBuffer[0] = 0x03;
            CmdBuffer[1] = address;
            CmdBuffer[2] = 0;
            CmdBuffer[3] = 0;
 
            _spi.WriteRead(CmdBuffer, CmdBuffer, 2);
 
            ushort command = CmdBuffer[0];
            if (command <  100)
                throw new ArgumentOutOfRangeException("volume");
 
            // SetVolumePercent(volume, volume);
            return command; // this was not here, but since CommandRead is not referenced anywhere I'm not sure it affects anything ...
        }

        public static void SetVolumePercent(int leftChannel, int rightChannel)
        {
            if (leftChannel < 0 || leftChannel > 100)
                throw new ArgumentOutOfRangeException("leftChannel");
            if (rightChannel < 0 || rightChannel > 100)
                throw new ArgumentOutOfRangeException("rightChannel");

            // TODO: Invert decibel value, divide by percent, call SetVolume(ushort leftChannel, ushort rightChannel)
        }

        public static void SetVolume(ushort bothChannels)
        {
            CommandWrite(RegisterSciVol, bothChannels);  // TODO: This doesn't work outside the Initialize() method
        }

        public static void SetVolume(ushort leftChannel, ushort rightChannel)
        {
            SetVolume((ushort)(leftChannel * 256 + rightChannel)); // TODO: Verify no loss of fidelity
        }

        public static void SendData(FileStream fileStream)
        {
            var size = fileStream.Length - fileStream.Length % BufferSize;
            for (var i = 0; i < size; i += BufferSize)
            {
                fileStream.Read(ReadBuffer, 0, BufferSize);

                _spi.Write(ReadBuffer);
            }
        }

        public static void Shutdown()
        {
            if (!_isInitialized) return;

            Reset();

            _spi.Dispose();
            _reset.Dispose();
            _dreq.Dispose();

            _isInitialized = false;
        }
    }
}


I found the original shield class on http://www.jaypm.com...-the-netduino/. The code did not work and I have made changes (noted in the comments).

The output of the program looks like this

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
01/01/2009 22:52:07
file count: 2
filename: \MP3SD\TRACK002.MP3
filename: \MP3SD\TRACK001.MP3
The program '[9] Micro Framework application: Managed' has exited with code 0 (0x0).


Thanks so much for your help.



#21778 Sparkfun MP3 Player Shield

Posted by NicholasSTG on 17 December 2011 - 01:41 AM in Netduino 2 (and Netduino 1)

I have a regular Netduino and a Sparkfun MP3 Player Shield with build in SD card reader (http://www.sparkfun.com/products/10628). It works great as an SD card reader, but I cannot manage to get it to play any mp3s. All of the examples I have found for it online point to the previous version of the board without the SD card reader so my gut feeling is that the addition of the SD card is causing my issues. Has anyone had any luck with this shield?



#21777 Spi prblems with vl1053 (mp3 decoder) - SOLVED

Posted by NicholasSTG on 17 December 2011 - 12:49 AM in Netduino Mini

Sorry, I don't know anything about the shield you're using. I'm using a simple vs1053 breakout board and a Netduino mini.

Maybe someone else can help you?


Thanks for all your help. I had a feeling the more I stepped through it I was using different hardware.



#21774 Spi prblems with vl1053 (mp3 decoder) - SOLVED

Posted by NicholasSTG on 16 December 2011 - 11:50 PM in Netduino Mini

You're welcome. The device is initially muted so remember to set an appropriate volume by writing a value of say 0x60 to register 0xB.

Use the WriteData class function to send your data (mp3 or other) for the device to play.

Good luck!


Ok, I'm beginning to think I'm not terribly bright. Than you so much for the code, but I cannot seem to make it work. I have the regular Netduino and the Sparkfun Shield with SD Card on board (http://www.sparkfun.com/products/10628). I've managed to read SD cards in a separate project.

Is the board I have the board you've gotten your card to work with? I've changed the pin definitions to match the shield as opposed to the Netduino Mini, and tried several other things I can think of, but it seems to think it's playing (and in a couple of cases I've gotten static, just no sound). The partial success is what lead me to pull the SD card bits out and just try to play an embedded resource, but that did not help (I've been trying the sample files posted on the sparkfun site just since it seemed most likely that those would work).

Would it be possible for you to post a working example of your code playing a file? I'm just going a little crazy after a couple days trying to make this work.

Thanks.



#21771 So how does the SD card stuff work anyway?

Posted by NicholasSTG on 16 December 2011 - 10:00 PM in Netduino 2 (and Netduino 1)

Hi Chad,
I am also trying to create an MP3 player using Netduino with an MP3 shield+SD card.
http://www.sparkfun.com/products/10628

However, I can't seem to get the audio to come out. The shield works with my Arduino. When I port the code over to Netduino It did not work. Can you share your set up for the VS1053 (MODE, CLOCK, VOL, etc...)?

I have spent many long nights and weekends without any luck.

Regards,
Richard


Hi, I am having the same issues. I was curious if you had managed to make yours work.



#21740 Spi prblems with vl1053 (mp3 decoder) - SOLVED

Posted by NicholasSTG on 15 December 2011 - 10:15 PM in Netduino Mini

Thanks for the post. I'm at work, but I can't wait to get home and give this a whirl.



#21721 Spi prblems with vl1053 (mp3 decoder) - SOLVED

Posted by NicholasSTG on 15 December 2011 - 04:08 AM in Netduino Mini

Sorry for taking so long to reply - are you still interested in the setup code?


I'd love to get this code if possible.




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.