# Porting TV-B-Gone Library

**URL:** <https://community.particle.io/t/porting-tv-b-gone-library/20558>\
**Category:** Troubleshooting\
**Created:** [February 28, 2016, 2:44pm UTC](https://community.particle.io/t/porting-tv-b-gone-library/20558 "2016-02-28T14:44:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrescottJoule](https://avatars.discourse-cdn.com/v4/letter/p/87869e/32.png) [@PrescottJoule](https://community.particle.io/u/PrescottJoule)\
**Post date:** [February 28, 2016, 2:44pm UTC](https://community.particle.io/t/porting-tv-b-gone-library/20558/1 "2016-02-28T14:44:31Z")

</div>

EDIT: I have finished the port. It will be available on my GitHub soon.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [February 28, 2016, 2:49pm UTC](https://community.particle.io/t/porting-tv-b-gone-library/20558/2 "2016-02-28T14:49:23Z")

</div>

const char \*\* is a weird thing to have been passing to pgm\_read\_word(). It would normally take a const char \* or some other pointer to a memory. Your value of x is a pointer to a pointer to memory, which is a not how pgm\_read\_word works on Arduino.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [February 28, 2016, 3:29pm UTC](https://community.particle.io/t/porting-tv-b-gone-library/20558/3 "2016-02-28T15:29:57Z")

</div>

Can you move the `#define` to the top of your file and post **_your_** whole code?

I’d expect these lines to cause the trouble

```cpp
    PGM_P data_ptr;
    ... 
    if (region == NA) {
      data_ptr = (PGM_P)pgm_read_word(NApowerCodes+i);
    }
    else {
      data_ptr = (PGM_P)pgm_read_word(EUpowerCodes+i);
    }
    ...
    PGM_P time_ptr = (PGM_P)pgm_read_word(data_ptr);
    data_ptr+=2;
    code_ptr = (PGM_P)pgm_read_word(data_ptr);

```

Just for the sake of testing try this instead

```cpp
#define pgm_read_word(x) (*(x))

```

Also this comment in the lib makes me think

```nohighlight
 Subsequent reads from the powerCode are n bits (same as the packing size)
 that index into another table in ROM that actually stores the on/off times
 const PGM_P time_ptr = (PGM_P)pgm_read_word(code_ptr);

```

We are dealing with a packing size of 32bit, while Arduino uses 8 or 16bits.

So you might need to redo more than just the `pgm_` macros in `void sendAllCodes()`.
