0

Electronic Animated Eyes using Teensy 3.1
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Electronic Animated Eyes using Teensy 3.1

by pburgess on Fri Jul 15, 2016 11:58 am

Absolutely, by tweaking the value of uThreshold and lThreshold near the end of the frame() function.

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Re: Electronic Animated Eyes using Teensy 3.1

by Dragten on Fri Jul 15, 2016 12:04 pm

pburgess wrote:Absolutely, by tweaking the value of uThreshold and lThreshold near the end of the frame() function.


With the speed of your replies, I sometimes wonder if you ever sleep!

Thank you for the reply. Its good to know that its possible.
Is there any way I can be so bold as to ask for the code example, if you have some time to spare?

Dragten
 
Posts: 10
Joined: Tue Feb 23, 2016 7:51 am

Re: Electronic Animated Eyes using Teensy 3.1

by pburgess on Fri Jul 15, 2016 12:20 pm

Dragten wrote:Is there any way I can be so bold as to ask for the code example, if you have some time to spare?


No.





Kidding. Maybe half no. My test eye rig is all dismantled at the moment, but I can give you some hints how it'd be done...

Very last line in in the frame() function is:
Code: Select all | TOGGLE FULL SIZE
  drawEye(eyeIndex, iScale, eyeX, eyeY, n, lThreshold);

The last two arguments, n and lThreshold, set the "closed-ness" of the upper and lower lids (don't modify uThreshold, I just noticed, it's a global thing that needs to keep state between invocations of that function). You could nudge these values based on a potentiometer reading, e.g.:
Code: Select all | TOGGLE FULL SIZE
uint16_t foo = analogRead(A3); // 0-1023
n = map(foo, 0, 1023, n, 254); // Push 'n' toward 254 based on foo
lThreshold = map(foo, 0, 1023, lThreshold, 254); // Ditto

I might have my idea of the threshold backwards, in which case change the last argument in each foo() call from 254 to 0.

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Re: Electronic Animated Eyes using Teensy 3.1

by Dragten on Fri Jul 15, 2016 12:28 pm

Thank you very much, I will try it out and see if I can figure it out.
Will poke around the dark a little :)



So far, thanks to you, I have made great progress.
http://i.imgur.com/HpTyunL.gifv

Dragten
 
Posts: 10
Joined: Tue Feb 23, 2016 7:51 am

Re: Electronic Animated Eyes using Teensy 3.1

by pburgess on Fri Jul 15, 2016 12:38 pm

OMG is that a gryphon?

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Re: Electronic Animated Eyes using Teensy 3.1

by Dragten on Fri Jul 15, 2016 12:40 pm

pburgess wrote:OMG is that a gryphon?


To-be :)

Dragten
 
Posts: 10
Joined: Tue Feb 23, 2016 7:51 am

Re: Electronic Animated Eyes using Teensy 3.1

by mr_koz on Sat Jul 16, 2016 11:01 am

I've been playing with this one for a while and its awesome, the trick is i have 4 screens and on my journey to getting all 4 working i'm trying to change the cs pins - doesn't seem to work on any pins apart from the 9/10 pins in the guide. Its likely i've crossed up some pins but i thought i'd ask, is there any reason i can't use different pins? Do they have to be digital pins? Pointers on which will/wont work?

PS its for my 1.2m spider named Yorick :)
Attachments
2016-05-30 19.40.39 copy.jpg
Yorick
2016-05-30 19.40.39 copy.jpg (385.77 KiB) Viewed 230 times

mr_koz
 
Posts: 5
Joined: Thu Sep 24, 2015 10:00 am

Re: Electronic Animated Eyes using Teensy 3.1

by pburgess on Sat Jul 16, 2016 1:59 pm

Hm!

Can't think of anything offhand that'd prevent other pins from working. Have you tried just one or two eyes using different CS pins?

Although -in theory- is should support multiple eyes, currently there's some assumptions in the code (like the horizontal flip) that are coded for one each left/right. I only have two screens on-hand so never got around to testing the idea. But at the very least, some tweaks are probably required.

What are the symptoms w/multiple eyes? Do the first two work? Or does the whole thing come crashing down?

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Re: Electronic Animated Eyes using Teensy 3.1

by Gid3on on Tue Jul 19, 2016 11:42 pm

pburgess wrote:The tablegen.py script currently can only handle a round pupil. "Novelty shapes" like the dragon or g0at™ are a kludge...basically, if you pass a negative iris size, the script loads an image (always called 'pupilMap.png') to use for pupil size calculations (image dimensions must match the absolute value of this size, e.g. pass -128 for a 128x128 pixel image).

Pixel brightness in this image corresponds to the pupil size/shape in response to light. For example, here's a 160x160 g0at pupil:
goatPupil.png

I haven't figured out the math for doing these funky pupil shapes all algorithmically, so the image thing was an interim compromise. Wanted to show that the eyeball code is fairly open-ended and customizable, even if I don't have the answers for every customization.


Sooooooooooooo, for us novice technical people, what exactly do I need to do? LOL. I just want to change the iris color of the Dragon Eye. Any additional direction would be much appreciated.

Gid3on
 
Posts: 39
Joined: Wed Jul 29, 2015 3:56 am

Re: Electronic Animated Eyes using Teensy 3.1

by mr_koz on Tue Jul 19, 2016 11:54 pm

pburgess wrote:Hm!

Can't think of anything offhand that'd prevent other pins from working. Have you tried just one or two eyes using different CS pins?

Although -in theory- is should support multiple eyes, currently there's some assumptions in the code (like the horizontal flip) that are coded for one each left/right. I only have two screens on-hand so never got around to testing the idea. But at the very least, some tweaks are probably required.

What are the symptoms w/multiple eyes? Do the first two work? Or does the whole thing come crashing down?


You're right! it was late and i was tired and wired it up wrong for the 3rd and 4th screens. Now i'm having an interesting time refactoring the code to work with 4 screens :)

I'll post a pic here when i get him leering at me x4

mr_koz
 
Posts: 5
Joined: Thu Sep 24, 2015 10:00 am

Re: Electronic Animated Eyes using Teensy 3.1

by pburgess on Wed Jul 20, 2016 1:29 am

mr_koz wrote:You're right! it was late and i was tired and wired it up wrong for the 3rd and 4th screens. Now i'm having an interesting time refactoring the code to work with 4 screens :)


Yay! Looking forward to seeing that. ::)

Some pointers: at the bottom of the setup() function, here's where one of the screens is flipped hardwarily:
Code: Select all | TOGGLE FULL SIZE
  // One of the displays is configured to mirror on the X axis.  Simplifies
  // eyelid handling in the drawEye() function -- no need for distinct
  // L-to-R or R-to-L inner loops.  Just the X coordinate of the iris is
  // then reversed when drawing this eye, so they move the same.  Magic!
#ifdef _ADAFRUIT_ST7735H_ // TFT
  digitalWrite(eye[0].cs , LOW);
  digitalWrite(DISPLAY_DC, LOW);
  SPI.transfer(ST7735_MADCTL);
  digitalWrite(DISPLAY_DC, HIGH);
  SPI.transfer(0x88); // MADCTL_MY | MADCTL_BGR
  digitalWrite(eye[0].cs , HIGH);
#else // OLED
  eye[0].display.writeCommand(SSD1351_CMD_SETREMAP);
  eye[0].display.writeData(0x76);
#endif

Could put this in a loop...need to decide if it's even/odd that determines left/right, or first half of list are left, second half are right...
Code: Select all | TOGGLE FULL SIZE
for(e=0; e<NUM_EYES; e += 2) {
  eye[e].display.writeCommand...

vs
Code: Select all | TOGGLE FULL SIZE
for(e=0; e<NUM_EYES/2; e++) {
  eye[e].display.writeCommand...

Then, in the frame() function:
Code: Select all | TOGGLE FULL SIZE
  if(eyeIndex == 1) eyeX = (SCLERA_WIDTH - 128) - eyeX; // Mirrored display

becomes either:
Code: Select all | TOGGLE FULL SIZE
  if(eyeIndex >= NUM_EYES/2)

or
Code: Select all | TOGGLE FULL SIZE
  if(eyeIndex & 1)

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Re: Electronic Animated Eyes using Teensy 3.1

by mr_koz on Wed Jul 20, 2016 1:34 am

@pburgess.. you're a legend, i'll play with that soon - thank you!

Also i've been racking my brains to figure out if i can make the eyes rotate clockwise/anticlockwise (think red biohazard symbols when he gets angry :D ) i'm probably looking at a rewrite for that though.

mr_koz
 
Posts: 5
Joined: Thu Sep 24, 2015 10:00 am

Re: Electronic Animated Eyes using Teensy 3.1

by pburgess on Wed Jul 20, 2016 1:55 am

mr_koz wrote:been racking my brains to figure out if i can make the eyes rotate clockwise/anticlockwise


in drawEye():
Code: Select all | TOGGLE FULL SIZE
          a = (IRIS_MAP_WIDTH * (p >> 7)) / 512;        // Angle (X)

Add a line after this:
Code: Select all | TOGGLE FULL SIZE
          a = (a + someOffset) % IRIS_MAP_WIDTH;

'someOffset' would be a global int. Increment it by some amount once per frame (depending how fast you want the rotation), wrapping around IRIS_MAP_WIDTH as necessary...either in loop() or split() depending whether you're doing interactive or auto-iris:
Code: Select all | TOGGLE FULL SIZE
someOffset = (someOffset + 3) % IRIS_MAP_WIDTH; // Change '3' to whatever increment

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Re: Electronic Animated Eyes using Teensy 3.1

by mr_koz on Wed Jul 20, 2016 1:59 am

Awesome :) I'll absolutely be sharing some more pics :) thank you so much!

mr_koz
 
Posts: 5
Joined: Thu Sep 24, 2015 10:00 am

Re: Electronic Animated Eyes using Teensy 3.1

by pburgess on Wed Jul 20, 2016 6:34 pm

Gid3on wrote:Sooooooooooooo, for us novice technical people, what exactly do I need to do? LOL. I just want to change the iris color of the Dragon Eye. Any additional direction would be much appreciated.


Edit the dragon iris image...using Photoshop or image editor of choice, there's usually an easy option to change the hue of things. Save as a PNG image...if it's in the same folder as the original, let's call it "myIris.png".

Then some command-line shell stuff. Make a copy of the dragonPupilMap.png image, call it pupilMap.png and put it in the same directory as the tablegen.py script, i.e.:
Code: Select all | TOGGLE FULL SIZE
cd convert
cp dragonEye/dragonPupilMap.png pupilMap.png


Run the Python script to convert the images into something the eye code can use:
Code: Select all | TOGGLE FULL SIZE
python tablegen.py dragonEye/sclera.png dragonEye/myIris.png dragonEye/upper.png dragonEye/lower.png -80 > foo.h

The Python stuff's all pretty simple on Mac or Linux, since it's built-in...couldn't tell you how it's done in Windows, but I'm sure it's a thing and some Googling would turn something up.

Copy the resulting header file (foo.h) to wherever the Arduino code is located, then run the Arduino IDE and open the uncannyEyes sketch. Or if the IDE is already running, create a new tab and copy-and-paste the .h file's contents there.
Edit the top of the Arduino sketch to use the new eye (comment out whatever one's currently enabled, replace it with this):
Code: Select all | TOGGLE FULL SIZE
#include "foo.h"        // My custom dragon eye

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Please be positive and constructive with your questions and comments.