element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Vision Thing
  • Challenges & Projects
  • Project14
  • Vision Thing
  • More
  • Cancel
Vision Thing
Blog LDR Camera #2 : Adding an 8x8 Dot Matrix LED Display
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Vision Thing to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dubbie
  • Date Created: 27 Sep 2019 2:15 PM Date Created
  • Views 2952 views
  • Likes 7 likes
  • Comments 4 comments
  • visionthingch
  • ardexpert
  • led matrix display
  • ldr camera
Related
Recommended

LDR Camera #2 : Adding an 8x8 Dot Matrix LED Display

dubbie
dubbie
27 Sep 2019
image

Vision Thing

Enter Your Project for a chance to win an Oscilloscope Grand Prize Package for the Most Creative Vision Thing Project!

Back to The Project14 homepage image

Project14 Home
Monthly Themes
Monthly Theme Poll

 

While I was waiting for the analogue multiplexers to come that I need to make the rest of the LDR camera I decided to add an 8x8 array LED display as I just happened to have one (thanks shabaz ). This is a fun display using a HT16K33 to drive an 8x8 LED array using the SPI interface. Unfortunately on the Arduino Nano the two SPI signals SCL and SDA are on pins A4 and A5 so I could not use two of the analogue inputs. This is not a problem for the final camera as with the 16-to-1 multiplexers I am hoping to use I will only need four of the analogue inputs, so it wasn't worth messing about trying to overcome this problem for this test-of-concept implementation.

 

These matrix LED arrays have been around for some time although I had never used any before, so the first step was to download the Arduino Libraries. I'm not familiar with this process despite having downloaded Arduino libraries before (but then I just clicked on a link and it all seemed to happen without too much of my intervention) and the descriptions do seem to assume that you mostly know what is going on. As I didn't it took me two days to work it all out. The test programmes provided with the matrix displays worked but when I tried to write my own, it didn't. That took me another day to work out - I had to define the display as an 8x8 matrix to do the individual pixel control that I wanted. Obvious when I had worked it out, but not at all clear from the documentation.

 

All I did then was to amend my previous LDR to serial monitor programme to include outputting to a row of pixels on the matrix display (only 6 of them as two analogue inputs are being used by the display), see below. The display works by setting values in a memory buffer using the drawPixel(x,y,colour) function and then transferring the buffer contents to the LED matrix using writeDisplay() function. I'm still not entirely sure how it works but at least it does what I want it to do. It is not a clever programme in any way but it is just for testing. Once I implement the analogue multiplexers I will see about making it more compact and more generalised.

 

threshold = 50;

while (1)
  {
    matrix.clear();      // clear display
    LDRvalue = analogRead(LDR0pin);
    Serial.print(LDRvalue);
    Serial.print(" ");
    if (LDRvalue > threshold)
      matrix.drawPixel(0, 0, 1);
    else
      matrix.drawPixel(0, 0, 0);   
    LDRvalue = analogRead(LDR1pin);
    Serial.print(LDRvalue);
    Serial.print(" ");
    if (LDRvalue > threshold)
      matrix.drawPixel(0, 1, 1);
    else
      matrix.drawPixel(0, 1, 0); 
    LDRvalue = analogRead(LDR2pin);
    Serial.print(LDRvalue);
    Serial.print(" ");
    if (LDRvalue > threshold)
      matrix.drawPixel(0, 2, 1);
    else
      matrix.drawPixel(0, 2, 0); 
    LDRvalue = analogRead(LDR3pin);
    Serial.print(LDRvalue);
    Serial.print(" ");
    if (LDRvalue > threshold)
      matrix.drawPixel(0, 3, 1);
    else
      matrix.drawPixel(0, 3, 0); 
//      LDRvalue = analogRead(LDR4pin);
    Serial.print("xx");
    Serial.print(" ");
//      LDRvalue = analogRead(LDR5pin);
    Serial.print("xx");
    Serial.print(" ");
    LDRvalue = analogRead(LDR6pin);
    Serial.print(LDRvalue);
    Serial.print(" ");
    if (LDRvalue > threshold)
      matrix.drawPixel(0, 6, 1);
    else
      matrix.drawPixel(0, 6, 0);   
    LDRvalue = analogRead(LDR7pin);
    Serial.println(LDRvalue);
    if (LDRvalue > threshold)
      matrix.drawPixel(0, 7, 1);
    else
      matrix.drawPixel(0, 7, 0);   
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(500);   
  } /* while */

 

The LEDs can only be ON or OFF which is disappointing as I was hoping for a grey scale LED matrix display. The documentation for the display does indicate that there are 16 levels of LED brightness but this applies to the whole display rather than being able to control individual pixels. It might be possible to achieve some level of grey scale control of individual LEDs by rapidly updating the display to create a kind of PWM for each LED but that's a lot of software I do not want to write at present.

 

I have set a threshold light level of 50 so any level below 50 which is bright light, has the LED off and any value above 50 which is shadow turns the LED on. The video below shows all this in operation. I still output the LDR data to the serial monitor and the xx values indicate the locations of the A4 and A5 inputs from the LDR that are used for the SPI interface.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

All I need now is for the rest of the LDRs and analogue multiplexers to arrive and I shold be able to make the rest of the LDR camera. After that it will be the ANN (artificial neural network) for for recognising the content of the images captured. You never know, it might all just work.

 

Dubbie

  • Sign in to reply

Top Comments

  • shabaz
    shabaz over 5 years ago +3
    Hi Dubbie, Glad the display is coming in handy : ) Adafruit had some code, but it was slightly bloated, so I too wrote my own code. There is some slightly weird mapping, as no doubt you spotted! : ) Anyway…
  • clem57
    clem57 over 5 years ago +3
    Great job dubbie . If you would like a bit of grey scale, you could turn on 0-8 depending on the level of grey and this would look like a graph of darkness or lightness. I will show using just the 3 LDR…
  • dubbie
    dubbie over 5 years ago in reply to shabaz +2
    I was struggling with GitHub when I started using the 8x8 matrix displays, so decided not to look up your programme at that time. Now that I have conquered getting the matrix display libraries installed…
  • dubbie
    dubbie over 5 years ago in reply to clem57

    Thanks for this idea. It took me a while to work out what the code would do but eventually understanding dawned. It's an interesting idea and seems like it would work well for a 1x8 LDR camera. Not sure how it might work for the final 8x8 camera.

     

    Dubbie

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dubbie
    dubbie over 5 years ago in reply to shabaz

    I was struggling with GitHub when I started using the 8x8 matrix displays, so decided not to look up your programme at that time. Now that I have conquered getting the matrix display libraries installed I might have another try.

     

    The snippet of code you provided is a good idea, I had not thought of putting the analogue input pin names into an array before, that's a good idea. I will have to try that. I'm still toying with the idea of trying to make the matrix display a sort of grey scale display. I reckon that if the display update rate is fast enough it might be possible to create a software loop that performs some sort of PWM on each individual LED. For example if I had four memory maps of the display, with each plane representing one level of a four level grey scale then output each plane for a quarter of the time, this should produce at least some variation in light intensity. Each pixel would then appear in none, one, two or three of the planes to create the four different levels of brightness. It would just depend on how quickly the 8x8 memory planes could be updated. I might give this a go.

     

    Dubbie

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 5 years ago

    Great job dubbie. If you would like a bit of grey scale, you could turn on 0-8 depending on the level of grey and this would look like a graph of darkness or lightness. I will show using just the 3 LDR. The others are the same method.

     

    Gval = value from ldr #3 / 32; The result should be from 0 through 7... So 0-31 is 0, 32-63 is 1, etc. up to 255.

    if (LDRvalue > threshold)

          matrix.drawPixel(Gval, 3, 1);

        else

          matrix.drawPixel(Gval, 3, 0); 

     

     

    Clem

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 5 years ago

    Hi Dubbie,

     

    Glad the display is coming in handy : )

    Adafruit had some code, but it was slightly bloated, so I too wrote my own code. There is some slightly weird mapping, as no doubt you spotted! : )

    Anyway, it sounds all sorted, otherwise see the Pocket Nim code from line 828 onward (not tested on Arduino, but the I2C specific stuff is isolated to the first two functions from that line onward, so those could be replaced).

    For the code above, something like this might work (this could be improved too, it's just to reduce the code a bit).

    #define LED_ON 1
    #define LED_OFF 0
    
    
    void loop() {
    
    
      int i, a;
      int ldr_pin[]={A0, A1, A2, A3, A4, A5, A6, A7};
      while(1)
      {
        matrix.clear();
        for (i=0; i<8; i++)
        {
          a=analogRead(ldr_pin[i]);
          Serial.print(a);
          Serial.print(" ");
          
          if (a>threshold)
          {
            matrix.drawPixel(0, i, LED_ON);
          }
          else
          {
            matrix.drawPixel(0, i, LED_OFF);
          }
        }
        matrix.writeDisplay();
        delay(500);
      } // end while(1)
      
    }

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube