Simulating Nintendo 3DS touchscreen input


hi! i've been working on project involves porting on code teensy device onto arduino. original project designed allow teensy microcontroller control nintendo 3ds simulating button inputs , touchscreen control. here's link source code , schematics using reference:
https://github.com/dekunukem/3xtds

i have button inputs working perfectly, having trouble simulating touchscreen input. i've unplugged touchscreen digitizer of nintendo 3ds , have put arduino in place. not sure if schematic has issue or if arduino's pwm frequency limitations problem.

here's example of touchscreen tap i'm trying simulate:


here's useful section of teensy code ported:
code: [select]
#include <stdint.h>
#include <stdio.h>
#define touch_screen_x_pin 23
#define touch_screen_y_pin a14
#define touch_screen_y_sense_pin 19
#define dac_9_bit_1v8 279

void setup()
{
    analogwriteresolution(9);
analogreadresolution(10);
// pwm frequency @ 90khz
analogwritefrequency(touch_screen_x_pin, 90000);
    pinmode(touch_screen_x_pin, output);
pinmode(touch_screen_y_pin, output);
    analogwrite(touch_screen_x_pin, 0);
    disable_touch_screen();
}

void touch_screen_click(uint16_t x, uint16_t y, int16_t duration_ms)
{
if(x <= 0 || y <= 0 || x > 320 || y > 240)
return;
int16_t x_potential = ((double)x / 320) * dac_9_bit_1v8;
int16_t y_potential = ((double)y / 240) * dac_9_bit_1v8;,

analogwrite(touch_screen_x_pin, x_potential);
enable_touch_screen();
int32_t start = millis();
while(millis() - start < duration_ms)
{
// wait until y+ pin in output mode
while(analogread(touch_screen_y_sense_pin) < 512);
delaymicroseconds(490);
// y+ pin in input mode, write value
analogwrite(touch_screen_y_pin, y_potential);
delaymicroseconds(180);
// pull y+ down again keep interrupt going
enable_touch_screen();
}
disable_touch_screen();
analogwrite(touch_screen_x_pin, 0);
delay(50);
}


void disable_touch_screen()
{
analogwrite(touch_screen_y_pin, dac_9_bit_1v8);
}

// pull y+ pin low initialize 3ds's touch interrupt
void enable_touch_screen()
{
analogwrite(touch_screen_y_pin, 0);
}


and here's code arduino:
code: [select]

// i've included setpwmfrequency() function listed on arduino site, i'm omitting here clarity reasons.

// main change between teensy , arduino teensy uses software lower pwm voltage teensy's native 3.3v down nintendo's 1.8v, while have instead used voltage divider on pwm output of arduino.

// x+ pin of touchscreen.
int touchx = 9;

// y+ pin of touchscreen.
int touchy = 10;

// pin monitor arduino's output of y+
int sensey = 11;

void setup() {
  // change pins 9 , 10 have 31,250 hz pwm frequency. highest can set it.
  // teensy set frequency 90khz.
  // difference in frequencies might cause of problems.
  // picked pins 9 , 10 because won't affect timing millis() , delay.
  setpwmfrequency(9, 1);
  setpwmfrequency(10, 1);
  
  // original teensy code set analog write resolution 9bits.
  // necessary because nintendo touchscreen 320x240, greater 255 8bit resolution.
  // however, don't mind minor accuracy loss! arduino's analog resolution accurate enough me.
  pinmode(touchx, output);
  pinmode(touchy, output);
  analogwrite(touchx, 0);
  disable_touch_screen();
}

void touch_screen_click(unsigned int x, unsigned int y, unsigned int duration_ms) {
  // calculate pwm value write  based on xy touchscreen coordinates want.
  unsigned int x_potential = ((double)x / 320) * 255;
  unsigned int y_potential = ((double)y / 240) * 255;

  // start outputting x value.
  analogwrite(touchx, x_potential);

  // pull y+ ground.
  enable_touch_screen();

  unsigned int start = millis();

  // keep touch screen pressed tap duration.
  while(millis() - start < duration_ms) {
    // wait until y+ pin in output mode
    // original teensy code checked 512, half of max value 1024.
    // we're outputting 1.8v our circuit, reading analog @ 5v
    // value check half of max value: 1.8/5*255=92
    // have used arduino's aref, math faster soldering
    while(analogread(sensey) < 46)
    delaymicroseconds(490);
    
    // y+ pin in output mode
    analogwrite(touchy, y_potential);
    delaymicroseconds(180);
    
    // pull y+ down again keep interrupt going
    enable_touch_screen();
  }
  disable_touch_screen();
  analogwrite(touchx, 0);
  delay(50);
}

void disable_touch_screen() {
  analogwrite(touchy, 255);
}

// pull y+ pin low initialize 3ds's touch interrupt
void enable_touch_screen() {
  analogwrite(touchy, 0);
}

// loop routine runs on , on again forever:
void loop() {

delay(800);
// tap @ 150x150 100ms.
touch_screen_click(150, 150, 100);

delay(800);

// tap @ 50x50 100ms.
touch_screen_click(50, 50, 100);
}


here's schematic i'm using. it's pretty simple, voltage divider , dac.



what thoughts? in code, have tried using 100 microsecond delay instead of waiting y sense pin. have tried placing diodes between capacitors , ground (i using ceramic capacitors bidirectional).

why think failing, compared teensy implementation? indeed arduino's pwm frequency limitations suspected, or think there's issue code or schematic?

this pretty generic touchscreen i'm trying simulate input for, let me know if have other ideas on how might deal it.



Arduino Forum > Using Arduino > General Electronics > Simulating Nintendo 3DS touchscreen input


arduino

Comments