[solved] Porting from Arduino to Particle

Hi there,

I’ve recently bought a bunch of Photons, and they’re awesome; I’ve had no trouble thus far. I’m now wanting to port some Arduino code to the Photons, but running into a few problems (as to be expected). My experience thus far is somewhat limited. I’m using the Particle Dev environment.

When I verify code I get 4 errors:

expected initializer before ‘VFDTUBE_FONT’

the piece of code to which this error refers, looks like:

const uint8_t PROGMEM VFDTUBE_FONT[] PROGMEM =
{
    // 0-9
    0xb7, 0x22, 0x9b, 0xab, 0x2e,
    0xad, 0xbd, 0x23, 0xbf, 0xaf,
    
    // a-z
    0xbb, 0xbc, 0x98, 0xba, 0x9f,
    0x1d, 0xb5, 0x3c, 0x14, 0xa2,
    0x9c, 0x94, 0x37, 0x38, 0xb8,
    0x1f, 0x2f, 0x18, 0x2c, 0x1c,
    0xb0, 0x90, 0x0e, 0x0f, 0x2a, 0x1a,
};

the other error, of which I have 3, is:

‘word’ has not been declared

one example line is:

void putWord(byte index, word value = 0xff00);

I realise this is all to do with variable declarations, but I’m not yet comfortable with the code. I have only really stuck with the basics until now.

In case you’re wondering, this code is for the VFD modules from DFRobot

If necessary, I can obviously provide more of the code. Please help, it would be amazing getting these VFD modules working on the Photons

Thank you!

Just solved the ‘word’ error - made them ints…

Commenting out the following bit

const uint8_t PROGMEM VFDTUBE_FONT[] PROGMEM =
{
	// 0-9
	0xb7, 0x22, 0x9b, 0xab, 0x2e,
	0xad, 0xbd, 0x23, 0xbf, 0xaf,

	// a-z
	0xbb, 0xbc, 0x98, 0xba, 0x9f,
	0x1d, 0xb5, 0x3c, 0x14, 0xa2,
	0x9c, 0x94, 0x37, 0x38, 0xb8,
	0x1f, 0x2f, 0x18, 0x2c, 0x1c,
	0xb0, 0x90, 0x0e, 0x0f, 0x2a, 0x1a,
};

produces a ton of other errors. This maybe won’t be that straightforward to port. Is there any kind of guide out there that may be of some help?

Thank you

@clone137, you should replace word with “uint16_t” which is an unsigned 16-bit value. I believe the error in the VFDTUBE_FONT code is the PROGMEM declarations. The STM32 used in the Core and Photon don’t use progmem since flash and RAM are in the same address space. You can just delete the PROGMEM statements or at the top of the file add #define PROGMEM.

:smile:

Thank you @peekay123 for the quick reply! :smile:

I’ve removed the PROGMEM declarations - can’t say I understand re the STM32, but I’m hoping to get to that point one day :wink:

Now that PROGMEM has been removed, the error is now:

'VFDTUBE_FONT' does not name a type

The last time I worked with C code was ~18 years ago, and it seems I don’t remember much at all. I’m beginning to wonder if it may just be better to write this from scratch - it’s using SPI with a 74HC595 shift register, so I have that to work from as a start.

Thank you, again!

@clone137, can you please post the VFDTube.h file so I can see what you’ve done?

I’m not sure how to paste code in here without it making it look terrible, let’s see if this works.

Thank you!

*edit: hopefully fixed the formatting

/*
 * VFDTube.h
 *
 *  Created on: Oct 29, 2012
 *      Author: agu
 */

#ifndef VFDTUBE_H_
#define VFDTUBE_H_

/* #include "Arduino.h" */

enum Color
{
	White, Yellow, Magenta, Red,
	Cyan, Green, Blue, Black,
};

const VFDTUBE_FONT[] =
{
	// 0-9
	0xb7, 0x22, 0x9b, 0xab, 0x2e,
	0xad, 0xbd, 0x23, 0xbf, 0xaf,

	// a-z
	0xbb, 0xbc, 0x98, 0xba, 0x9f,
	0x1d, 0xb5, 0x3c, 0x14, 0xa2,
	0x9c, 0x94, 0x37, 0x38, 0xb8,
	0x1f, 0x2f, 0x18, 0x2c, 0x1c,
	0xb0, 0x90, 0x0e, 0x0f, 0x2a, 0x1a,
};

class VFDTube
{
public:

	VFDTube(uint8_t pin_din, uint8_t pin_oe, uint8_t pin_st, uint8_t pin_sh,
			byte section_count);
	virtual ~VFDTube();

	void display();

	void putWord(byte index, uint16_t value = 0xff00);
	void clear(int value = 0xff00);

	void setBackgroundColor(Color color);
	void setBackgroundColor(byte index, Color color);

	void setBrightness(byte brightness = 0xff);

	void setPoint(byte index);
	bool setChar(byte index, char c);
	void setChar(char c);

	void printf(const char *__fmt, ...);

private:

	int *_buff;

	const uint8_t _pin_din; // DIN
	const uint8_t _pin_oe; // OE, pin with PWM output is recommended to enable brightness adjustment
	const uint8_t _pin_st; // STCP
	const uint8_t _pin_sh; // SHCP

	const byte _section_count;

	void send(byte data) const;
	bool displayable(char c);
};

#endif /* VFDTUBE_H_ */

Is ‘VFDTUBE_FONT’ meant to be an array/pointer? I can do the code, but I’m getting stuck on data types, etc.

hi

missing the type ? quickly checked and

const int VFDTUBE_FONT[]

compile for me

cheers/Alex

@clone137, close! Next time, use the </> item instead of the double quote one.

In your haste to remove the PROGMEM statements, you also removed the uin8_t typedef statement!! Let me explain:

  • The const on the Core and Photon does two things. It says whatever follows is a constant (cannot be changed) and so store it in flash memory.
  • The uint8_t says that the elements in the array are of type “unsigned 8-bit integers”
  • The VFDTUBE_FONT[] is the name of the array with the default data following the equal sign.

:smile:

Thanks @peekay123, fixed the formatting :smile:

Yes, I know I’d removed it - wasn’t by accident, but I hadn’t yet replaced it with something else - what that something else is meant to be is the problem. I’m not new to code, so I do understand some of this, but I’m definitely rusty :frowning:

It didn’t like const uint8_t VFDTUBE_FONT[] =: 'uint8_t' doesn't name a type

Setting it as type int as @aledand (thank you) mentioned, does move past this error, though.

@clone137, the uint8_t is REALLY important to use (uint8_t specifies one byte whereas int uses 4!). However, I did forget to mention that at the top of the VFDTube.h file, you need to add #include application.h. That should fix the uint8_t issue. :wink:

in reality uint8_t is better than int … does not work for you because you are missing its declaration … do you have #include "application.h" on top of your code ?

1 Like

Is there maybe something wrong with my build environment? I’m using Particle Dev 0.0.25. It’s failing on all uint8_t types

you have to replace “Arduino.h” with “application.h”

@clone137, to make things simple, replace the #include "Arduino.h" line with the #include "application.h" line I mentioned above.

100%, thank you. Now, just a few more things for me to work through :smile:
actually, the #include "Arduino.h" was commented out, but including application.h now has solved my uint8_t problem

Thank you both

2 Likes

I haven’t had a chance to do much since my last post, but I successfully got this working 100% as of 10 minutes ago :smiley:

Thank you so much for the help here. It’s really very much appreciated!

1 Like

@clone137

I’m also trying to use the same library and none of the solutions here have helped me get it going yet.

Could you share your latest revision of the VFDTube.h file?

@jgarland79, I’m working on the port. Stay tuned.